diff --git a/cmd/jetson_exporter.go b/cmd/jetson_exporter.go index 7b4b389..9a55c39 100644 --- a/cmd/jetson_exporter.go +++ b/cmd/jetson_exporter.go @@ -13,81 +13,40 @@ import ( "github.com/gdwr/jetson_exporter/pkg/tegrastats" "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/client_golang/prometheus/promauto" "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/common/promlog" webflag "github.com/prometheus/exporter-toolkit/web/kingpinflag" ) var ( - ramUsageMegabytes = promauto.NewGauge(prometheus.GaugeOpts{ - Name: "tegrastats_ram_usage_megabytes", - Help: "The current RAM usage in megabytes", - }) - ramMaxMegabytes = promauto.NewGauge(prometheus.GaugeOpts{ - Name: "tegrastats_ram_max_megabytes", - Help: "The maximum RAM in megabytes", - }) - swapUsageMegabytes = promauto.NewGauge(prometheus.GaugeOpts{ - Name: "tegrastats_swap_usage_megabytes", - Help: "The current SWAP usage in megabytes", - }) - swapMaxMegabytes = promauto.NewGauge(prometheus.GaugeOpts{ - Name: "tegrastats_swap_max_megabytes", - Help: "The maximum SWAP in megabytes", - }) - swapCachedMegabytes = promauto.NewGauge(prometheus.GaugeOpts{ - Name: "tegrastats_swap_cached_megabytes", - Help: "The current SWAP cached in megabytes", - }) - emcFreqPercent = promauto.NewGauge(prometheus.GaugeOpts{ - Name: "tegrastats_emc_freq_percent", - Help: "The current EMC frequency in percent", - }) - gr3dFreqPercent = promauto.NewGauge(prometheus.GaugeOpts{ - Name: "tegrastats_gr3d_freq_percent", - Help: "The current GR3D frequency in percent", - }) - cpuTempCelsius = promauto.NewGauge(prometheus.GaugeOpts{ - Name: "tegrastats_cpu_temp_celsius", - Help: "The current temperature of the CPU in celsius", - }) - tboardTempCelsius = promauto.NewGauge(prometheus.GaugeOpts{ - Name: "tegrastats_tboard_temp_celsius", - Help: "The current temperature of the T(egra)Board in celsius", - }) - soc2TempCelsius = promauto.NewGauge(prometheus.GaugeOpts{ - Name: "tegrastats_soc2_temp_celsius", - Help: "The current temperature of the SOC2 in celsius", - }) - diodeTempCelsius = promauto.NewGauge(prometheus.GaugeOpts{ - Name: "tegrastats_diode_temp_celsius", - Help: "The current temperature of the diode in celsius", - }) - soc0TempCelsius = promauto.NewGauge(prometheus.GaugeOpts{ - Name: "tegrastats_soc0_temp_celsius", - Help: "The current temperature of the SOC0 in celsius", - }) - cv1TempCelsius = promauto.NewGauge(prometheus.GaugeOpts{ - Name: "tegrastats_cv1_temp_celsius", - Help: "The current temperature of the CV1 in celsius", - }) - gpuTempCelsius = promauto.NewGauge(prometheus.GaugeOpts{ - Name: "tegrastats_gpu_temp_celsius", - Help: "The current temperature of the GPU in celsius", - }) - tjTempCelsius = promauto.NewGauge(prometheus.GaugeOpts{ - Name: "tegrastats_tj_temp_celsius", - Help: "The current temperature of the TJ in celsius", - }) - soc1TempCelsius = promauto.NewGauge(prometheus.GaugeOpts{ - Name: "tegrastats_soc1_temp_celsius", - Help: "The current temperature of the SOC1 in celsius", - }) - cv2TempCelsius = promauto.NewGauge(prometheus.GaugeOpts{ - Name: "tegrastats_cv2_temp_celsius", - Help: "The current temperature of the CV2 in celsius", - }) + tegrastatsTemperature = prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Name: "tegrastats_temperature_celsius", + Help: "temperature in celsius gathered from tegrastats", + }, + []string{"component"}, + ) + tegrastatsRam = prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Name: "tegrastats_ram_megabytes", + Help: "ram metrics in megabytes gathered from tegrastats", + }, + []string{"type"}, + ) + tegrastatsSwap = prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Name: "tegrastats_swap_megabytes", + Help: "swap metrics in megabytes gathered from tegrastats", + }, + []string{"type"}, + ) + tegrastatsCpu = prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Name: "tegrastats_cpu_percentage", + Help: "cpu metrics in percentage gathered from tegrastats", + }, + []string{"core"}, + ) ) func main() { @@ -104,6 +63,11 @@ func main() { kingpin.Parse() logger := promlog.New(promlogConfig) + prometheus.Register(tegrastatsTemperature) + prometheus.Register(tegrastatsRam) + prometheus.Register(tegrastatsSwap) + prometheus.Register(tegrastatsCpu) + level.Info(logger).Log("msg", "Starting jetson-exporter", "tegraPath", *tegrastatsPath) go func() { @@ -133,23 +97,28 @@ func main() { continue } level.Debug(logger).Log("message", "updating metrics") - ramUsageMegabytes.Set(float64(stats.Ram)) - ramMaxMegabytes.Set(float64(stats.RamMax)) - swapUsageMegabytes.Set(float64(stats.Swap)) - swapMaxMegabytes.Set(float64(stats.SwapMax)) - swapCachedMegabytes.Set(float64(stats.SwapCached)) - emcFreqPercent.Set(float64(stats.EMCFreq)) - gr3dFreqPercent.Set(float64(stats.GR3DFreq)) - cpuTempCelsius.Set(stats.CpuTemp) - tboardTempCelsius.Set(stats.TBoardTemp) - soc2TempCelsius.Set(stats.SOC2Temp) - diodeTempCelsius.Set(stats.DiodeTemp) - soc0TempCelsius.Set(stats.SOC0Temp) - cv1TempCelsius.Set(stats.CV1Temp) - gpuTempCelsius.Set(stats.GpuTemp) - tjTempCelsius.Set(stats.TjTemp) - soc1TempCelsius.Set(stats.Soc1Temp) - cv2TempCelsius.Set(stats.CV2Temp) + + tegrastatsTemperature.WithLabelValues("cpu").Set(stats.CpuTemp) + tegrastatsTemperature.WithLabelValues("gpu").Set(stats.GpuTemp) + tegrastatsTemperature.WithLabelValues("tboard").Set(stats.TBoardTemp) + tegrastatsTemperature.WithLabelValues("diode").Set(stats.DiodeTemp) + tegrastatsTemperature.WithLabelValues("tj").Set(stats.TjTemp) + tegrastatsTemperature.WithLabelValues("soc0").Set(stats.SOC0Temp) + tegrastatsTemperature.WithLabelValues("soc1").Set(stats.Soc1Temp) + tegrastatsTemperature.WithLabelValues("soc2").Set(stats.SOC2Temp) + tegrastatsTemperature.WithLabelValues("cv1").Set(stats.CV1Temp) + tegrastatsTemperature.WithLabelValues("cv2").Set(stats.CV2Temp) + + tegrastatsRam.WithLabelValues("usage").Set(float64(stats.Ram)) + tegrastatsRam.WithLabelValues("max").Set(float64(stats.RamMax)) + + tegrastatsSwap.WithLabelValues("current").Set(float64(stats.Swap)) + tegrastatsSwap.WithLabelValues("cached").Set(float64(stats.SwapCached)) + tegrastatsSwap.WithLabelValues("max").Set(float64(stats.SwapMax)) + + for _, cpu := range stats.Cpus { + tegrastatsCpu.WithLabelValues(cpu.Core).Set(cpu.Percentage) + } } }() diff --git a/example/grafana/dashboards/jetson-exporter.json b/example/grafana/dashboards/jetson-exporter.json index 29545f1..78906bf 100644 --- a/example/grafana/dashboards/jetson-exporter.json +++ b/example/grafana/dashboards/jetson-exporter.json @@ -18,7 +18,6 @@ "editable": true, "fiscalYearStartMonth": 0, "graphTooltip": 0, - "id": 1, "links": [], "liveNow": false, "panels": [ @@ -30,8 +29,7 @@ "fieldConfig": { "defaults": { "color": { - "fixedColor": "green", - "mode": "fixed" + "mode": "continuous-GrYlRd" }, "mappings": [], "thresholds": { @@ -47,23 +45,25 @@ } ] }, - "unit": "decmbytes", + "unit": "percent", "unitScale": true }, "overrides": [] }, "gridPos": { - "h": 5, + "h": 11, "w": 4, "x": 0, "y": 0 }, - "id": 2, + "id": 6, "options": { - "colorMode": "background", - "graphMode": "none", - "justifyMode": "auto", - "orientation": "auto", + "displayMode": "lcd", + "maxVizHeight": 300, + "minVizHeight": 16, + "minVizWidth": 8, + "namePlacement": "auto", + "orientation": "horizontal", "reduceOptions": { "calcs": [ "lastNotNull" @@ -71,9 +71,9 @@ "fields": "", "values": false }, - "showPercentChange": false, - "textMode": "auto", - "wideLayout": true + "showUnfilled": true, + "sizing": "auto", + "valueMode": "color" }, "pluginVersion": "10.3.1", "targets": [ @@ -84,130 +84,22 @@ }, "disableTextWrap": false, "editorMode": "builder", - "expr": "tegrastats_ram_usage_megabytes{instance=\"$instance\"}", - "fullMetaSearch": false, - "hide": true, - "includeNullMetadata": true, - "instant": false, - "legendFormat": "Usage", - "range": true, - "refId": "Ram Usage", - "useBackend": false - }, - { - "datasource": { - "type": "prometheus", - "uid": "prometheus" - }, - "disableTextWrap": false, - "editorMode": "builder", - "expr": "tegrastats_ram_max_megabytes{instance=\"$instance\"}", + "exemplar": false, + "expr": "sort_desc(sort(tegrastats_cpu_percentage{instance=\"$instance\"}))", "fullMetaSearch": false, "hide": false, "includeNullMetadata": true, "instant": false, - "legendFormat": "Max", - "range": true, - "refId": "Ram Max", - "useBackend": false - } - ], - "title": "Available RAM", - "transparent": true, - "type": "stat" - }, - { - "datasource": { - "type": "prometheus", - "uid": "prometheus" - }, - "fieldConfig": { - "defaults": { - "mappings": [], - "thresholds": { - "mode": "percentage", - "steps": [ - { - "color": "green", - "value": null - }, - { - "color": "orange", - "value": 70 - }, - { - "color": "red", - "value": 85 - } - ] - }, - "unit": "percent", - "unitScale": true - }, - "overrides": [] - }, - "gridPos": { - "h": 5, - "w": 6, - "x": 4, - "y": 0 - }, - "id": 5, - "options": { - "minVizHeight": 75, - "minVizWidth": 75, - "orientation": "auto", - "reduceOptions": { - "calcs": [ - "lastNotNull" - ], - "fields": "", - "values": false - }, - "showThresholdLabels": false, - "showThresholdMarkers": true, - "sizing": "auto" - }, - "pluginVersion": "10.3.1", - "targets": [ - { - "datasource": { - "type": "prometheus", - "uid": "prometheus" - }, - "disableTextWrap": false, - "editorMode": "builder", - "expr": "tegrastats_emc_freq_percent{instance=\"$instance\"}", - "fullMetaSearch": false, - "hide": false, - "includeNullMetadata": true, - "instant": false, - "legendFormat": "emc", - "range": true, - "refId": "Tboard", - "useBackend": false - }, - { - "datasource": { - "type": "prometheus", - "uid": "prometheus" - }, - "disableTextWrap": false, - "editorMode": "builder", - "expr": "tegrastats_gr3d_freq_percent{instance=\"$instance\"}", - "fullMetaSearch": false, - "hide": false, - "includeNullMetadata": true, - "instant": false, - "legendFormat": "gr3d", + "legendFormat": "{{core}}", "range": true, "refId": "A", "useBackend": false } ], - "title": "Usage", + "title": "CPU Usage per core", + "transformations": [], "transparent": true, - "type": "gauge" + "type": "bargauge" }, { "datasource": { @@ -227,7 +119,7 @@ "axisPlacement": "auto", "barAlignment": 0, "drawStyle": "line", - "fillOpacity": 6, + "fillOpacity": 78, "gradientMode": "opacity", "hideFrom": { "legend": false, @@ -236,25 +128,27 @@ }, "insertNulls": false, "lineInterpolation": "smooth", - "lineWidth": 1, - "pointSize": 5, + "lineStyle": { + "fill": "solid" + }, + "lineWidth": 2, + "pointSize": 1, "scaleDistribution": { - "log": 2, - "type": "log" + "type": "linear" }, "showPoints": "auto", "spanNulls": false, "stacking": { "group": "A", - "mode": "none" + "mode": "normal" }, "thresholdsStyle": { - "mode": "dashed" + "mode": "off" } }, "mappings": [], "thresholds": { - "mode": "percentage", + "mode": "absolute", "steps": [ { "color": "green", @@ -262,23 +156,21 @@ } ] }, - "unit": "decmbytes", - "unitScale": true + "unit": "percent", + "unitScale": false }, "overrides": [] }, "gridPos": { - "h": 5, - "w": 11, - "x": 10, + "h": 11, + "w": 10, + "x": 4, "y": 0 }, - "id": 4, + "id": 7, "options": { "legend": { "calcs": [ - "max", - "stdDev", "mean" ], "displayMode": "table", @@ -290,6 +182,7 @@ "sort": "none" } }, + "pluginVersion": "10.3.1", "targets": [ { "datasource": { @@ -298,16 +191,91 @@ }, "disableTextWrap": false, "editorMode": "builder", - "expr": "tegrastats_swap_usage_megabytes{instance=\"$instance\"}", + "exemplar": false, + "expr": "sort_desc(sort(tegrastats_cpu_percentage{instance=\"$instance\"}))", "fullMetaSearch": false, "hide": false, "includeNullMetadata": true, "instant": false, - "legendFormat": "Usage", + "legendFormat": "{{core}}", "range": true, - "refId": "Tboard", + "refId": "A", "useBackend": false + } + ], + "title": "CPU Usage Total", + "transformations": [], + "transparent": true, + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "fieldConfig": { + "defaults": { + "mappings": [ + { + "options": { + "-256": { + "index": 0, + "text": "N/a" + } + }, + "type": "value" + } + ], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "blue", + "value": null + }, + { + "color": "green", + "value": 50 + }, + { + "color": "orange", + "value": 70 + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "celsius", + "unitScale": true }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 10, + "x": 14, + "y": 0 + }, + "id": 3, + "options": { + "minVizHeight": 75, + "minVizWidth": 75, + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showThresholdLabels": false, + "showThresholdMarkers": true, + "sizing": "auto" + }, + "pluginVersion": "10.3.1", + "targets": [ { "datasource": { "type": "prometheus", @@ -315,20 +283,20 @@ }, "disableTextWrap": false, "editorMode": "builder", - "expr": "tegrastats_swap_cached_megabytes{instance=\"$instance\"}", + "expr": "tegrastats_temperature_celsius{instance=\"$instance\"}", "fullMetaSearch": false, "hide": false, "includeNullMetadata": true, "instant": false, - "legendFormat": "Cached", + "legendFormat": "{{component}}", "range": true, "refId": "A", "useBackend": false } ], - "title": "Swap", + "title": "Temperature", "transparent": true, - "type": "timeseries" + "type": "gauge" }, { "datasource": { @@ -360,8 +328,7 @@ "lineWidth": 1, "pointSize": 5, "scaleDistribution": { - "log": 2, - "type": "log" + "type": "linear" }, "showPoints": "auto", "spanNulls": false, @@ -383,18 +350,43 @@ } ] }, - "unit": "celsius", + "unit": "decmbytes", "unitScale": true }, - "overrides": [] + "overrides": [ + { + "__systemRef": "hideSeriesFrom", + "matcher": { + "id": "byNames", + "options": { + "mode": "exclude", + "names": [ + "ram" + ], + "prefix": "All except:", + "readOnly": true + } + }, + "properties": [ + { + "id": "custom.hideFrom", + "value": { + "legend": false, + "tooltip": false, + "viz": true + } + } + ] + } + ] }, "gridPos": { - "h": 8, - "w": 21, - "x": 0, - "y": 5 + "h": 6, + "w": 10, + "x": 14, + "y": 8 }, - "id": 3, + "id": 4, "options": { "legend": { "calcs": [ @@ -419,170 +411,18 @@ }, "disableTextWrap": false, "editorMode": "builder", - "expr": "tegrastats_cpu_temp_celsius{instance=\"$instance\"}", - "fullMetaSearch": false, - "includeNullMetadata": true, - "instant": false, - "legendFormat": "Cpu", - "range": true, - "refId": "Cpu", - "useBackend": false - }, - { - "datasource": { - "type": "prometheus", - "uid": "prometheus" - }, - "disableTextWrap": false, - "editorMode": "builder", - "expr": "tegrastats_cv1_temp_celsius{instance=\"$instance\"}", - "fullMetaSearch": false, - "hide": true, - "includeNullMetadata": true, - "instant": false, - "legendFormat": "Cv1", - "range": true, - "refId": "Cv1", - "useBackend": false - }, - { - "datasource": { - "type": "prometheus", - "uid": "prometheus" - }, - "disableTextWrap": false, - "editorMode": "builder", - "expr": "tegrastats_cv2_temp_celsius{instance=\"$instance\"}", - "fullMetaSearch": false, - "hide": true, - "includeNullMetadata": true, - "instant": false, - "legendFormat": "Cv2", - "range": true, - "refId": "Cv2", - "useBackend": false - }, - { - "datasource": { - "type": "prometheus", - "uid": "prometheus" - }, - "disableTextWrap": false, - "editorMode": "builder", - "expr": "tegrastats_diode_temp_celsius{instance=\"$instance\"}", - "fullMetaSearch": false, - "hide": false, - "includeNullMetadata": true, - "instant": false, - "legendFormat": "Diode", - "range": true, - "refId": "Diode", - "useBackend": false - }, - { - "datasource": { - "type": "prometheus", - "uid": "prometheus" - }, - "disableTextWrap": false, - "editorMode": "builder", - "expr": "tegrastats_gpu_temp_celsius{instance=\"$instance\"}", - "fullMetaSearch": false, - "hide": true, - "includeNullMetadata": true, - "instant": false, - "legendFormat": "Gpu", - "range": true, - "refId": "Gpu", - "useBackend": false - }, - { - "datasource": { - "type": "prometheus", - "uid": "prometheus" - }, - "disableTextWrap": false, - "editorMode": "builder", - "expr": "tegrastats_soc0_temp_celsius{instance=\"$instance\"}", + "expr": "tegrastats_ram_megabytes{instance=\"$instance\"}", "fullMetaSearch": false, "hide": false, "includeNullMetadata": true, "instant": false, - "legendFormat": "Soc0", - "range": true, - "refId": "Soc0", - "useBackend": false - }, - { - "datasource": { - "type": "prometheus", - "uid": "prometheus" - }, - "disableTextWrap": false, - "editorMode": "builder", - "expr": "tegrastats_soc1_temp_celsius{instance=\"$instance\"}", - "fullMetaSearch": false, - "hide": false, - "includeNullMetadata": true, - "instant": false, - "legendFormat": "Soc1", - "range": true, - "refId": "Soc1", - "useBackend": false - }, - { - "datasource": { - "type": "prometheus", - "uid": "prometheus" - }, - "disableTextWrap": false, - "editorMode": "builder", - "expr": "tegrastats_soc2_temp_celsius{instance=\"$instance\"}", - "fullMetaSearch": false, - "hide": false, - "includeNullMetadata": true, - "instant": false, - "legendFormat": "Soc2", - "range": true, - "refId": "Soc2", - "useBackend": false - }, - { - "datasource": { - "type": "prometheus", - "uid": "prometheus" - }, - "disableTextWrap": false, - "editorMode": "builder", - "expr": "tegrastats_tboard_temp_celsius{instance=\"$instance\"}", - "fullMetaSearch": false, - "hide": false, - "includeNullMetadata": true, - "instant": false, - "legendFormat": "Tboard", - "range": true, - "refId": "Tboard", - "useBackend": false - }, - { - "datasource": { - "type": "prometheus", - "uid": "prometheus" - }, - "disableTextWrap": false, - "editorMode": "builder", - "expr": "tegrastats_tj_temp_celsius{instance=\"$instance\"}", - "fullMetaSearch": false, - "hide": false, - "includeNullMetadata": true, - "instant": false, - "legendFormat": "Tj", + "legendFormat": "{{type}}", "range": true, "refId": "A", "useBackend": false } ], - "title": "Temperature", + "title": "RAM", "transparent": true, "type": "timeseries" }, @@ -594,7 +434,7 @@ "fieldConfig": { "defaults": { "color": { - "mode": "continuous-GrYlRd" + "mode": "palette-classic" }, "custom": { "axisBorderShow": false, @@ -613,11 +453,10 @@ }, "insertNulls": false, "lineInterpolation": "smooth", - "lineWidth": 2, + "lineWidth": 1, "pointSize": 5, "scaleDistribution": { - "log": 2, - "type": "log" + "type": "linear" }, "showPoints": "auto", "spanNulls": false, @@ -642,15 +481,41 @@ "unit": "decmbytes", "unitScale": true }, - "overrides": [] + "overrides": [ + { + "__systemRef": "hideSeriesFrom", + "matcher": { + "id": "byNames", + "options": { + "mode": "exclude", + "names": [ + "swap", + "swap_cached" + ], + "prefix": "All except:", + "readOnly": true + } + }, + "properties": [ + { + "id": "custom.hideFrom", + "value": { + "legend": false, + "tooltip": false, + "viz": true + } + } + ] + } + ] }, "gridPos": { - "h": 8, - "w": 21, - "x": 0, - "y": 13 + "h": 6, + "w": 10, + "x": 14, + "y": 14 }, - "id": 1, + "id": 5, "options": { "legend": { "calcs": [ @@ -675,46 +540,30 @@ }, "disableTextWrap": false, "editorMode": "builder", - "expr": "tegrastats_ram_usage_megabytes{instance=\"$instance\"}", + "expr": "tegrastats_swap_megabytes{instance=\"$instance\"}", "fullMetaSearch": false, + "hide": false, "includeNullMetadata": true, "instant": false, - "legendFormat": "Usage", - "range": true, - "refId": "Ram Usage", - "useBackend": false - }, - { - "datasource": { - "type": "prometheus", - "uid": "prometheus" - }, - "disableTextWrap": false, - "editorMode": "builder", - "expr": "tegrastats_ram_max_megabytes{instance=\"$instance\"}", - "fullMetaSearch": false, - "hide": true, - "includeNullMetadata": true, - "instant": false, - "legendFormat": "Max", + "legendFormat": "{{type}}", "range": true, - "refId": "Ram Max", + "refId": "A", "useBackend": false } ], - "title": "RAM Usage", + "title": "Swap", "transparent": true, "type": "timeseries" } ], - "refresh": "", + "refresh": "5s", "schemaVersion": 39, "tags": [], "templating": { "list": [ { "current": { - "selected": true, + "selected": false, "text": "127.0.0.1:9102", "value": "127.0.0.1:9102" }, @@ -749,6 +598,6 @@ "timezone": "", "title": "Jetson Exporter", "uid": "d3572e85-6cf6-4efc-b267-c3709d0f2f2a", - "version": 3, + "version": 4, "weekStart": "" } \ No newline at end of file diff --git a/pkg/tegrastats/parse.go b/pkg/tegrastats/parse.go index ec0d6c8..8a271d7 100644 --- a/pkg/tegrastats/parse.go +++ b/pkg/tegrastats/parse.go @@ -4,6 +4,7 @@ import ( "fmt" "regexp" "strconv" + "strings" "time" ) @@ -153,5 +154,16 @@ func ParseTegraStats(input string) (*TegraStats, error) { func ParseTegraStatsCpus(input string) []TegraCpu { output := make([]TegraCpu, 0) + + rawCpus := strings.Split(input, ",") + for i, rawCpu := range rawCpus { + cpu := strings.Split(rawCpu, "@") + percentage, _ := strconv.ParseFloat(strings.TrimSuffix(cpu[0], "%"), 64) + output = append(output, TegraCpu{ + Core: strconv.Itoa(i), + Percentage: percentage, + }) + } + return output } diff --git a/pkg/tegrastats/tegrastats.go b/pkg/tegrastats/tegrastats.go index 2f645ea..75e4a09 100644 --- a/pkg/tegrastats/tegrastats.go +++ b/pkg/tegrastats/tegrastats.go @@ -32,11 +32,10 @@ func (ts TegraStats) String() string { } type TegraCpu struct { - X int - Y int - Z int + Core string + Percentage float64 } func (tc TegraCpu) String() string { - return fmt.Sprintf("%v%%@%v", tc.X, tc.Z) + return fmt.Sprintf("%v@%v%%", tc.Core, tc.Percentage) }