From 6f7f8976592db03faae90ab986b9b73e95bbae0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96rnfeldt=20Philip=20=2866140321=29?= Date: Wed, 6 Aug 2025 15:23:36 +0200 Subject: [PATCH 1/7] Performance status probe added MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Örnfeldt Philip (66140321) --- README.md | 16 ++ pkg/probe/probe.go | 1 + pkg/probe/system_performance_status.go | 161 ++++++++++++++++++ pkg/probe/system_performance_status_test.go | 104 +++++++++++ .../system-performance-status.jsonnet | 76 +++++++++ 5 files changed, 358 insertions(+) create mode 100644 pkg/probe/system_performance_status.go create mode 100644 pkg/probe/system_performance_status_test.go create mode 100644 pkg/probe/testdata/system-performance-status.jsonnet diff --git a/README.md b/README.md index 2b843beb..03349b2d 100755 --- a/README.md +++ b/README.md @@ -49,6 +49,21 @@ Global: * `fortigate_cpu_usage_ratio` * `fortigate_memory_usage_ratio` * `fortigate_current_sessions` + * _System/Performance/status/_ + * `fortigate_system_performance_status_cpu_cores_idle` + * `fortigate_system_performance_status_cpu_cores_iowait` + * `fortigate_system_performance_status_cpu_cores_nice` + * `fortigate_system_performance_status_cpu_cores_system` + * `fortigate_system_performance_status_cpu_cores_user` + * `fortigate_system_performance_status_cpu_idle` + * `fortigate_system_performance_status_cpu_iowait` + * `fortigate_system_performance_status_cpu_nice` + * `fortigate_system_performance_status_cpu_system` + * `fortigate_system_performance_status_cpu_user` + * `fortigate_system_performance_status_mem_free` + * `fortigate_system_performance_status_mem_freeable` + * `fortigate_system_performance_status_mem_total` + * `fortigate_system_performance_status_mem_used` * _System/HAChecksums_ * `fortigate_ha_member_has_role` * _License/Status_ @@ -416,6 +431,7 @@ To improve security, limit permissions to required ones only (least privilege pr |System/HAStatistics | sysgrp.cfg |api/v2/monitor/system/ha-statistics
api/v2/cmdb/system/ha | |System/Interface | netgrp.cfg |api/v2/monitor/system/interface/select | |System/LinkMonitor | sysgrp.cfg |api/v2/monitor/system/link-monitor | +|System/Performance/Status | sysgrp.cfg |api/v2/monitor/system/performance/status | |System/Resource/Usage | sysgrp.cfg |api/v2/monitor/system/resource/usage | |System/SensorInfo | sysgrp.cfg |api/v2/monitor/system/sensor-info | |System/Status | *any* |api/v2/monitor/system/status | diff --git a/pkg/probe/probe.go b/pkg/probe/probe.go index 88d76fe6..70056045 100644 --- a/pkg/probe/probe.go +++ b/pkg/probe/probe.go @@ -145,6 +145,7 @@ func (p *ProbeCollector) Probe(ctx context.Context, target map[string]string, hc {"System/HAStatistics", probeSystemHAStatistics}, {"System/Interface", probeSystemInterface}, {"System/LinkMonitor", probeSystemLinkMonitor}, + {"System/Perfomance/Status", probeSystemPerformanceStatus}, {"System/Resource/Usage", probeSystemResourceUsage}, {"System/SDNConnector", probeSystemSDNConnector}, {"System/SensorInfo", probeSystemSensorInfo}, diff --git a/pkg/probe/system_performance_status.go b/pkg/probe/system_performance_status.go new file mode 100644 index 00000000..35cb1229 --- /dev/null +++ b/pkg/probe/system_performance_status.go @@ -0,0 +1,161 @@ +// Copyright 2025 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package probe + +import ( + "log" + "strconv" + + "github.com/prometheus-community/fortigate_exporter/pkg/http" + "github.com/prometheus/client_golang/prometheus" +) + +func probeSystemPerformanceStatus(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) { + var ( + cpuCoresUser = prometheus.NewDesc( + "fortigate_system_performance_status_cpu_cores_user", + "Percentage of CPU utilization that occurred at the user level.", + []string{"label"}, nil, + ) + cpuCoresSystem = prometheus.NewDesc( + "fortigate_system_performance_status_cpu_cores_system", + "Percentage of CPU utilization that occurred while executing at the system level.", + []string{"label"}, nil, + ) + cpuCoresNice = prometheus.NewDesc( + "fortigate_system_performance_status_cpu_cores_nice", + "Percentage of CPU utilization that occurred while executing at the user level with nice priority.", + []string{"label"}, nil, + ) + cpuCoresIdle = prometheus.NewDesc( + "fortigate_system_performance_status_cpu_cores_idle", + "Percentage of time that the CPU was idle and the system did not have an outstanding disk I/O request.", + []string{"label"}, nil, + ) + cpuCoresIowait = prometheus.NewDesc( + "fortigate_system_performance_status_cpu_cores_iowait", + "Percentage of time that the CPU was idle during which the system had an outstanding disk I/O request.", + []string{"label"}, nil, + ) + cpuUser = prometheus.NewDesc( + "fortigate_system_performance_status_cpu_user", + "Percentage of CPU utilization that occurred at the user level.", + []string{"label"}, nil, + ) + cpuSystem = prometheus.NewDesc( + "fortigate_system_performance_status_cpu_system", + "Percentage of CPU utilization that occurred while executing at the system level.", + []string{"label"}, nil, + ) + cpuNice = prometheus.NewDesc( + "fortigate_system_performance_status_cpu_nice", + "Percentage of CPU utilization that occurred while executing at the user level with nice priority.", + []string{"label"}, nil, + ) + cpuIdle = prometheus.NewDesc( + "fortigate_system_performance_status_cpu_idle", + "Percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request.", + []string{"label"}, nil, + ) + cpuIowait = prometheus.NewDesc( + "fortigate_system_performance_status_cpu_iowait", + "Percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request.", + []string{"label"}, nil, + ) + memTotal = prometheus.NewDesc( + "fortigate_system_performance_status_mem_total", + "All the installed memory in RAM, in bytes.", + []string{"label"}, nil, + ) + memUsed = prometheus.NewDesc( + "fortigate_system_performance_status_mem_used", + "Memory are being used, in bytes.", + []string{"label"}, nil, + ) + memFree = prometheus.NewDesc( + "fortigate_system_performance_status_mem_free", + "All the memory in RAM that is not being used for anything (even caches), in bytes.", + []string{"label"}, nil, + ) + memFreeable = prometheus.NewDesc( + "fortigate_system_performance_status_mem_freeable", + "Freeable buffers/caches memory, in bytes.", + []string{"label"}, nil, + ) + ) + + type SystemPerformanceStatusCores struct { + User int `json:"user"` + System int `json:"system"` + Nice int `json:"nice"` + Idle int `json:"idle"` + Iowait int `json:"iowait"` + } + + type SystemPerformanceStatusCpu struct { + Cores []SystemPerformanceStatusCores `json:"cores"` + User int `json:"user"` + System int `json:"system"` + Nice int `json:"nice"` + Idle int `json:"idle"` + Iowait int `json:"iowait"` + } + + type SystemPerformanceStatusMem struct { + Total int `json:"total"` + Used int `json:"used"` + Free int `json:"free"` + Freeable int `json:"freeable"` + } + + type SystemPerformanceStatus struct { + Cpu SystemPerformanceStatusCpu `json:"cpu"` + Mem SystemPerformanceStatusMem `json:"mem"` + } + + type SystemPerformanceStatusResult struct { + Results []SystemPerformanceStatus `json:"results"` + } + + var res SystemPerformanceStatusResult + if err := c.Get("api/v2/monitor/system/performance/status", "", &res); err != nil { + log.Printf("Error: %v", err) + return nil, false + } + m := []prometheus.Metric{} + var cpu_num, mem_num, core_num string + for n, r := range res.Results { + cpu_num = "cpu_" + strconv.Itoa(n) + mem_num = "mem_" + strconv.Itoa(n) + for i, core := range r.Cpu.Cores { + core_num = "core_" + strconv.Itoa(i) + m = append(m, prometheus.MustNewConstMetric(cpuCoresUser, prometheus.GaugeValue, float64(core.User), cpu_num + "_" + core_num)) + m = append(m, prometheus.MustNewConstMetric(cpuCoresSystem, prometheus.GaugeValue, float64(core.System), cpu_num + "_" + core_num)) + m = append(m, prometheus.MustNewConstMetric(cpuCoresNice, prometheus.GaugeValue, float64(core.Nice), cpu_num + "_" + core_num)) + m = append(m, prometheus.MustNewConstMetric(cpuCoresIdle, prometheus.GaugeValue, float64(core.Idle), cpu_num + "_" + core_num)) + m = append(m, prometheus.MustNewConstMetric(cpuCoresIowait, prometheus.GaugeValue, float64(core.Iowait), cpu_num + "_" + core_num)) + } + m = append(m, prometheus.MustNewConstMetric(cpuUser,prometheus.GaugeValue, float64(r.Cpu.User), cpu_num)) + m = append(m, prometheus.MustNewConstMetric(cpuSystem,prometheus.GaugeValue, float64(r.Cpu.System), cpu_num)) + m = append(m, prometheus.MustNewConstMetric(cpuNice,prometheus.GaugeValue, float64(r.Cpu.Nice), cpu_num)) + m = append(m, prometheus.MustNewConstMetric(cpuIdle,prometheus.GaugeValue, float64(r.Cpu.Idle), cpu_num)) + m = append(m, prometheus.MustNewConstMetric(cpuIowait,prometheus.GaugeValue, float64(r.Cpu.Iowait), cpu_num)) + m = append(m, prometheus.MustNewConstMetric(memTotal,prometheus.GaugeValue, float64(r.Mem.Total), mem_num)) + m = append(m, prometheus.MustNewConstMetric(memUsed,prometheus.GaugeValue, float64(r.Mem.Used), mem_num)) + m = append(m, prometheus.MustNewConstMetric(memFree,prometheus.GaugeValue, float64(r.Mem.Free), mem_num)) + m = append(m, prometheus.MustNewConstMetric(memFreeable,prometheus.GaugeValue, float64(r.Mem.Freeable), mem_num)) + } + + return m, true +} \ No newline at end of file diff --git a/pkg/probe/system_performance_status_test.go b/pkg/probe/system_performance_status_test.go new file mode 100644 index 00000000..6277c374 --- /dev/null +++ b/pkg/probe/system_performance_status_test.go @@ -0,0 +1,104 @@ +// Copyright 2025 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package probe + +import ( + "strings" + "testing" + + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/testutil" +) + +func TestSystemPerformanceStatus(t *testing.T) { + c := newFakeClient() + c.prepare("api/v2/monitor/system/performance/status", "testdata/system-performance-status.jsonnet") + r := prometheus.NewPedanticRegistry() + if !testProbe(probeSystemPerformanceStatus, c, r) { + t.Errorf("probeSystemPerformanceStatus() returned non-success") + } + + em := ` + # HELP fortigate_system_performance_status_cpu_cores_idle Percentage of time that the CPU was idle and the system did not have an outstanding disk I/O request. + # TYPE fortigate_system_performance_status_cpu_cores_idle gauge + fortigate_system_performance_status_cpu_cores_idle{label="cpu_0_core_0"} 0 + fortigate_system_performance_status_cpu_cores_idle{label="cpu_0_core_1"} 0 + fortigate_system_performance_status_cpu_cores_idle{label="cpu_0_core_2"} 0 + fortigate_system_performance_status_cpu_cores_idle{label="cpu_1_core_0"} 0 + # HELP fortigate_system_performance_status_cpu_cores_iowait Percentage of time that the CPU was idle during which the system had an outstanding disk I/O request. + # TYPE fortigate_system_performance_status_cpu_cores_iowait gauge + fortigate_system_performance_status_cpu_cores_iowait{label="cpu_0_core_0"} 0 + fortigate_system_performance_status_cpu_cores_iowait{label="cpu_0_core_1"} 0 + fortigate_system_performance_status_cpu_cores_iowait{label="cpu_0_core_2"} 0 + fortigate_system_performance_status_cpu_cores_iowait{label="cpu_1_core_0"} 0 + # HELP fortigate_system_performance_status_cpu_cores_nice Percentage of CPU utilization that occurred while executing at the user level with nice priority. + # TYPE fortigate_system_performance_status_cpu_cores_nice gauge + fortigate_system_performance_status_cpu_cores_nice{label="cpu_0_core_0"} 0 + fortigate_system_performance_status_cpu_cores_nice{label="cpu_0_core_1"} 0 + fortigate_system_performance_status_cpu_cores_nice{label="cpu_0_core_2"} 0 + fortigate_system_performance_status_cpu_cores_nice{label="cpu_1_core_0"} 0 + # HELP fortigate_system_performance_status_cpu_cores_system Percentage of CPU utilization that occurred while executing at the system level. + # TYPE fortigate_system_performance_status_cpu_cores_system gauge + fortigate_system_performance_status_cpu_cores_system{label="cpu_0_core_0"} 13 + fortigate_system_performance_status_cpu_cores_system{label="cpu_0_core_1"} 14 + fortigate_system_performance_status_cpu_cores_system{label="cpu_0_core_2"} 0 + fortigate_system_performance_status_cpu_cores_system{label="cpu_1_core_0"} 0 + # HELP fortigate_system_performance_status_cpu_cores_user Percentage of CPU utilization that occurred at the user level. + # TYPE fortigate_system_performance_status_cpu_cores_user gauge + fortigate_system_performance_status_cpu_cores_user{label="cpu_0_core_0"} 0 + fortigate_system_performance_status_cpu_cores_user{label="cpu_0_core_1"} 1 + fortigate_system_performance_status_cpu_cores_user{label="cpu_0_core_2"} 2 + fortigate_system_performance_status_cpu_cores_user{label="cpu_1_core_0"} 0 + # HELP fortigate_system_performance_status_cpu_idle Percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request. + # TYPE fortigate_system_performance_status_cpu_idle gauge + fortigate_system_performance_status_cpu_idle{label="cpu_0"} 0 + fortigate_system_performance_status_cpu_idle{label="cpu_1"} 0 + # HELP fortigate_system_performance_status_cpu_iowait Percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request. + # TYPE fortigate_system_performance_status_cpu_iowait gauge + fortigate_system_performance_status_cpu_iowait{label="cpu_0"} 0 + fortigate_system_performance_status_cpu_iowait{label="cpu_1"} 0 + # HELP fortigate_system_performance_status_cpu_nice Percentage of CPU utilization that occurred while executing at the user level with nice priority. + # TYPE fortigate_system_performance_status_cpu_nice gauge + fortigate_system_performance_status_cpu_nice{label="cpu_0"} 0 + fortigate_system_performance_status_cpu_nice{label="cpu_1"} 0 + # HELP fortigate_system_performance_status_cpu_system Percentage of CPU utilization that occurred while executing at the system level. + # TYPE fortigate_system_performance_status_cpu_system gauge + fortigate_system_performance_status_cpu_system{label="cpu_0"} 0 + fortigate_system_performance_status_cpu_system{label="cpu_1"} 0 + # HELP fortigate_system_performance_status_cpu_user Percentage of CPU utilization that occurred at the user level. + # TYPE fortigate_system_performance_status_cpu_user gauge + fortigate_system_performance_status_cpu_user{label="cpu_0"} 200 + fortigate_system_performance_status_cpu_user{label="cpu_1"} 0 + # HELP fortigate_system_performance_status_mem_free All the memory in RAM that is not being used for anything (even caches), in bytes. + # TYPE fortigate_system_performance_status_mem_free gauge + fortigate_system_performance_status_mem_free{label="mem_0"} 0 + fortigate_system_performance_status_mem_free{label="mem_1"} 0 + # HELP fortigate_system_performance_status_mem_freeable Freeable buffers/caches memory, in bytes. + # TYPE fortigate_system_performance_status_mem_freeable gauge + fortigate_system_performance_status_mem_freeable{label="mem_0"} 0 + fortigate_system_performance_status_mem_freeable{label="mem_1"} 0 + # HELP fortigate_system_performance_status_mem_total All the installed memory in RAM, in bytes. + # TYPE fortigate_system_performance_status_mem_total gauge + fortigate_system_performance_status_mem_total{label="mem_0"} 0 + fortigate_system_performance_status_mem_total{label="mem_1"} 0 + # HELP fortigate_system_performance_status_mem_used Memory are being used, in bytes. + # TYPE fortigate_system_performance_status_mem_used gauge + fortigate_system_performance_status_mem_used{label="mem_0"} 0 + fortigate_system_performance_status_mem_used{label="mem_1"} 0 + ` + + if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil { + t.Fatalf("metric compare: err %v", err) + } +} \ No newline at end of file diff --git a/pkg/probe/testdata/system-performance-status.jsonnet b/pkg/probe/testdata/system-performance-status.jsonnet new file mode 100644 index 00000000..81c5b802 --- /dev/null +++ b/pkg/probe/testdata/system-performance-status.jsonnet @@ -0,0 +1,76 @@ +# api/v2/monitor/system/performance/status +{ + "http_method":"GET", + "results": [ + { + "cpu": { + "cores": [ + { + "user": 0, + "system": 13, + "nice": 0, + "idle": 0, + "iowait": 0 + }, + { + "user": 1, + "system": 14, + "nice": 0, + "idle": 0, + "iowait": 0 + }, + { + "user": 2, + "system": 0, + "nice": 0, + "idle": 0, + "iowait": 0 + } + ], + "user": 200, + "system": 0, + "nice": 0, + "idle": 0, + "iowait": 0 + }, + "mem": { + "total": 0, + "used": 0, + "free": 0, + "freeable": 0 + } + }, + { + "cpu": { + "cores": [ + { + "user": 0, + "system": 0, + "nice": 0, + "idle": 0, + "iowait": 0 + } + ], + "user": 0, + "system": 0, + "nice": 0, + "idle": 0, + "iowait": 0 + }, + "mem": { + "total": 0, + "used": 0, + "free": 0, + "freeable": 0 + } + } + ], + "vdom":"root", + "path":"system", + "name":"fortimanager", + "action":"status", + "status":"success", + "serial":"FGT61FT000000000", + "version":"v6.0.10", + "build":365 +} \ No newline at end of file From 857c0359d6c5a05aac4a4fedb56c658432a5921a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96rnfeldt=20Philip=20=2866140321=29?= Date: Mon, 15 Sep 2025 14:16:57 +0200 Subject: [PATCH 2/7] Added vdoms MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Örnfeldt Philip (66140321) --- pkg/probe/system_performance_status.go | 74 +++++++++--------- pkg/probe/system_performance_status_test.go | 76 +++++++++---------- .../system-performance-status.jsonnet | 4 +- 3 files changed, 78 insertions(+), 76 deletions(-) diff --git a/pkg/probe/system_performance_status.go b/pkg/probe/system_performance_status.go index 35cb1229..018d86e7 100644 --- a/pkg/probe/system_performance_status.go +++ b/pkg/probe/system_performance_status.go @@ -26,72 +26,72 @@ func probeSystemPerformanceStatus(c http.FortiHTTP, meta *TargetMetadata) ([]pro cpuCoresUser = prometheus.NewDesc( "fortigate_system_performance_status_cpu_cores_user", "Percentage of CPU utilization that occurred at the user level.", - []string{"label"}, nil, + []string{"label", "vdom"}, nil, ) cpuCoresSystem = prometheus.NewDesc( "fortigate_system_performance_status_cpu_cores_system", "Percentage of CPU utilization that occurred while executing at the system level.", - []string{"label"}, nil, + []string{"label", "vdom"}, nil, ) cpuCoresNice = prometheus.NewDesc( "fortigate_system_performance_status_cpu_cores_nice", "Percentage of CPU utilization that occurred while executing at the user level with nice priority.", - []string{"label"}, nil, + []string{"label", "vdom"}, nil, ) cpuCoresIdle = prometheus.NewDesc( "fortigate_system_performance_status_cpu_cores_idle", "Percentage of time that the CPU was idle and the system did not have an outstanding disk I/O request.", - []string{"label"}, nil, + []string{"label", "vdom"}, nil, ) cpuCoresIowait = prometheus.NewDesc( "fortigate_system_performance_status_cpu_cores_iowait", "Percentage of time that the CPU was idle during which the system had an outstanding disk I/O request.", - []string{"label"}, nil, + []string{"label", "vdom"}, nil, ) cpuUser = prometheus.NewDesc( "fortigate_system_performance_status_cpu_user", "Percentage of CPU utilization that occurred at the user level.", - []string{"label"}, nil, + []string{"label", "vdom"}, nil, ) cpuSystem = prometheus.NewDesc( "fortigate_system_performance_status_cpu_system", "Percentage of CPU utilization that occurred while executing at the system level.", - []string{"label"}, nil, + []string{"label", "vdom"}, nil, ) cpuNice = prometheus.NewDesc( "fortigate_system_performance_status_cpu_nice", "Percentage of CPU utilization that occurred while executing at the user level with nice priority.", - []string{"label"}, nil, + []string{"label", "vdom"}, nil, ) cpuIdle = prometheus.NewDesc( "fortigate_system_performance_status_cpu_idle", "Percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request.", - []string{"label"}, nil, + []string{"label", "vdom"}, nil, ) cpuIowait = prometheus.NewDesc( "fortigate_system_performance_status_cpu_iowait", "Percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request.", - []string{"label"}, nil, + []string{"label", "vdom"}, nil, ) memTotal = prometheus.NewDesc( "fortigate_system_performance_status_mem_total", "All the installed memory in RAM, in bytes.", - []string{"label"}, nil, + []string{"label", "vdom"}, nil, ) memUsed = prometheus.NewDesc( "fortigate_system_performance_status_mem_used", "Memory are being used, in bytes.", - []string{"label"}, nil, + []string{"label", "vdom"}, nil, ) memFree = prometheus.NewDesc( "fortigate_system_performance_status_mem_free", "All the memory in RAM that is not being used for anything (even caches), in bytes.", - []string{"label"}, nil, + []string{"label", "vdom"}, nil, ) memFreeable = prometheus.NewDesc( "fortigate_system_performance_status_mem_freeable", "Freeable buffers/caches memory, in bytes.", - []string{"label"}, nil, + []string{"label", "vdom"}, nil, ) ) @@ -126,36 +126,38 @@ func probeSystemPerformanceStatus(c http.FortiHTTP, meta *TargetMetadata) ([]pro type SystemPerformanceStatusResult struct { Results []SystemPerformanceStatus `json:"results"` + VDOM string `json:"vdom"` } - var res SystemPerformanceStatusResult - if err := c.Get("api/v2/monitor/system/performance/status", "", &res); err != nil { + var result []SystemPerformanceStatusResult + if err := c.Get("api/v2/monitor/system/performance/status", "vdom=*", &result); err != nil { log.Printf("Error: %v", err) return nil, false } m := []prometheus.Metric{} var cpu_num, mem_num, core_num string - for n, r := range res.Results { - cpu_num = "cpu_" + strconv.Itoa(n) - mem_num = "mem_" + strconv.Itoa(n) - for i, core := range r.Cpu.Cores { - core_num = "core_" + strconv.Itoa(i) - m = append(m, prometheus.MustNewConstMetric(cpuCoresUser, prometheus.GaugeValue, float64(core.User), cpu_num + "_" + core_num)) - m = append(m, prometheus.MustNewConstMetric(cpuCoresSystem, prometheus.GaugeValue, float64(core.System), cpu_num + "_" + core_num)) - m = append(m, prometheus.MustNewConstMetric(cpuCoresNice, prometheus.GaugeValue, float64(core.Nice), cpu_num + "_" + core_num)) - m = append(m, prometheus.MustNewConstMetric(cpuCoresIdle, prometheus.GaugeValue, float64(core.Idle), cpu_num + "_" + core_num)) - m = append(m, prometheus.MustNewConstMetric(cpuCoresIowait, prometheus.GaugeValue, float64(core.Iowait), cpu_num + "_" + core_num)) + for _, res := range result{ + for n, r := range res.Results { + cpu_num = "cpu_" + strconv.Itoa(n) + mem_num = "mem_" + strconv.Itoa(n) + for i, core := range r.Cpu.Cores { + core_num = "core_" + strconv.Itoa(i) + m = append(m, prometheus.MustNewConstMetric(cpuCoresUser, prometheus.GaugeValue, float64(core.User), cpu_num + "_" + core_num, res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(cpuCoresSystem, prometheus.GaugeValue, float64(core.System), cpu_num + "_" + core_num, res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(cpuCoresNice, prometheus.GaugeValue, float64(core.Nice), cpu_num + "_" + core_num, res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(cpuCoresIdle, prometheus.GaugeValue, float64(core.Idle), cpu_num + "_" + core_num, res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(cpuCoresIowait, prometheus.GaugeValue, float64(core.Iowait), cpu_num + "_" + core_num, res.VDOM)) + } + m = append(m, prometheus.MustNewConstMetric(cpuUser,prometheus.GaugeValue, float64(r.Cpu.User), cpu_num, res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(cpuSystem,prometheus.GaugeValue, float64(r.Cpu.System), cpu_num, res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(cpuNice,prometheus.GaugeValue, float64(r.Cpu.Nice), cpu_num, res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(cpuIdle,prometheus.GaugeValue, float64(r.Cpu.Idle), cpu_num, res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(cpuIowait,prometheus.GaugeValue, float64(r.Cpu.Iowait), cpu_num, res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(memTotal,prometheus.GaugeValue, float64(r.Mem.Total), mem_num, res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(memUsed,prometheus.GaugeValue, float64(r.Mem.Used), mem_num, res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(memFree,prometheus.GaugeValue, float64(r.Mem.Free), mem_num, res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(memFreeable,prometheus.GaugeValue, float64(r.Mem.Freeable), mem_num, res.VDOM)) } - m = append(m, prometheus.MustNewConstMetric(cpuUser,prometheus.GaugeValue, float64(r.Cpu.User), cpu_num)) - m = append(m, prometheus.MustNewConstMetric(cpuSystem,prometheus.GaugeValue, float64(r.Cpu.System), cpu_num)) - m = append(m, prometheus.MustNewConstMetric(cpuNice,prometheus.GaugeValue, float64(r.Cpu.Nice), cpu_num)) - m = append(m, prometheus.MustNewConstMetric(cpuIdle,prometheus.GaugeValue, float64(r.Cpu.Idle), cpu_num)) - m = append(m, prometheus.MustNewConstMetric(cpuIowait,prometheus.GaugeValue, float64(r.Cpu.Iowait), cpu_num)) - m = append(m, prometheus.MustNewConstMetric(memTotal,prometheus.GaugeValue, float64(r.Mem.Total), mem_num)) - m = append(m, prometheus.MustNewConstMetric(memUsed,prometheus.GaugeValue, float64(r.Mem.Used), mem_num)) - m = append(m, prometheus.MustNewConstMetric(memFree,prometheus.GaugeValue, float64(r.Mem.Free), mem_num)) - m = append(m, prometheus.MustNewConstMetric(memFreeable,prometheus.GaugeValue, float64(r.Mem.Freeable), mem_num)) } - return m, true } \ No newline at end of file diff --git a/pkg/probe/system_performance_status_test.go b/pkg/probe/system_performance_status_test.go index 6277c374..87157465 100644 --- a/pkg/probe/system_performance_status_test.go +++ b/pkg/probe/system_performance_status_test.go @@ -32,70 +32,70 @@ func TestSystemPerformanceStatus(t *testing.T) { em := ` # HELP fortigate_system_performance_status_cpu_cores_idle Percentage of time that the CPU was idle and the system did not have an outstanding disk I/O request. # TYPE fortigate_system_performance_status_cpu_cores_idle gauge - fortigate_system_performance_status_cpu_cores_idle{label="cpu_0_core_0"} 0 - fortigate_system_performance_status_cpu_cores_idle{label="cpu_0_core_1"} 0 - fortigate_system_performance_status_cpu_cores_idle{label="cpu_0_core_2"} 0 - fortigate_system_performance_status_cpu_cores_idle{label="cpu_1_core_0"} 0 + fortigate_system_performance_status_cpu_cores_idle{label="cpu_0_core_0",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_idle{label="cpu_0_core_1",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_idle{label="cpu_0_core_2",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_idle{label="cpu_1_core_0",vdom="root"} 0 # HELP fortigate_system_performance_status_cpu_cores_iowait Percentage of time that the CPU was idle during which the system had an outstanding disk I/O request. # TYPE fortigate_system_performance_status_cpu_cores_iowait gauge - fortigate_system_performance_status_cpu_cores_iowait{label="cpu_0_core_0"} 0 - fortigate_system_performance_status_cpu_cores_iowait{label="cpu_0_core_1"} 0 - fortigate_system_performance_status_cpu_cores_iowait{label="cpu_0_core_2"} 0 - fortigate_system_performance_status_cpu_cores_iowait{label="cpu_1_core_0"} 0 + fortigate_system_performance_status_cpu_cores_iowait{label="cpu_0_core_0",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_iowait{label="cpu_0_core_1",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_iowait{label="cpu_0_core_2",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_iowait{label="cpu_1_core_0",vdom="root"} 0 # HELP fortigate_system_performance_status_cpu_cores_nice Percentage of CPU utilization that occurred while executing at the user level with nice priority. # TYPE fortigate_system_performance_status_cpu_cores_nice gauge - fortigate_system_performance_status_cpu_cores_nice{label="cpu_0_core_0"} 0 - fortigate_system_performance_status_cpu_cores_nice{label="cpu_0_core_1"} 0 - fortigate_system_performance_status_cpu_cores_nice{label="cpu_0_core_2"} 0 - fortigate_system_performance_status_cpu_cores_nice{label="cpu_1_core_0"} 0 + fortigate_system_performance_status_cpu_cores_nice{label="cpu_0_core_0",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_nice{label="cpu_0_core_1",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_nice{label="cpu_0_core_2",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_nice{label="cpu_1_core_0",vdom="root"} 0 # HELP fortigate_system_performance_status_cpu_cores_system Percentage of CPU utilization that occurred while executing at the system level. # TYPE fortigate_system_performance_status_cpu_cores_system gauge - fortigate_system_performance_status_cpu_cores_system{label="cpu_0_core_0"} 13 - fortigate_system_performance_status_cpu_cores_system{label="cpu_0_core_1"} 14 - fortigate_system_performance_status_cpu_cores_system{label="cpu_0_core_2"} 0 - fortigate_system_performance_status_cpu_cores_system{label="cpu_1_core_0"} 0 + fortigate_system_performance_status_cpu_cores_system{label="cpu_0_core_0",vdom="root"} 13 + fortigate_system_performance_status_cpu_cores_system{label="cpu_0_core_1",vdom="root"} 14 + fortigate_system_performance_status_cpu_cores_system{label="cpu_0_core_2",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_system{label="cpu_1_core_0",vdom="root"} 0 # HELP fortigate_system_performance_status_cpu_cores_user Percentage of CPU utilization that occurred at the user level. # TYPE fortigate_system_performance_status_cpu_cores_user gauge - fortigate_system_performance_status_cpu_cores_user{label="cpu_0_core_0"} 0 - fortigate_system_performance_status_cpu_cores_user{label="cpu_0_core_1"} 1 - fortigate_system_performance_status_cpu_cores_user{label="cpu_0_core_2"} 2 - fortigate_system_performance_status_cpu_cores_user{label="cpu_1_core_0"} 0 + fortigate_system_performance_status_cpu_cores_user{label="cpu_0_core_0",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_user{label="cpu_0_core_1",vdom="root"} 1 + fortigate_system_performance_status_cpu_cores_user{label="cpu_0_core_2",vdom="root"} 2 + fortigate_system_performance_status_cpu_cores_user{label="cpu_1_core_0",vdom="root"} 0 # HELP fortigate_system_performance_status_cpu_idle Percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request. # TYPE fortigate_system_performance_status_cpu_idle gauge - fortigate_system_performance_status_cpu_idle{label="cpu_0"} 0 - fortigate_system_performance_status_cpu_idle{label="cpu_1"} 0 + fortigate_system_performance_status_cpu_idle{label="cpu_0",vdom="root"} 0 + fortigate_system_performance_status_cpu_idle{label="cpu_1",vdom="root"} 0 # HELP fortigate_system_performance_status_cpu_iowait Percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request. # TYPE fortigate_system_performance_status_cpu_iowait gauge - fortigate_system_performance_status_cpu_iowait{label="cpu_0"} 0 - fortigate_system_performance_status_cpu_iowait{label="cpu_1"} 0 + fortigate_system_performance_status_cpu_iowait{label="cpu_0",vdom="root"} 0 + fortigate_system_performance_status_cpu_iowait{label="cpu_1",vdom="root"} 0 # HELP fortigate_system_performance_status_cpu_nice Percentage of CPU utilization that occurred while executing at the user level with nice priority. # TYPE fortigate_system_performance_status_cpu_nice gauge - fortigate_system_performance_status_cpu_nice{label="cpu_0"} 0 - fortigate_system_performance_status_cpu_nice{label="cpu_1"} 0 + fortigate_system_performance_status_cpu_nice{label="cpu_0",vdom="root"} 0 + fortigate_system_performance_status_cpu_nice{label="cpu_1",vdom="root"} 0 # HELP fortigate_system_performance_status_cpu_system Percentage of CPU utilization that occurred while executing at the system level. # TYPE fortigate_system_performance_status_cpu_system gauge - fortigate_system_performance_status_cpu_system{label="cpu_0"} 0 - fortigate_system_performance_status_cpu_system{label="cpu_1"} 0 + fortigate_system_performance_status_cpu_system{label="cpu_0",vdom="root"} 0 + fortigate_system_performance_status_cpu_system{label="cpu_1",vdom="root"} 0 # HELP fortigate_system_performance_status_cpu_user Percentage of CPU utilization that occurred at the user level. # TYPE fortigate_system_performance_status_cpu_user gauge - fortigate_system_performance_status_cpu_user{label="cpu_0"} 200 - fortigate_system_performance_status_cpu_user{label="cpu_1"} 0 + fortigate_system_performance_status_cpu_user{label="cpu_0",vdom="root"} 200 + fortigate_system_performance_status_cpu_user{label="cpu_1",vdom="root"} 0 # HELP fortigate_system_performance_status_mem_free All the memory in RAM that is not being used for anything (even caches), in bytes. # TYPE fortigate_system_performance_status_mem_free gauge - fortigate_system_performance_status_mem_free{label="mem_0"} 0 - fortigate_system_performance_status_mem_free{label="mem_1"} 0 + fortigate_system_performance_status_mem_free{label="mem_0",vdom="root"} 0 + fortigate_system_performance_status_mem_free{label="mem_1",vdom="root"} 0 # HELP fortigate_system_performance_status_mem_freeable Freeable buffers/caches memory, in bytes. # TYPE fortigate_system_performance_status_mem_freeable gauge - fortigate_system_performance_status_mem_freeable{label="mem_0"} 0 - fortigate_system_performance_status_mem_freeable{label="mem_1"} 0 + fortigate_system_performance_status_mem_freeable{label="mem_0",vdom="root"} 0 + fortigate_system_performance_status_mem_freeable{label="mem_1",vdom="root"} 0 # HELP fortigate_system_performance_status_mem_total All the installed memory in RAM, in bytes. # TYPE fortigate_system_performance_status_mem_total gauge - fortigate_system_performance_status_mem_total{label="mem_0"} 0 - fortigate_system_performance_status_mem_total{label="mem_1"} 0 + fortigate_system_performance_status_mem_total{label="mem_0",vdom="root"} 0 + fortigate_system_performance_status_mem_total{label="mem_1",vdom="root"} 0 # HELP fortigate_system_performance_status_mem_used Memory are being used, in bytes. # TYPE fortigate_system_performance_status_mem_used gauge - fortigate_system_performance_status_mem_used{label="mem_0"} 0 - fortigate_system_performance_status_mem_used{label="mem_1"} 0 + fortigate_system_performance_status_mem_used{label="mem_0",vdom="root"} 0 + fortigate_system_performance_status_mem_used{label="mem_1",vdom="root"} 0 ` if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil { diff --git a/pkg/probe/testdata/system-performance-status.jsonnet b/pkg/probe/testdata/system-performance-status.jsonnet index 81c5b802..c43de7b6 100644 --- a/pkg/probe/testdata/system-performance-status.jsonnet +++ b/pkg/probe/testdata/system-performance-status.jsonnet @@ -1,5 +1,5 @@ # api/v2/monitor/system/performance/status -{ +[{ "http_method":"GET", "results": [ { @@ -73,4 +73,4 @@ "serial":"FGT61FT000000000", "version":"v6.0.10", "build":365 -} \ No newline at end of file +}] \ No newline at end of file From 2f70f7f2ac81566210474fb51b50d9cf4aa2e18f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96rnfeldt=20Philip=20=2866140321=29?= Date: Tue, 30 Sep 2025 08:24:08 +0200 Subject: [PATCH 3/7] Not supposed to run for all vdoms. Result not a list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Örnfeldt Philip (66140321) --- pkg/probe/system_performance_status.go | 66 ++++++------ pkg/probe/system_performance_status_test.go | 62 +++++------ .../system-performance-status.jsonnet | 102 +++++++----------- 3 files changed, 92 insertions(+), 138 deletions(-) diff --git a/pkg/probe/system_performance_status.go b/pkg/probe/system_performance_status.go index 018d86e7..b94726eb 100644 --- a/pkg/probe/system_performance_status.go +++ b/pkg/probe/system_performance_status.go @@ -51,47 +51,47 @@ func probeSystemPerformanceStatus(c http.FortiHTTP, meta *TargetMetadata) ([]pro cpuUser = prometheus.NewDesc( "fortigate_system_performance_status_cpu_user", "Percentage of CPU utilization that occurred at the user level.", - []string{"label", "vdom"}, nil, + []string{"vdom"}, nil, ) cpuSystem = prometheus.NewDesc( "fortigate_system_performance_status_cpu_system", "Percentage of CPU utilization that occurred while executing at the system level.", - []string{"label", "vdom"}, nil, + []string{"vdom"}, nil, ) cpuNice = prometheus.NewDesc( "fortigate_system_performance_status_cpu_nice", "Percentage of CPU utilization that occurred while executing at the user level with nice priority.", - []string{"label", "vdom"}, nil, + []string{"vdom"}, nil, ) cpuIdle = prometheus.NewDesc( "fortigate_system_performance_status_cpu_idle", "Percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request.", - []string{"label", "vdom"}, nil, + []string{"vdom"}, nil, ) cpuIowait = prometheus.NewDesc( "fortigate_system_performance_status_cpu_iowait", "Percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request.", - []string{"label", "vdom"}, nil, + []string{"vdom"}, nil, ) memTotal = prometheus.NewDesc( "fortigate_system_performance_status_mem_total", "All the installed memory in RAM, in bytes.", - []string{"label", "vdom"}, nil, + []string{"vdom"}, nil, ) memUsed = prometheus.NewDesc( "fortigate_system_performance_status_mem_used", "Memory are being used, in bytes.", - []string{"label", "vdom"}, nil, + []string{"vdom"}, nil, ) memFree = prometheus.NewDesc( "fortigate_system_performance_status_mem_free", "All the memory in RAM that is not being used for anything (even caches), in bytes.", - []string{"label", "vdom"}, nil, + []string{"vdom"}, nil, ) memFreeable = prometheus.NewDesc( "fortigate_system_performance_status_mem_freeable", "Freeable buffers/caches memory, in bytes.", - []string{"label", "vdom"}, nil, + []string{"vdom"}, nil, ) ) @@ -125,39 +125,33 @@ func probeSystemPerformanceStatus(c http.FortiHTTP, meta *TargetMetadata) ([]pro } type SystemPerformanceStatusResult struct { - Results []SystemPerformanceStatus `json:"results"` - VDOM string `json:"vdom"` + Results SystemPerformanceStatus `json:"results"` + VDOM string `json:"vdom"` } - var result []SystemPerformanceStatusResult - if err := c.Get("api/v2/monitor/system/performance/status", "vdom=*", &result); err != nil { + var res SystemPerformanceStatusResult + if err := c.Get("api/v2/monitor/system/performance/status", "", &res); err != nil { log.Printf("Error: %v", err) return nil, false } m := []prometheus.Metric{} - var cpu_num, mem_num, core_num string - for _, res := range result{ - for n, r := range res.Results { - cpu_num = "cpu_" + strconv.Itoa(n) - mem_num = "mem_" + strconv.Itoa(n) - for i, core := range r.Cpu.Cores { - core_num = "core_" + strconv.Itoa(i) - m = append(m, prometheus.MustNewConstMetric(cpuCoresUser, prometheus.GaugeValue, float64(core.User), cpu_num + "_" + core_num, res.VDOM)) - m = append(m, prometheus.MustNewConstMetric(cpuCoresSystem, prometheus.GaugeValue, float64(core.System), cpu_num + "_" + core_num, res.VDOM)) - m = append(m, prometheus.MustNewConstMetric(cpuCoresNice, prometheus.GaugeValue, float64(core.Nice), cpu_num + "_" + core_num, res.VDOM)) - m = append(m, prometheus.MustNewConstMetric(cpuCoresIdle, prometheus.GaugeValue, float64(core.Idle), cpu_num + "_" + core_num, res.VDOM)) - m = append(m, prometheus.MustNewConstMetric(cpuCoresIowait, prometheus.GaugeValue, float64(core.Iowait), cpu_num + "_" + core_num, res.VDOM)) - } - m = append(m, prometheus.MustNewConstMetric(cpuUser,prometheus.GaugeValue, float64(r.Cpu.User), cpu_num, res.VDOM)) - m = append(m, prometheus.MustNewConstMetric(cpuSystem,prometheus.GaugeValue, float64(r.Cpu.System), cpu_num, res.VDOM)) - m = append(m, prometheus.MustNewConstMetric(cpuNice,prometheus.GaugeValue, float64(r.Cpu.Nice), cpu_num, res.VDOM)) - m = append(m, prometheus.MustNewConstMetric(cpuIdle,prometheus.GaugeValue, float64(r.Cpu.Idle), cpu_num, res.VDOM)) - m = append(m, prometheus.MustNewConstMetric(cpuIowait,prometheus.GaugeValue, float64(r.Cpu.Iowait), cpu_num, res.VDOM)) - m = append(m, prometheus.MustNewConstMetric(memTotal,prometheus.GaugeValue, float64(r.Mem.Total), mem_num, res.VDOM)) - m = append(m, prometheus.MustNewConstMetric(memUsed,prometheus.GaugeValue, float64(r.Mem.Used), mem_num, res.VDOM)) - m = append(m, prometheus.MustNewConstMetric(memFree,prometheus.GaugeValue, float64(r.Mem.Free), mem_num, res.VDOM)) - m = append(m, prometheus.MustNewConstMetric(memFreeable,prometheus.GaugeValue, float64(r.Mem.Freeable), mem_num, res.VDOM)) - } + var core_num string + for i, core := range res.Results.Cpu.Cores { + core_num = "core_" + strconv.Itoa(i) + m = append(m, prometheus.MustNewConstMetric(cpuCoresUser, prometheus.GaugeValue, float64(core.User), core_num, res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(cpuCoresSystem, prometheus.GaugeValue, float64(core.System), core_num, res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(cpuCoresNice, prometheus.GaugeValue, float64(core.Nice), core_num, res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(cpuCoresIdle, prometheus.GaugeValue, float64(core.Idle), core_num, res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(cpuCoresIowait, prometheus.GaugeValue, float64(core.Iowait), core_num, res.VDOM)) } + m = append(m, prometheus.MustNewConstMetric(cpuUser,prometheus.GaugeValue, float64(res.Results.Cpu.User), res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(cpuSystem,prometheus.GaugeValue, float64(res.Results.Cpu.System), res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(cpuNice,prometheus.GaugeValue, float64(res.Results.Cpu.Nice), res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(cpuIdle,prometheus.GaugeValue, float64(res.Results.Cpu.Idle), res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(cpuIowait,prometheus.GaugeValue, float64(res.Results.Cpu.Iowait), res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(memTotal,prometheus.GaugeValue, float64(res.Results.Mem.Total), res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(memUsed,prometheus.GaugeValue, float64(res.Results.Mem.Used), res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(memFree,prometheus.GaugeValue, float64(res.Results.Mem.Free), res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(memFreeable,prometheus.GaugeValue, float64(res.Results.Mem.Freeable), res.VDOM)) return m, true } \ No newline at end of file diff --git a/pkg/probe/system_performance_status_test.go b/pkg/probe/system_performance_status_test.go index 87157465..838fb02b 100644 --- a/pkg/probe/system_performance_status_test.go +++ b/pkg/probe/system_performance_status_test.go @@ -32,70 +32,56 @@ func TestSystemPerformanceStatus(t *testing.T) { em := ` # HELP fortigate_system_performance_status_cpu_cores_idle Percentage of time that the CPU was idle and the system did not have an outstanding disk I/O request. # TYPE fortigate_system_performance_status_cpu_cores_idle gauge - fortigate_system_performance_status_cpu_cores_idle{label="cpu_0_core_0",vdom="root"} 0 - fortigate_system_performance_status_cpu_cores_idle{label="cpu_0_core_1",vdom="root"} 0 - fortigate_system_performance_status_cpu_cores_idle{label="cpu_0_core_2",vdom="root"} 0 - fortigate_system_performance_status_cpu_cores_idle{label="cpu_1_core_0",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_idle{label="core_0",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_idle{label="core_1",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_idle{label="core_2",vdom="root"} 0 # HELP fortigate_system_performance_status_cpu_cores_iowait Percentage of time that the CPU was idle during which the system had an outstanding disk I/O request. # TYPE fortigate_system_performance_status_cpu_cores_iowait gauge - fortigate_system_performance_status_cpu_cores_iowait{label="cpu_0_core_0",vdom="root"} 0 - fortigate_system_performance_status_cpu_cores_iowait{label="cpu_0_core_1",vdom="root"} 0 - fortigate_system_performance_status_cpu_cores_iowait{label="cpu_0_core_2",vdom="root"} 0 - fortigate_system_performance_status_cpu_cores_iowait{label="cpu_1_core_0",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_iowait{label="core_0",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_iowait{label="core_1",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_iowait{label="core_2",vdom="root"} 0 # HELP fortigate_system_performance_status_cpu_cores_nice Percentage of CPU utilization that occurred while executing at the user level with nice priority. # TYPE fortigate_system_performance_status_cpu_cores_nice gauge - fortigate_system_performance_status_cpu_cores_nice{label="cpu_0_core_0",vdom="root"} 0 - fortigate_system_performance_status_cpu_cores_nice{label="cpu_0_core_1",vdom="root"} 0 - fortigate_system_performance_status_cpu_cores_nice{label="cpu_0_core_2",vdom="root"} 0 - fortigate_system_performance_status_cpu_cores_nice{label="cpu_1_core_0",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_nice{label="core_0",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_nice{label="core_1",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_nice{label="core_2",vdom="root"} 0 # HELP fortigate_system_performance_status_cpu_cores_system Percentage of CPU utilization that occurred while executing at the system level. # TYPE fortigate_system_performance_status_cpu_cores_system gauge - fortigate_system_performance_status_cpu_cores_system{label="cpu_0_core_0",vdom="root"} 13 - fortigate_system_performance_status_cpu_cores_system{label="cpu_0_core_1",vdom="root"} 14 - fortigate_system_performance_status_cpu_cores_system{label="cpu_0_core_2",vdom="root"} 0 - fortigate_system_performance_status_cpu_cores_system{label="cpu_1_core_0",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_system{label="core_0",vdom="root"} 13 + fortigate_system_performance_status_cpu_cores_system{label="core_1",vdom="root"} 14 + fortigate_system_performance_status_cpu_cores_system{label="core_2",vdom="root"} 0 # HELP fortigate_system_performance_status_cpu_cores_user Percentage of CPU utilization that occurred at the user level. # TYPE fortigate_system_performance_status_cpu_cores_user gauge - fortigate_system_performance_status_cpu_cores_user{label="cpu_0_core_0",vdom="root"} 0 - fortigate_system_performance_status_cpu_cores_user{label="cpu_0_core_1",vdom="root"} 1 - fortigate_system_performance_status_cpu_cores_user{label="cpu_0_core_2",vdom="root"} 2 - fortigate_system_performance_status_cpu_cores_user{label="cpu_1_core_0",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_user{label="core_0",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_user{label="core_1",vdom="root"} 1 + fortigate_system_performance_status_cpu_cores_user{label="core_2",vdom="root"} 2 # HELP fortigate_system_performance_status_cpu_idle Percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request. # TYPE fortigate_system_performance_status_cpu_idle gauge - fortigate_system_performance_status_cpu_idle{label="cpu_0",vdom="root"} 0 - fortigate_system_performance_status_cpu_idle{label="cpu_1",vdom="root"} 0 + fortigate_system_performance_status_cpu_idle{vdom="root"} 0 # HELP fortigate_system_performance_status_cpu_iowait Percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request. # TYPE fortigate_system_performance_status_cpu_iowait gauge - fortigate_system_performance_status_cpu_iowait{label="cpu_0",vdom="root"} 0 - fortigate_system_performance_status_cpu_iowait{label="cpu_1",vdom="root"} 0 + fortigate_system_performance_status_cpu_iowait{vdom="root"} 0 # HELP fortigate_system_performance_status_cpu_nice Percentage of CPU utilization that occurred while executing at the user level with nice priority. # TYPE fortigate_system_performance_status_cpu_nice gauge - fortigate_system_performance_status_cpu_nice{label="cpu_0",vdom="root"} 0 - fortigate_system_performance_status_cpu_nice{label="cpu_1",vdom="root"} 0 + fortigate_system_performance_status_cpu_nice{vdom="root"} 0 # HELP fortigate_system_performance_status_cpu_system Percentage of CPU utilization that occurred while executing at the system level. # TYPE fortigate_system_performance_status_cpu_system gauge - fortigate_system_performance_status_cpu_system{label="cpu_0",vdom="root"} 0 - fortigate_system_performance_status_cpu_system{label="cpu_1",vdom="root"} 0 + fortigate_system_performance_status_cpu_system{vdom="root"} 0 # HELP fortigate_system_performance_status_cpu_user Percentage of CPU utilization that occurred at the user level. # TYPE fortigate_system_performance_status_cpu_user gauge - fortigate_system_performance_status_cpu_user{label="cpu_0",vdom="root"} 200 - fortigate_system_performance_status_cpu_user{label="cpu_1",vdom="root"} 0 + fortigate_system_performance_status_cpu_user{vdom="root"} 200 # HELP fortigate_system_performance_status_mem_free All the memory in RAM that is not being used for anything (even caches), in bytes. # TYPE fortigate_system_performance_status_mem_free gauge - fortigate_system_performance_status_mem_free{label="mem_0",vdom="root"} 0 - fortigate_system_performance_status_mem_free{label="mem_1",vdom="root"} 0 + fortigate_system_performance_status_mem_free{vdom="root"} 0 # HELP fortigate_system_performance_status_mem_freeable Freeable buffers/caches memory, in bytes. # TYPE fortigate_system_performance_status_mem_freeable gauge - fortigate_system_performance_status_mem_freeable{label="mem_0",vdom="root"} 0 - fortigate_system_performance_status_mem_freeable{label="mem_1",vdom="root"} 0 + fortigate_system_performance_status_mem_freeable{vdom="root"} 0 # HELP fortigate_system_performance_status_mem_total All the installed memory in RAM, in bytes. # TYPE fortigate_system_performance_status_mem_total gauge - fortigate_system_performance_status_mem_total{label="mem_0",vdom="root"} 0 - fortigate_system_performance_status_mem_total{label="mem_1",vdom="root"} 0 + fortigate_system_performance_status_mem_total{vdom="root"} 0 # HELP fortigate_system_performance_status_mem_used Memory are being used, in bytes. # TYPE fortigate_system_performance_status_mem_used gauge - fortigate_system_performance_status_mem_used{label="mem_0",vdom="root"} 0 - fortigate_system_performance_status_mem_used{label="mem_1",vdom="root"} 0 + fortigate_system_performance_status_mem_used{vdom="root"} 0 ` if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil { diff --git a/pkg/probe/testdata/system-performance-status.jsonnet b/pkg/probe/testdata/system-performance-status.jsonnet index c43de7b6..70bebbb1 100644 --- a/pkg/probe/testdata/system-performance-status.jsonnet +++ b/pkg/probe/testdata/system-performance-status.jsonnet @@ -1,70 +1,44 @@ # api/v2/monitor/system/performance/status -[{ +{ "http_method":"GET", - "results": [ - { - "cpu": { - "cores": [ - { - "user": 0, - "system": 13, - "nice": 0, - "idle": 0, - "iowait": 0 - }, - { - "user": 1, - "system": 14, - "nice": 0, - "idle": 0, - "iowait": 0 - }, - { - "user": 2, - "system": 0, - "nice": 0, - "idle": 0, - "iowait": 0 - } - ], - "user": 200, - "system": 0, - "nice": 0, - "idle": 0, - "iowait": 0 - }, - "mem": { - "total": 0, - "used": 0, - "free": 0, - "freeable": 0 - } + "results": { + "cpu": { + "cores": [ + { + "user": 0, + "system": 13, + "nice": 0, + "idle": 0, + "iowait": 0 + }, + { + "user": 1, + "system": 14, + "nice": 0, + "idle": 0, + "iowait": 0 + }, + { + "user": 2, + "system": 0, + "nice": 0, + "idle": 0, + "iowait": 0 + } + ], + "user": 200, + "system": 0, + "nice": 0, + "idle": 0, + "iowait": 0 }, - { - "cpu": { - "cores": [ - { - "user": 0, - "system": 0, - "nice": 0, - "idle": 0, - "iowait": 0 - } - ], - "user": 0, - "system": 0, - "nice": 0, - "idle": 0, - "iowait": 0 - }, - "mem": { - "total": 0, - "used": 0, - "free": 0, - "freeable": 0 - } + "mem": { + "total": 0, + "used": 0, + "free": 0, + "freeable": 0 } - ], + }, "vdom":"root", "path":"system", "name":"fortimanager", @@ -73,4 +47,4 @@ "serial":"FGT61FT000000000", "version":"v6.0.10", "build":365 -}] \ No newline at end of file +} \ No newline at end of file From 7ae2f7063b638851b5564e572a4fb7e3b69b1401 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96rnfeldt=20Philip=20=2866140321=29?= Date: Tue, 4 Nov 2025 15:38:58 +0100 Subject: [PATCH 4/7] Typo in text MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Örnfeldt Philip (66140321) --- pkg/probe/probe.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/probe/probe.go b/pkg/probe/probe.go index 70056045..8ac2b9dc 100644 --- a/pkg/probe/probe.go +++ b/pkg/probe/probe.go @@ -145,7 +145,7 @@ func (p *ProbeCollector) Probe(ctx context.Context, target map[string]string, hc {"System/HAStatistics", probeSystemHAStatistics}, {"System/Interface", probeSystemInterface}, {"System/LinkMonitor", probeSystemLinkMonitor}, - {"System/Perfomance/Status", probeSystemPerformanceStatus}, + {"System/Performance/Status", probeSystemPerformanceStatus}, {"System/Resource/Usage", probeSystemResourceUsage}, {"System/SDNConnector", probeSystemSDNConnector}, {"System/SensorInfo", probeSystemSensorInfo}, From 3205596fde9faee5cd1fa0502cf8b4a72fd4de75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96rnfeldt=20Philip=20=2866140321=29?= Date: Wed, 5 Nov 2025 08:43:28 +0100 Subject: [PATCH 5/7] New metric name standard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Örnfeldt Philip (66140321) --- pkg/probe/system_performance_status.go | 48 +-- pkg/probe/system_performance_status_test.go | 249 +++++++++++---- .../system-performance-status.jsonnet | 291 +++++++++++++++--- 3 files changed, 468 insertions(+), 120 deletions(-) diff --git a/pkg/probe/system_performance_status.go b/pkg/probe/system_performance_status.go index b94726eb..d3710f59 100644 --- a/pkg/probe/system_performance_status.go +++ b/pkg/probe/system_performance_status.go @@ -24,72 +24,72 @@ import ( func probeSystemPerformanceStatus(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) { var ( cpuCoresUser = prometheus.NewDesc( - "fortigate_system_performance_status_cpu_cores_user", + "fortigate_system_performance_status_cpu_cores_user_ratio", "Percentage of CPU utilization that occurred at the user level.", []string{"label", "vdom"}, nil, ) cpuCoresSystem = prometheus.NewDesc( - "fortigate_system_performance_status_cpu_cores_system", + "fortigate_system_performance_status_cpu_cores_system_ratio", "Percentage of CPU utilization that occurred while executing at the system level.", []string{"label", "vdom"}, nil, ) cpuCoresNice = prometheus.NewDesc( - "fortigate_system_performance_status_cpu_cores_nice", + "fortigate_system_performance_status_cpu_cores_nice_ratio", "Percentage of CPU utilization that occurred while executing at the user level with nice priority.", []string{"label", "vdom"}, nil, ) cpuCoresIdle = prometheus.NewDesc( - "fortigate_system_performance_status_cpu_cores_idle", + "fortigate_system_performance_status_cpu_cores_idle_ratio", "Percentage of time that the CPU was idle and the system did not have an outstanding disk I/O request.", []string{"label", "vdom"}, nil, ) cpuCoresIowait = prometheus.NewDesc( - "fortigate_system_performance_status_cpu_cores_iowait", + "fortigate_system_performance_status_cpu_cores_iowait_ratio", "Percentage of time that the CPU was idle during which the system had an outstanding disk I/O request.", []string{"label", "vdom"}, nil, ) cpuUser = prometheus.NewDesc( - "fortigate_system_performance_status_cpu_user", + "fortigate_system_performance_status_cpu_user_ratio", "Percentage of CPU utilization that occurred at the user level.", []string{"vdom"}, nil, ) cpuSystem = prometheus.NewDesc( - "fortigate_system_performance_status_cpu_system", + "fortigate_system_performance_status_cpu_system_ratio", "Percentage of CPU utilization that occurred while executing at the system level.", []string{"vdom"}, nil, ) cpuNice = prometheus.NewDesc( - "fortigate_system_performance_status_cpu_nice", + "fortigate_system_performance_status_cpu_nice_ratio", "Percentage of CPU utilization that occurred while executing at the user level with nice priority.", []string{"vdom"}, nil, ) cpuIdle = prometheus.NewDesc( - "fortigate_system_performance_status_cpu_idle", + "fortigate_system_performance_status_cpu_idle_ratio", "Percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request.", []string{"vdom"}, nil, ) cpuIowait = prometheus.NewDesc( - "fortigate_system_performance_status_cpu_iowait", + "fortigate_system_performance_status_cpu_iowait_ratio", "Percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request.", []string{"vdom"}, nil, ) memTotal = prometheus.NewDesc( - "fortigate_system_performance_status_mem_total", + "fortigate_system_performance_status_mem_bytes_total", "All the installed memory in RAM, in bytes.", []string{"vdom"}, nil, ) memUsed = prometheus.NewDesc( - "fortigate_system_performance_status_mem_used", + "fortigate_system_performance_status_mem_used_bytes", "Memory are being used, in bytes.", []string{"vdom"}, nil, ) memFree = prometheus.NewDesc( - "fortigate_system_performance_status_mem_free", + "fortigate_system_performance_status_mem_free_bytes", "All the memory in RAM that is not being used for anything (even caches), in bytes.", []string{"vdom"}, nil, ) memFreeable = prometheus.NewDesc( - "fortigate_system_performance_status_mem_freeable", + "fortigate_system_performance_status_mem_freeable_bytes", "Freeable buffers/caches memory, in bytes.", []string{"vdom"}, nil, ) @@ -138,17 +138,17 @@ func probeSystemPerformanceStatus(c http.FortiHTTP, meta *TargetMetadata) ([]pro var core_num string for i, core := range res.Results.Cpu.Cores { core_num = "core_" + strconv.Itoa(i) - m = append(m, prometheus.MustNewConstMetric(cpuCoresUser, prometheus.GaugeValue, float64(core.User), core_num, res.VDOM)) - m = append(m, prometheus.MustNewConstMetric(cpuCoresSystem, prometheus.GaugeValue, float64(core.System), core_num, res.VDOM)) - m = append(m, prometheus.MustNewConstMetric(cpuCoresNice, prometheus.GaugeValue, float64(core.Nice), core_num, res.VDOM)) - m = append(m, prometheus.MustNewConstMetric(cpuCoresIdle, prometheus.GaugeValue, float64(core.Idle), core_num, res.VDOM)) - m = append(m, prometheus.MustNewConstMetric(cpuCoresIowait, prometheus.GaugeValue, float64(core.Iowait), core_num, res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(cpuCoresUser, prometheus.GaugeValue, float64(core.User) * 0.01, core_num, res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(cpuCoresSystem, prometheus.GaugeValue, float64(core.System) * 0.01, core_num, res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(cpuCoresNice, prometheus.GaugeValue, float64(core.Nice) * 0.01, core_num, res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(cpuCoresIdle, prometheus.GaugeValue, float64(core.Idle) * 0.01, core_num, res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(cpuCoresIowait, prometheus.GaugeValue, float64(core.Iowait) * 0.01, core_num, res.VDOM)) } - m = append(m, prometheus.MustNewConstMetric(cpuUser,prometheus.GaugeValue, float64(res.Results.Cpu.User), res.VDOM)) - m = append(m, prometheus.MustNewConstMetric(cpuSystem,prometheus.GaugeValue, float64(res.Results.Cpu.System), res.VDOM)) - m = append(m, prometheus.MustNewConstMetric(cpuNice,prometheus.GaugeValue, float64(res.Results.Cpu.Nice), res.VDOM)) - m = append(m, prometheus.MustNewConstMetric(cpuIdle,prometheus.GaugeValue, float64(res.Results.Cpu.Idle), res.VDOM)) - m = append(m, prometheus.MustNewConstMetric(cpuIowait,prometheus.GaugeValue, float64(res.Results.Cpu.Iowait), res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(cpuUser,prometheus.GaugeValue, float64(res.Results.Cpu.User) * 0.01, res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(cpuSystem,prometheus.GaugeValue, float64(res.Results.Cpu.System) * 0.01, res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(cpuNice,prometheus.GaugeValue, float64(res.Results.Cpu.Nice) * 0.01, res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(cpuIdle,prometheus.GaugeValue, float64(res.Results.Cpu.Idle) * 0.01, res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(cpuIowait,prometheus.GaugeValue, float64(res.Results.Cpu.Iowait) * 0.01, res.VDOM)) m = append(m, prometheus.MustNewConstMetric(memTotal,prometheus.GaugeValue, float64(res.Results.Mem.Total), res.VDOM)) m = append(m, prometheus.MustNewConstMetric(memUsed,prometheus.GaugeValue, float64(res.Results.Mem.Used), res.VDOM)) m = append(m, prometheus.MustNewConstMetric(memFree,prometheus.GaugeValue, float64(res.Results.Mem.Free), res.VDOM)) diff --git a/pkg/probe/system_performance_status_test.go b/pkg/probe/system_performance_status_test.go index 838fb02b..b658b1c8 100644 --- a/pkg/probe/system_performance_status_test.go +++ b/pkg/probe/system_performance_status_test.go @@ -30,58 +30,203 @@ func TestSystemPerformanceStatus(t *testing.T) { } em := ` - # HELP fortigate_system_performance_status_cpu_cores_idle Percentage of time that the CPU was idle and the system did not have an outstanding disk I/O request. - # TYPE fortigate_system_performance_status_cpu_cores_idle gauge - fortigate_system_performance_status_cpu_cores_idle{label="core_0",vdom="root"} 0 - fortigate_system_performance_status_cpu_cores_idle{label="core_1",vdom="root"} 0 - fortigate_system_performance_status_cpu_cores_idle{label="core_2",vdom="root"} 0 - # HELP fortigate_system_performance_status_cpu_cores_iowait Percentage of time that the CPU was idle during which the system had an outstanding disk I/O request. - # TYPE fortigate_system_performance_status_cpu_cores_iowait gauge - fortigate_system_performance_status_cpu_cores_iowait{label="core_0",vdom="root"} 0 - fortigate_system_performance_status_cpu_cores_iowait{label="core_1",vdom="root"} 0 - fortigate_system_performance_status_cpu_cores_iowait{label="core_2",vdom="root"} 0 - # HELP fortigate_system_performance_status_cpu_cores_nice Percentage of CPU utilization that occurred while executing at the user level with nice priority. - # TYPE fortigate_system_performance_status_cpu_cores_nice gauge - fortigate_system_performance_status_cpu_cores_nice{label="core_0",vdom="root"} 0 - fortigate_system_performance_status_cpu_cores_nice{label="core_1",vdom="root"} 0 - fortigate_system_performance_status_cpu_cores_nice{label="core_2",vdom="root"} 0 - # HELP fortigate_system_performance_status_cpu_cores_system Percentage of CPU utilization that occurred while executing at the system level. - # TYPE fortigate_system_performance_status_cpu_cores_system gauge - fortigate_system_performance_status_cpu_cores_system{label="core_0",vdom="root"} 13 - fortigate_system_performance_status_cpu_cores_system{label="core_1",vdom="root"} 14 - fortigate_system_performance_status_cpu_cores_system{label="core_2",vdom="root"} 0 - # HELP fortigate_system_performance_status_cpu_cores_user Percentage of CPU utilization that occurred at the user level. - # TYPE fortigate_system_performance_status_cpu_cores_user gauge - fortigate_system_performance_status_cpu_cores_user{label="core_0",vdom="root"} 0 - fortigate_system_performance_status_cpu_cores_user{label="core_1",vdom="root"} 1 - fortigate_system_performance_status_cpu_cores_user{label="core_2",vdom="root"} 2 - # HELP fortigate_system_performance_status_cpu_idle Percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request. - # TYPE fortigate_system_performance_status_cpu_idle gauge - fortigate_system_performance_status_cpu_idle{vdom="root"} 0 - # HELP fortigate_system_performance_status_cpu_iowait Percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request. - # TYPE fortigate_system_performance_status_cpu_iowait gauge - fortigate_system_performance_status_cpu_iowait{vdom="root"} 0 - # HELP fortigate_system_performance_status_cpu_nice Percentage of CPU utilization that occurred while executing at the user level with nice priority. - # TYPE fortigate_system_performance_status_cpu_nice gauge - fortigate_system_performance_status_cpu_nice{vdom="root"} 0 - # HELP fortigate_system_performance_status_cpu_system Percentage of CPU utilization that occurred while executing at the system level. - # TYPE fortigate_system_performance_status_cpu_system gauge - fortigate_system_performance_status_cpu_system{vdom="root"} 0 - # HELP fortigate_system_performance_status_cpu_user Percentage of CPU utilization that occurred at the user level. - # TYPE fortigate_system_performance_status_cpu_user gauge - fortigate_system_performance_status_cpu_user{vdom="root"} 200 - # HELP fortigate_system_performance_status_mem_free All the memory in RAM that is not being used for anything (even caches), in bytes. - # TYPE fortigate_system_performance_status_mem_free gauge - fortigate_system_performance_status_mem_free{vdom="root"} 0 - # HELP fortigate_system_performance_status_mem_freeable Freeable buffers/caches memory, in bytes. - # TYPE fortigate_system_performance_status_mem_freeable gauge - fortigate_system_performance_status_mem_freeable{vdom="root"} 0 - # HELP fortigate_system_performance_status_mem_total All the installed memory in RAM, in bytes. - # TYPE fortigate_system_performance_status_mem_total gauge - fortigate_system_performance_status_mem_total{vdom="root"} 0 - # HELP fortigate_system_performance_status_mem_used Memory are being used, in bytes. - # TYPE fortigate_system_performance_status_mem_used gauge - fortigate_system_performance_status_mem_used{vdom="root"} 0 + # HELP fortigate_system_performance_status_cpu_cores_idle_ratio Percentage of time that the CPU was idle and the system did not have an outstanding disk I/O request. + # TYPE fortigate_system_performance_status_cpu_cores_idle_ratio gauge + fortigate_system_performance_status_cpu_cores_idle_ratio{label="core_0",vdom="root"} 1 + fortigate_system_performance_status_cpu_cores_idle_ratio{label="core_1",vdom="root"} 1 + fortigate_system_performance_status_cpu_cores_idle_ratio{label="core_10",vdom="root"} 1 + fortigate_system_performance_status_cpu_cores_idle_ratio{label="core_11",vdom="root"} 1 + fortigate_system_performance_status_cpu_cores_idle_ratio{label="core_12",vdom="root"} 1 + fortigate_system_performance_status_cpu_cores_idle_ratio{label="core_13",vdom="root"} 1 + fortigate_system_performance_status_cpu_cores_idle_ratio{label="core_14",vdom="root"} 1 + fortigate_system_performance_status_cpu_cores_idle_ratio{label="core_15",vdom="root"} 1 + fortigate_system_performance_status_cpu_cores_idle_ratio{label="core_16",vdom="root"} 1 + fortigate_system_performance_status_cpu_cores_idle_ratio{label="core_17",vdom="root"} 1 + fortigate_system_performance_status_cpu_cores_idle_ratio{label="core_18",vdom="root"} 1 + fortigate_system_performance_status_cpu_cores_idle_ratio{label="core_19",vdom="root"} 1 + fortigate_system_performance_status_cpu_cores_idle_ratio{label="core_2",vdom="root"} 0.53 + fortigate_system_performance_status_cpu_cores_idle_ratio{label="core_20",vdom="root"} 1 + fortigate_system_performance_status_cpu_cores_idle_ratio{label="core_21",vdom="root"} 1 + fortigate_system_performance_status_cpu_cores_idle_ratio{label="core_22",vdom="root"} 1 + fortigate_system_performance_status_cpu_cores_idle_ratio{label="core_23",vdom="root"} 1 + fortigate_system_performance_status_cpu_cores_idle_ratio{label="core_24",vdom="root"} 1 + fortigate_system_performance_status_cpu_cores_idle_ratio{label="core_25",vdom="root"} 1 + fortigate_system_performance_status_cpu_cores_idle_ratio{label="core_26",vdom="root"} 1 + fortigate_system_performance_status_cpu_cores_idle_ratio{label="core_27",vdom="root"} 1 + fortigate_system_performance_status_cpu_cores_idle_ratio{label="core_28",vdom="root"} 1 + fortigate_system_performance_status_cpu_cores_idle_ratio{label="core_29",vdom="root"} 1 + fortigate_system_performance_status_cpu_cores_idle_ratio{label="core_3",vdom="root"} 0.51 + fortigate_system_performance_status_cpu_cores_idle_ratio{label="core_30",vdom="root"} 1 + fortigate_system_performance_status_cpu_cores_idle_ratio{label="core_31",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_idle_ratio{label="core_4",vdom="root"} 0.99 + fortigate_system_performance_status_cpu_cores_idle_ratio{label="core_5",vdom="root"} 0.98 + fortigate_system_performance_status_cpu_cores_idle_ratio{label="core_6",vdom="root"} 0.92 + fortigate_system_performance_status_cpu_cores_idle_ratio{label="core_7",vdom="root"} 1 + fortigate_system_performance_status_cpu_cores_idle_ratio{label="core_8",vdom="root"} 0.92 + fortigate_system_performance_status_cpu_cores_idle_ratio{label="core_9",vdom="root"} 1 + # HELP fortigate_system_performance_status_cpu_cores_iowait_ratio Percentage of time that the CPU was idle during which the system had an outstanding disk I/O request. + # TYPE fortigate_system_performance_status_cpu_cores_iowait_ratio gauge + fortigate_system_performance_status_cpu_cores_iowait_ratio{label="core_0",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_iowait_ratio{label="core_1",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_iowait_ratio{label="core_10",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_iowait_ratio{label="core_11",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_iowait_ratio{label="core_12",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_iowait_ratio{label="core_13",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_iowait_ratio{label="core_14",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_iowait_ratio{label="core_15",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_iowait_ratio{label="core_16",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_iowait_ratio{label="core_17",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_iowait_ratio{label="core_18",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_iowait_ratio{label="core_19",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_iowait_ratio{label="core_2",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_iowait_ratio{label="core_20",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_iowait_ratio{label="core_21",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_iowait_ratio{label="core_22",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_iowait_ratio{label="core_23",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_iowait_ratio{label="core_24",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_iowait_ratio{label="core_25",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_iowait_ratio{label="core_26",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_iowait_ratio{label="core_27",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_iowait_ratio{label="core_28",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_iowait_ratio{label="core_29",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_iowait_ratio{label="core_3",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_iowait_ratio{label="core_30",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_iowait_ratio{label="core_31",vdom="root"} 1 + fortigate_system_performance_status_cpu_cores_iowait_ratio{label="core_4",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_iowait_ratio{label="core_5",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_iowait_ratio{label="core_6",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_iowait_ratio{label="core_7",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_iowait_ratio{label="core_8",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_iowait_ratio{label="core_9",vdom="root"} 0 + # HELP fortigate_system_performance_status_cpu_cores_nice_ratio Percentage of CPU utilization that occurred while executing at the user level with nice priority. + # TYPE fortigate_system_performance_status_cpu_cores_nice_ratio gauge + fortigate_system_performance_status_cpu_cores_nice_ratio{label="core_0",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_nice_ratio{label="core_1",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_nice_ratio{label="core_10",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_nice_ratio{label="core_11",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_nice_ratio{label="core_12",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_nice_ratio{label="core_13",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_nice_ratio{label="core_14",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_nice_ratio{label="core_15",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_nice_ratio{label="core_16",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_nice_ratio{label="core_17",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_nice_ratio{label="core_18",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_nice_ratio{label="core_19",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_nice_ratio{label="core_2",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_nice_ratio{label="core_20",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_nice_ratio{label="core_21",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_nice_ratio{label="core_22",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_nice_ratio{label="core_23",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_nice_ratio{label="core_24",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_nice_ratio{label="core_25",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_nice_ratio{label="core_26",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_nice_ratio{label="core_27",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_nice_ratio{label="core_28",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_nice_ratio{label="core_29",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_nice_ratio{label="core_3",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_nice_ratio{label="core_30",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_nice_ratio{label="core_31",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_nice_ratio{label="core_4",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_nice_ratio{label="core_5",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_nice_ratio{label="core_6",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_nice_ratio{label="core_7",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_nice_ratio{label="core_8",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_nice_ratio{label="core_9",vdom="root"} 0 + # HELP fortigate_system_performance_status_cpu_cores_system_ratio Percentage of CPU utilization that occurred while executing at the system level. + # TYPE fortigate_system_performance_status_cpu_cores_system_ratio gauge + fortigate_system_performance_status_cpu_cores_system_ratio{label="core_0",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_system_ratio{label="core_1",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_system_ratio{label="core_10",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_system_ratio{label="core_11",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_system_ratio{label="core_12",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_system_ratio{label="core_13",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_system_ratio{label="core_14",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_system_ratio{label="core_15",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_system_ratio{label="core_16",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_system_ratio{label="core_17",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_system_ratio{label="core_18",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_system_ratio{label="core_19",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_system_ratio{label="core_2",vdom="root"} 0.2 + fortigate_system_performance_status_cpu_cores_system_ratio{label="core_20",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_system_ratio{label="core_21",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_system_ratio{label="core_22",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_system_ratio{label="core_23",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_system_ratio{label="core_24",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_system_ratio{label="core_25",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_system_ratio{label="core_26",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_system_ratio{label="core_27",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_system_ratio{label="core_28",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_system_ratio{label="core_29",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_system_ratio{label="core_3",vdom="root"} 0.18 + fortigate_system_performance_status_cpu_cores_system_ratio{label="core_30",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_system_ratio{label="core_31",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_system_ratio{label="core_4",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_system_ratio{label="core_5",vdom="root"} 0.01 + fortigate_system_performance_status_cpu_cores_system_ratio{label="core_6",vdom="root"} 0.01 + fortigate_system_performance_status_cpu_cores_system_ratio{label="core_7",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_system_ratio{label="core_8",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_system_ratio{label="core_9",vdom="root"} 0 + # HELP fortigate_system_performance_status_cpu_cores_user_ratio Percentage of CPU utilization that occurred at the user level. + # TYPE fortigate_system_performance_status_cpu_cores_user_ratio gauge + fortigate_system_performance_status_cpu_cores_user_ratio{label="core_0",vdom="root"} 0. + fortigate_system_performance_status_cpu_cores_user_ratio{label="core_1",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_user_ratio{label="core_10",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_user_ratio{label="core_11",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_user_ratio{label="core_12",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_user_ratio{label="core_13",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_user_ratio{label="core_14",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_user_ratio{label="core_15",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_user_ratio{label="core_16",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_user_ratio{label="core_17",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_user_ratio{label="core_18",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_user_ratio{label="core_19",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_user_ratio{label="core_2",vdom="root"} 0.27 + fortigate_system_performance_status_cpu_cores_user_ratio{label="core_20",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_user_ratio{label="core_21",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_user_ratio{label="core_22",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_user_ratio{label="core_23",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_user_ratio{label="core_24",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_user_ratio{label="core_25",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_user_ratio{label="core_26",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_user_ratio{label="core_27",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_user_ratio{label="core_28",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_user_ratio{label="core_29",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_user_ratio{label="core_3",vdom="root"} 0.31 + fortigate_system_performance_status_cpu_cores_user_ratio{label="core_30",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_user_ratio{label="core_31",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_user_ratio{label="core_4",vdom="root"} 0.01 + fortigate_system_performance_status_cpu_cores_user_ratio{label="core_5",vdom="root"} 0.01 + fortigate_system_performance_status_cpu_cores_user_ratio{label="core_6",vdom="root"} 0.07 + fortigate_system_performance_status_cpu_cores_user_ratio{label="core_7",vdom="root"} 0 + fortigate_system_performance_status_cpu_cores_user_ratio{label="core_8",vdom="root"} 0.08 + fortigate_system_performance_status_cpu_cores_user_ratio{label="core_9",vdom="root"} 0 + # HELP fortigate_system_performance_status_cpu_idle_ratio Percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request. + # TYPE fortigate_system_performance_status_cpu_idle_ratio gauge + fortigate_system_performance_status_cpu_idle_ratio{vdom="root"} 0.97 + # HELP fortigate_system_performance_status_cpu_iowait_ratio Percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request. + # TYPE fortigate_system_performance_status_cpu_iowait_ratio gauge + fortigate_system_performance_status_cpu_iowait_ratio{vdom="root"} 0 + # HELP fortigate_system_performance_status_cpu_nice_ratio Percentage of CPU utilization that occurred while executing at the user level with nice priority. + # TYPE fortigate_system_performance_status_cpu_nice_ratio gauge + fortigate_system_performance_status_cpu_nice_ratio{vdom="root"} 0 + # HELP fortigate_system_performance_status_cpu_system_ratio Percentage of CPU utilization that occurred while executing at the system level. + # TYPE fortigate_system_performance_status_cpu_system_ratio gauge + fortigate_system_performance_status_cpu_system_ratio{vdom="root"} 0.01 + # HELP fortigate_system_performance_status_cpu_user_ratio Percentage of CPU utilization that occurred at the user level. + # TYPE fortigate_system_performance_status_cpu_user_ratio gauge + fortigate_system_performance_status_cpu_user_ratio{vdom="root"} 0.02 + # HELP fortigate_system_performance_status_mem_free_bytes All the memory in RAM that is not being used for anything (even caches), in bytes. + # TYPE fortigate_system_performance_status_mem_free_bytes gauge + fortigate_system_performance_status_mem_free_bytes{vdom="root"} 361498 + # HELP fortigate_system_performance_status_mem_freeable_bytes Freeable buffers/caches memory, in bytes. + # TYPE fortigate_system_performance_status_mem_freeable_bytes gauge + fortigate_system_performance_status_mem_freeable_bytes{vdom="root"} 5299 + # HELP fortigate_system_performance_status_mem_bytes_total All the installed memory in RAM, in bytes. + # TYPE fortigate_system_performance_status_mem_bytes_total gauge + fortigate_system_performance_status_mem_bytes_total{vdom="root"} 50727878 + # HELP fortigate_system_performance_status_mem_used_bytes Memory are being used, in bytes. + # TYPE fortigate_system_performance_status_mem_used_bytes gauge + fortigate_system_performance_status_mem_used_bytes{vdom="root"} 140480780 ` if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil { diff --git a/pkg/probe/testdata/system-performance-status.jsonnet b/pkg/probe/testdata/system-performance-status.jsonnet index 70bebbb1..e67bc2ef 100644 --- a/pkg/probe/testdata/system-performance-status.jsonnet +++ b/pkg/probe/testdata/system-performance-status.jsonnet @@ -1,50 +1,253 @@ # api/v2/monitor/system/performance/status { - "http_method":"GET", - "results": { - "cpu": { - "cores": [ - { - "user": 0, - "system": 13, - "nice": 0, - "idle": 0, - "iowait": 0 + "http_method": "GET", + "results": { + "cpu": { + "cores": [ + { + "user": 0, + "system": 0, + "nice": 0, + "idle": 100, + "iowait": 0 + }, + { + "user": 0, + "system": 0, + "nice": 0, + "idle": 100, + "iowait": 0 + }, + { + "user": 27, + "system": 20, + "nice": 0, + "idle": 53, + "iowait": 0 + }, + { + "user": 31, + "system": 18, + "nice": 0, + "idle": 51, + "iowait": 0 + }, + { + "user": 1, + "system": 0, + "nice": 0, + "idle": 99, + "iowait": 0 + }, + { + "user": 1, + "system": 1, + "nice": 0, + "idle": 98, + "iowait": 0 + }, + { + "user": 7, + "system": 1, + "nice": 0, + "idle": 92, + "iowait": 0 + }, + { + "user": 0, + "system": 0, + "nice": 0, + "idle": 100, + "iowait": 0 + }, + { + "user": 8, + "system": 0, + "nice": 0, + "idle": 92, + "iowait": 0 + }, + { + "user": 0, + "system": 0, + "nice": 0, + "idle": 100, + "iowait": 0 + }, + { + "user": 0, + "system": 0, + "nice": 0, + "idle": 100, + "iowait": 0 + }, + { + "user": 0, + "system": 0, + "nice": 0, + "idle": 100, + "iowait": 0 + }, + { + "user": 0, + "system": 0, + "nice": 0, + "idle": 100, + "iowait": 0 + }, + { + "user": 0, + "system": 0, + "nice": 0, + "idle": 100, + "iowait": 0 + }, + { + "user": 0, + "system": 0, + "nice": 0, + "idle": 100, + "iowait": 0 + }, + { + "user": 0, + "system": 0, + "nice": 0, + "idle": 100, + "iowait": 0 + }, + { + "user": 0, + "system": 0, + "nice": 0, + "idle": 100, + "iowait": 0 + }, + { + "user": 0, + "system": 0, + "nice": 0, + "idle": 100, + "iowait": 0 + }, + { + "user": 0, + "system": 0, + "nice": 0, + "idle": 100, + "iowait": 0 + }, + { + "user": 0, + "system": 0, + "nice": 0, + "idle": 100, + "iowait": 0 + }, + { + "user": 0, + "system": 0, + "nice": 0, + "idle": 100, + "iowait": 0 + }, + { + "user": 0, + "system": 0, + "nice": 0, + "idle": 100, + "iowait": 0 + }, + { + "user": 0, + "system": 0, + "nice": 0, + "idle": 100, + "iowait": 0 + }, + { + "user": 0, + "system": 0, + "nice": 0, + "idle": 100, + "iowait": 0 + }, + { + "user": 0, + "system": 0, + "nice": 0, + "idle": 100, + "iowait": 0 + }, + { + "user": 0, + "system": 0, + "nice": 0, + "idle": 100, + "iowait": 0 + }, + { + "user": 0, + "system": 0, + "nice": 0, + "idle": 100, + "iowait": 0 + }, + { + "user": 0, + "system": 0, + "nice": 0, + "idle": 100, + "iowait": 0 + }, + { + "user": 0, + "system": 0, + "nice": 0, + "idle": 100, + "iowait": 0 + }, + { + "user": 0, + "system": 0, + "nice": 0, + "idle": 100, + "iowait": 0 + }, + { + "user": 0, + "system": 0, + "nice": 0, + "idle": 100, + "iowait": 0 + }, + { + "user": 0, + "system": 0, + "nice": 0, + "idle": 0, + "iowait": 100 + } + ], + "user": 2, + "system": 1, + "nice": 0, + "idle": 97, + "iowait": 0 }, - { - "user": 1, - "system": 14, - "nice": 0, - "idle": 0, - "iowait": 0 - }, - { - "user": 2, - "system": 0, - "nice": 0, - "idle": 0, - "iowait": 0 + "mem": { + "total": 50727878, + "used": 140480780, + "free": 361498, + "freeable": 5299 } - ], - "user": 200, - "system": 0, - "nice": 0, - "idle": 0, - "iowait": 0 }, - "mem": { - "total": 0, - "used": 0, - "free": 0, - "freeable": 0 - } - }, - "vdom":"root", - "path":"system", - "name":"fortimanager", - "action":"status", - "status":"success", - "serial":"FGT61FT000000000", - "version":"v6.0.10", - "build":365 + "vdom": "root", + "path": "system", + "name": "performance", + "action": "status", + "status": "success", + "serial": "F2", + "version": "v7.4.9", + "build": 2829 } \ No newline at end of file From 3e72f6eb05313897c120df56382b05677203e83e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96rnfeldt=20Philip=20=2866140321=29?= Date: Wed, 5 Nov 2025 10:12:05 +0100 Subject: [PATCH 6/7] Update Readme MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Örnfeldt Philip (66140321) --- README.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 03349b2d..8edc82c1 100755 --- a/README.md +++ b/README.md @@ -50,20 +50,20 @@ Global: * `fortigate_memory_usage_ratio` * `fortigate_current_sessions` * _System/Performance/status/_ - * `fortigate_system_performance_status_cpu_cores_idle` - * `fortigate_system_performance_status_cpu_cores_iowait` - * `fortigate_system_performance_status_cpu_cores_nice` - * `fortigate_system_performance_status_cpu_cores_system` - * `fortigate_system_performance_status_cpu_cores_user` - * `fortigate_system_performance_status_cpu_idle` - * `fortigate_system_performance_status_cpu_iowait` - * `fortigate_system_performance_status_cpu_nice` - * `fortigate_system_performance_status_cpu_system` - * `fortigate_system_performance_status_cpu_user` - * `fortigate_system_performance_status_mem_free` - * `fortigate_system_performance_status_mem_freeable` - * `fortigate_system_performance_status_mem_total` - * `fortigate_system_performance_status_mem_used` + * `fortigate_system_performance_status_cpu_cores_idle_ratio` + * `fortigate_system_performance_status_cpu_cores_iowait_ratio` + * `fortigate_system_performance_status_cpu_cores_nice_ratio` + * `fortigate_system_performance_status_cpu_cores_system_ratio` + * `fortigate_system_performance_status_cpu_cores_user_ratio` + * `fortigate_system_performance_status_cpu_idle_ratio` + * `fortigate_system_performance_status_cpu_iowait_ratio` + * `fortigate_system_performance_status_cpu_nice_ratio` + * `fortigate_system_performance_status_cpu_system_ratio` + * `fortigate_system_performance_status_cpu_user_ratio` + * `fortigate_system_performance_status_mem_free_bytes` + * `fortigate_system_performance_status_mem_freeable_bytes` + * `fortigate_system_performance_status_mem_bytes_total` + * `fortigate_system_performance_status_mem_used_bytes` * _System/HAChecksums_ * `fortigate_ha_member_has_role` * _License/Status_ From f4663036402725bf89a26e75074cfeef518bed4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96rnfeldt=20Philip=20=2866140321=29?= Date: Thu, 13 Nov 2025 20:08:45 +0100 Subject: [PATCH 7/7] Lint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Örnfeldt Philip (66140321) --- pkg/probe/probe.go | 2 +- pkg/probe/system_performance_status.go | 45 +++++++------- pkg/probe/system_performance_status_test.go | 2 +- pkg/probe/system_vdom-resource.go | 66 ++++++++++----------- 4 files changed, 58 insertions(+), 57 deletions(-) diff --git a/pkg/probe/probe.go b/pkg/probe/probe.go index 6961b501..53b8c776 100644 --- a/pkg/probe/probe.go +++ b/pkg/probe/probe.go @@ -156,7 +156,7 @@ func (p *Collector) Probe(ctx context.Context, target map[string]string, hc *htt {"System/SDNConnector", probeSystemSDNConnector}, {"System/SensorInfo", probeSystemSensorInfo}, {"System/Status", probeSystemStatus}, - {"System/VDOMResource",probeSystemVdomResource}, + {"System/VDOMResource", probeSystemVdomResource}, {"System/HAChecksum", probeSystemHAChecksum}, {"User/Fsso", probeUserFsso}, {"VPN/IPSec", probeVPNIPSec}, diff --git a/pkg/probe/system_performance_status.go b/pkg/probe/system_performance_status.go index d3710f59..29e736d0 100644 --- a/pkg/probe/system_performance_status.go +++ b/pkg/probe/system_performance_status.go @@ -17,11 +17,12 @@ import ( "log" "strconv" - "github.com/prometheus-community/fortigate_exporter/pkg/http" "github.com/prometheus/client_golang/prometheus" + + "github.com/prometheus-community/fortigate_exporter/pkg/http" ) -func probeSystemPerformanceStatus(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) { +func probeSystemPerformanceStatus(c http.FortiHTTP, _ *TargetMetadata) ([]prometheus.Metric, bool) { var ( cpuCoresUser = prometheus.NewDesc( "fortigate_system_performance_status_cpu_cores_user_ratio", @@ -103,7 +104,7 @@ func probeSystemPerformanceStatus(c http.FortiHTTP, meta *TargetMetadata) ([]pro Iowait int `json:"iowait"` } - type SystemPerformanceStatusCpu struct { + type SystemPerformanceStatusCPU struct { Cores []SystemPerformanceStatusCores `json:"cores"` User int `json:"user"` System int `json:"system"` @@ -120,7 +121,7 @@ func probeSystemPerformanceStatus(c http.FortiHTTP, meta *TargetMetadata) ([]pro } type SystemPerformanceStatus struct { - Cpu SystemPerformanceStatusCpu `json:"cpu"` + CPU SystemPerformanceStatusCPU `json:"cpu"` Mem SystemPerformanceStatusMem `json:"mem"` } @@ -135,23 +136,23 @@ func probeSystemPerformanceStatus(c http.FortiHTTP, meta *TargetMetadata) ([]pro return nil, false } m := []prometheus.Metric{} - var core_num string - for i, core := range res.Results.Cpu.Cores { - core_num = "core_" + strconv.Itoa(i) - m = append(m, prometheus.MustNewConstMetric(cpuCoresUser, prometheus.GaugeValue, float64(core.User) * 0.01, core_num, res.VDOM)) - m = append(m, prometheus.MustNewConstMetric(cpuCoresSystem, prometheus.GaugeValue, float64(core.System) * 0.01, core_num, res.VDOM)) - m = append(m, prometheus.MustNewConstMetric(cpuCoresNice, prometheus.GaugeValue, float64(core.Nice) * 0.01, core_num, res.VDOM)) - m = append(m, prometheus.MustNewConstMetric(cpuCoresIdle, prometheus.GaugeValue, float64(core.Idle) * 0.01, core_num, res.VDOM)) - m = append(m, prometheus.MustNewConstMetric(cpuCoresIowait, prometheus.GaugeValue, float64(core.Iowait) * 0.01, core_num, res.VDOM)) + var coreNum string + for i, core := range res.Results.CPU.Cores { + coreNum = "core_" + strconv.Itoa(i) + m = append(m, prometheus.MustNewConstMetric(cpuCoresUser, prometheus.GaugeValue, float64(core.User)*0.01, coreNum, res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(cpuCoresSystem, prometheus.GaugeValue, float64(core.System)*0.01, coreNum, res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(cpuCoresNice, prometheus.GaugeValue, float64(core.Nice)*0.01, coreNum, res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(cpuCoresIdle, prometheus.GaugeValue, float64(core.Idle)*0.01, coreNum, res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(cpuCoresIowait, prometheus.GaugeValue, float64(core.Iowait)*0.01, coreNum, res.VDOM)) } - m = append(m, prometheus.MustNewConstMetric(cpuUser,prometheus.GaugeValue, float64(res.Results.Cpu.User) * 0.01, res.VDOM)) - m = append(m, prometheus.MustNewConstMetric(cpuSystem,prometheus.GaugeValue, float64(res.Results.Cpu.System) * 0.01, res.VDOM)) - m = append(m, prometheus.MustNewConstMetric(cpuNice,prometheus.GaugeValue, float64(res.Results.Cpu.Nice) * 0.01, res.VDOM)) - m = append(m, prometheus.MustNewConstMetric(cpuIdle,prometheus.GaugeValue, float64(res.Results.Cpu.Idle) * 0.01, res.VDOM)) - m = append(m, prometheus.MustNewConstMetric(cpuIowait,prometheus.GaugeValue, float64(res.Results.Cpu.Iowait) * 0.01, res.VDOM)) - m = append(m, prometheus.MustNewConstMetric(memTotal,prometheus.GaugeValue, float64(res.Results.Mem.Total), res.VDOM)) - m = append(m, prometheus.MustNewConstMetric(memUsed,prometheus.GaugeValue, float64(res.Results.Mem.Used), res.VDOM)) - m = append(m, prometheus.MustNewConstMetric(memFree,prometheus.GaugeValue, float64(res.Results.Mem.Free), res.VDOM)) - m = append(m, prometheus.MustNewConstMetric(memFreeable,prometheus.GaugeValue, float64(res.Results.Mem.Freeable), res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(cpuUser, prometheus.GaugeValue, float64(res.Results.CPU.User)*0.01, res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(cpuSystem, prometheus.GaugeValue, float64(res.Results.CPU.System)*0.01, res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(cpuNice, prometheus.GaugeValue, float64(res.Results.CPU.Nice)*0.01, res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(cpuIdle, prometheus.GaugeValue, float64(res.Results.CPU.Idle)*0.01, res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(cpuIowait, prometheus.GaugeValue, float64(res.Results.CPU.Iowait)*0.01, res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(memTotal, prometheus.GaugeValue, float64(res.Results.Mem.Total), res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(memUsed, prometheus.GaugeValue, float64(res.Results.Mem.Used), res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(memFree, prometheus.GaugeValue, float64(res.Results.Mem.Free), res.VDOM)) + m = append(m, prometheus.MustNewConstMetric(memFreeable, prometheus.GaugeValue, float64(res.Results.Mem.Freeable), res.VDOM)) return m, true -} \ No newline at end of file +} diff --git a/pkg/probe/system_performance_status_test.go b/pkg/probe/system_performance_status_test.go index b658b1c8..93955fbd 100644 --- a/pkg/probe/system_performance_status_test.go +++ b/pkg/probe/system_performance_status_test.go @@ -232,4 +232,4 @@ func TestSystemPerformanceStatus(t *testing.T) { if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil { t.Fatalf("metric compare: err %v", err) } -} \ No newline at end of file +} diff --git a/pkg/probe/system_vdom-resource.go b/pkg/probe/system_vdom-resource.go index c955a61a..a37e76c9 100644 --- a/pkg/probe/system_vdom-resource.go +++ b/pkg/probe/system_vdom-resource.go @@ -16,12 +16,12 @@ package probe import ( "log" - "github.com/prometheus-community/fortigate_exporter/pkg/http" "github.com/prometheus/client_golang/prometheus" + + "github.com/prometheus-community/fortigate_exporter/pkg/http" ) -func probeSystemVdomResource(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) { - +func probeSystemVdomResource(c http.FortiHTTP, _ *TargetMetadata) ([]prometheus.Metric, bool) { vdomDesc := make(map[string]*prometheus.Desc) vdomDesc["cpu"] = prometheus.NewDesc( "fortigate_vdom_resource_cpu_usage_ratio", @@ -46,12 +46,12 @@ func probeSystemVdomResource(c http.FortiHTTP, meta *TargetMetadata) ([]promethe vdomDesc["id"] = prometheus.NewDesc( "fortigate_vdom_resource_object_id", "Object Resource ID", - []string{"vdom", "object"},nil, + []string{"vdom", "object"}, nil, ) vdomDesc["custom_max"] = prometheus.NewDesc( "fortigate_vdom_resource_object_custom_max", "Object Custom Max", - []string{"vdom", "object"},nil, + []string{"vdom", "object"}, nil, ) vdomDesc["min_custom_value"] = prometheus.NewDesc( "fortigate_vdom_resource_object_custom_min_value", @@ -61,42 +61,42 @@ func probeSystemVdomResource(c http.FortiHTTP, meta *TargetMetadata) ([]promethe vdomDesc["max_custom_value"] = prometheus.NewDesc( "fortigate_vdom_resource_object_custom_max_value", "Object Maximum custom value", - []string{"vdom", "object"},nil, + []string{"vdom", "object"}, nil, ) vdomDesc["guaranteed"] = prometheus.NewDesc( "fortigate_vdom_resource_object_guaranteed", "Object Guaranteed", - []string{"vdom", "object"},nil, + []string{"vdom", "object"}, nil, ) vdomDesc["min_guaranteed_value"] = prometheus.NewDesc( "fortigate_vdom_resource_object_guaranteed_max_value", "Object Minimum guaranteed value", - []string{"vdom", "object"},nil, + []string{"vdom", "object"}, nil, ) vdomDesc["max_guaranteed_value"] = prometheus.NewDesc( "fortigate_vdom_resource_object_guaranteed_min_value", "Object Maximum guaranteed value", - []string{"vdom", "object"},nil, + []string{"vdom", "object"}, nil, ) vdomDesc["global_max"] = prometheus.NewDesc( "fortigate_vdom_resource_object_global_max", "Object Global max", - []string{"vdom", "object"},nil, + []string{"vdom", "object"}, nil, ) vdomDesc["current_usage"] = prometheus.NewDesc( "fortigate_vdom_resource_object_current_usage", "Object Current usage", - []string{"vdom", "object"},nil, + []string{"vdom", "object"}, nil, ) vdomDesc["usage_percent"] = prometheus.NewDesc( "fortigate_vdom_resource_object_usage_ratio", "Object Usage percentage", - []string{"vdom", "object"},nil, + []string{"vdom", "object"}, nil, ) type VDOMResourceResult struct { - Result interface{} `json:"results"` - Vdom string `json:"vdom"` + Result any `json:"results"` + Vdom string `json:"vdom"` } var res []VDOMResourceResult @@ -107,7 +107,7 @@ func probeSystemVdomResource(c http.FortiHTTP, meta *TargetMetadata) ([]promethe m := []prometheus.Metric{} for _, result := range res { - for k, elem := range result.Result.(map[string]interface{}) { + for k, elem := range result.Result.(map[string]any) { switch k { case "cpu", "memory", "setup_rate": m = append(m, prometheus.MustNewConstMetric(vdomDesc[k], prometheus.GaugeValue, elem.(float64), result.Vdom)) @@ -118,24 +118,24 @@ func probeSystemVdomResource(c http.FortiHTTP, meta *TargetMetadata) ([]promethe m = append(m, prometheus.MustNewConstMetric(vdomDesc[k], prometheus.GaugeValue, 0, result.Vdom)) } case "session", - "ipsec-phase1", - "ipsec-phase2", - "ipsec-phase1-interface", - "ipsec-phase2-interface", - "dialup-tunnel", - "firewall-policy", - "firewall-address", - "firewall-addrgrp", - "custom-service", - "service-group", - "onetime-schedule", - "recurring-schedule", - "user", - "user-group", - "sslvpn", - "proxy", - "log-disk-quota": - for val, e := range elem.(map[string]interface{}) { + "ipsec-phase1", + "ipsec-phase2", + "ipsec-phase1-interface", + "ipsec-phase2-interface", + "dialup-tunnel", + "firewall-policy", + "firewall-address", + "firewall-addrgrp", + "custom-service", + "service-group", + "onetime-schedule", + "recurring-schedule", + "user", + "user-group", + "sslvpn", + "proxy", + "log-disk-quota": + for val, e := range elem.(map[string]any) { m = append(m, prometheus.MustNewConstMetric(vdomDesc[val], prometheus.GaugeValue, e.(float64), result.Vdom, k)) } default: