mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-25 08:31:03 +00:00
feat: add lookupAndConvertBigMetric and convertBigMetricFromSchema
This commit is contained in:
parent
2ebe3848d6
commit
e758c35e3b
1 changed files with 65 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
package presentation
|
package presentation
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
@ -17,6 +18,36 @@ import (
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var SCHEMA_JSON = `{
|
||||||
|
"client_stats": {
|
||||||
|
"cpu_stats": {
|
||||||
|
"cpu_usage": {
|
||||||
|
"total_usage": "seconds",
|
||||||
|
"percpu_usage": []string{"seconds"},
|
||||||
|
"usage_in_kernelmode": "seconds",
|
||||||
|
"usage_in_usermode": "seconds",
|
||||||
|
},
|
||||||
|
"system_cpu_usage": "seconds",
|
||||||
|
},
|
||||||
|
"precpu_stats": {
|
||||||
|
"cpu_usage": {
|
||||||
|
"total_usage": "seconds",
|
||||||
|
"percpu_usage": []string{"seconds"},
|
||||||
|
"usage_in_kernelmode": "seconds",
|
||||||
|
"usage_in_usermode": "seconds",
|
||||||
|
},
|
||||||
|
"system_cpu_usage": "seconds",
|
||||||
|
},
|
||||||
|
"memory_stats": {
|
||||||
|
"stats": {
|
||||||
|
"hierarchical_memory_limit": "bytes",
|
||||||
|
"hierarchical_memsw_limit": "bytes",
|
||||||
|
},
|
||||||
|
"limit": "bytes",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}`
|
||||||
|
|
||||||
func RenderStats(userConfig *config.UserConfig, container *commands.Container, viewWidth int) (string, error) {
|
func RenderStats(userConfig *config.UserConfig, container *commands.Container, viewWidth int) (string, error) {
|
||||||
stats, ok := container.GetLastStats()
|
stats, ok := container.GetLastStats()
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
@ -144,3 +175,37 @@ func getFloat(unk interface{}) (float64, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func lookupAndConvertBigMetric(data *interface{}, path string) error {
|
||||||
|
var schema map[string]interface{}
|
||||||
|
|
||||||
|
// Unmarshal
|
||||||
|
err := json.Unmarshal([]byte(SCHEMA_JSON), &schema)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error:", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = convertBigMetricFromSchema(data, path, schema)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func convertBigMetricFromSchema(data *interface{}, path string, schema interface{}) error {
|
||||||
|
switch value := schema.(type) {
|
||||||
|
case map[string]interface{}:
|
||||||
|
for key, val := range value {
|
||||||
|
path = strings.TrimSuffix(path, fmt.Sprintf(".%s", key))
|
||||||
|
return convertBigMetricFromSchema(data, path, val)
|
||||||
|
}
|
||||||
|
case []string:
|
||||||
|
// use path to translate from []int to []string
|
||||||
|
return nil
|
||||||
|
case string:
|
||||||
|
// use path to translate from int/int64 to string
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue