Skip to content

Commit 6f7f897

Browse files
committed
Performance status probe added
Signed-off-by: Örnfeldt Philip (66140321) <philip.ornfeldt@forsakringskassan.se>
1 parent afcfb5f commit 6f7f897

File tree

5 files changed

+358
-0
lines changed

5 files changed

+358
-0
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,21 @@ Global:
4949
* `fortigate_cpu_usage_ratio`
5050
* `fortigate_memory_usage_ratio`
5151
* `fortigate_current_sessions`
52+
* _System/Performance/status/_
53+
* `fortigate_system_performance_status_cpu_cores_idle`
54+
* `fortigate_system_performance_status_cpu_cores_iowait`
55+
* `fortigate_system_performance_status_cpu_cores_nice`
56+
* `fortigate_system_performance_status_cpu_cores_system`
57+
* `fortigate_system_performance_status_cpu_cores_user`
58+
* `fortigate_system_performance_status_cpu_idle`
59+
* `fortigate_system_performance_status_cpu_iowait`
60+
* `fortigate_system_performance_status_cpu_nice`
61+
* `fortigate_system_performance_status_cpu_system`
62+
* `fortigate_system_performance_status_cpu_user`
63+
* `fortigate_system_performance_status_mem_free`
64+
* `fortigate_system_performance_status_mem_freeable`
65+
* `fortigate_system_performance_status_mem_total`
66+
* `fortigate_system_performance_status_mem_used`
5267
* _System/HAChecksums_
5368
* `fortigate_ha_member_has_role`
5469
* _License/Status_
@@ -416,6 +431,7 @@ To improve security, limit permissions to required ones only (least privilege pr
416431
|System/HAStatistics | sysgrp.cfg |api/v2/monitor/system/ha-statistics<br>api/v2/cmdb/system/ha |
417432
|System/Interface | netgrp.cfg |api/v2/monitor/system/interface/select |
418433
|System/LinkMonitor | sysgrp.cfg |api/v2/monitor/system/link-monitor |
434+
|System/Performance/Status | sysgrp.cfg |api/v2/monitor/system/performance/status |
419435
|System/Resource/Usage | sysgrp.cfg |api/v2/monitor/system/resource/usage |
420436
|System/SensorInfo | sysgrp.cfg |api/v2/monitor/system/sensor-info |
421437
|System/Status | *any* |api/v2/monitor/system/status |

pkg/probe/probe.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ func (p *ProbeCollector) Probe(ctx context.Context, target map[string]string, hc
145145
{"System/HAStatistics", probeSystemHAStatistics},
146146
{"System/Interface", probeSystemInterface},
147147
{"System/LinkMonitor", probeSystemLinkMonitor},
148+
{"System/Perfomance/Status", probeSystemPerformanceStatus},
148149
{"System/Resource/Usage", probeSystemResourceUsage},
149150
{"System/SDNConnector", probeSystemSDNConnector},
150151
{"System/SensorInfo", probeSystemSensorInfo},
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
// Copyright 2025 The Prometheus Authors
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
package probe
15+
16+
import (
17+
"log"
18+
"strconv"
19+
20+
"github.com/prometheus-community/fortigate_exporter/pkg/http"
21+
"github.com/prometheus/client_golang/prometheus"
22+
)
23+
24+
func probeSystemPerformanceStatus(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {
25+
var (
26+
cpuCoresUser = prometheus.NewDesc(
27+
"fortigate_system_performance_status_cpu_cores_user",
28+
"Percentage of CPU utilization that occurred at the user level.",
29+
[]string{"label"}, nil,
30+
)
31+
cpuCoresSystem = prometheus.NewDesc(
32+
"fortigate_system_performance_status_cpu_cores_system",
33+
"Percentage of CPU utilization that occurred while executing at the system level.",
34+
[]string{"label"}, nil,
35+
)
36+
cpuCoresNice = prometheus.NewDesc(
37+
"fortigate_system_performance_status_cpu_cores_nice",
38+
"Percentage of CPU utilization that occurred while executing at the user level with nice priority.",
39+
[]string{"label"}, nil,
40+
)
41+
cpuCoresIdle = prometheus.NewDesc(
42+
"fortigate_system_performance_status_cpu_cores_idle",
43+
"Percentage of time that the CPU was idle and the system did not have an outstanding disk I/O request.",
44+
[]string{"label"}, nil,
45+
)
46+
cpuCoresIowait = prometheus.NewDesc(
47+
"fortigate_system_performance_status_cpu_cores_iowait",
48+
"Percentage of time that the CPU was idle during which the system had an outstanding disk I/O request.",
49+
[]string{"label"}, nil,
50+
)
51+
cpuUser = prometheus.NewDesc(
52+
"fortigate_system_performance_status_cpu_user",
53+
"Percentage of CPU utilization that occurred at the user level.",
54+
[]string{"label"}, nil,
55+
)
56+
cpuSystem = prometheus.NewDesc(
57+
"fortigate_system_performance_status_cpu_system",
58+
"Percentage of CPU utilization that occurred while executing at the system level.",
59+
[]string{"label"}, nil,
60+
)
61+
cpuNice = prometheus.NewDesc(
62+
"fortigate_system_performance_status_cpu_nice",
63+
"Percentage of CPU utilization that occurred while executing at the user level with nice priority.",
64+
[]string{"label"}, nil,
65+
)
66+
cpuIdle = prometheus.NewDesc(
67+
"fortigate_system_performance_status_cpu_idle",
68+
"Percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request.",
69+
[]string{"label"}, nil,
70+
)
71+
cpuIowait = prometheus.NewDesc(
72+
"fortigate_system_performance_status_cpu_iowait",
73+
"Percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request.",
74+
[]string{"label"}, nil,
75+
)
76+
memTotal = prometheus.NewDesc(
77+
"fortigate_system_performance_status_mem_total",
78+
"All the installed memory in RAM, in bytes.",
79+
[]string{"label"}, nil,
80+
)
81+
memUsed = prometheus.NewDesc(
82+
"fortigate_system_performance_status_mem_used",
83+
"Memory are being used, in bytes.",
84+
[]string{"label"}, nil,
85+
)
86+
memFree = prometheus.NewDesc(
87+
"fortigate_system_performance_status_mem_free",
88+
"All the memory in RAM that is not being used for anything (even caches), in bytes.",
89+
[]string{"label"}, nil,
90+
)
91+
memFreeable = prometheus.NewDesc(
92+
"fortigate_system_performance_status_mem_freeable",
93+
"Freeable buffers/caches memory, in bytes.",
94+
[]string{"label"}, nil,
95+
)
96+
)
97+
98+
type SystemPerformanceStatusCores struct {
99+
User int `json:"user"`
100+
System int `json:"system"`
101+
Nice int `json:"nice"`
102+
Idle int `json:"idle"`
103+
Iowait int `json:"iowait"`
104+
}
105+
106+
type SystemPerformanceStatusCpu struct {
107+
Cores []SystemPerformanceStatusCores `json:"cores"`
108+
User int `json:"user"`
109+
System int `json:"system"`
110+
Nice int `json:"nice"`
111+
Idle int `json:"idle"`
112+
Iowait int `json:"iowait"`
113+
}
114+
115+
type SystemPerformanceStatusMem struct {
116+
Total int `json:"total"`
117+
Used int `json:"used"`
118+
Free int `json:"free"`
119+
Freeable int `json:"freeable"`
120+
}
121+
122+
type SystemPerformanceStatus struct {
123+
Cpu SystemPerformanceStatusCpu `json:"cpu"`
124+
Mem SystemPerformanceStatusMem `json:"mem"`
125+
}
126+
127+
type SystemPerformanceStatusResult struct {
128+
Results []SystemPerformanceStatus `json:"results"`
129+
}
130+
131+
var res SystemPerformanceStatusResult
132+
if err := c.Get("api/v2/monitor/system/performance/status", "", &res); err != nil {
133+
log.Printf("Error: %v", err)
134+
return nil, false
135+
}
136+
m := []prometheus.Metric{}
137+
var cpu_num, mem_num, core_num string
138+
for n, r := range res.Results {
139+
cpu_num = "cpu_" + strconv.Itoa(n)
140+
mem_num = "mem_" + strconv.Itoa(n)
141+
for i, core := range r.Cpu.Cores {
142+
core_num = "core_" + strconv.Itoa(i)
143+
m = append(m, prometheus.MustNewConstMetric(cpuCoresUser, prometheus.GaugeValue, float64(core.User), cpu_num + "_" + core_num))
144+
m = append(m, prometheus.MustNewConstMetric(cpuCoresSystem, prometheus.GaugeValue, float64(core.System), cpu_num + "_" + core_num))
145+
m = append(m, prometheus.MustNewConstMetric(cpuCoresNice, prometheus.GaugeValue, float64(core.Nice), cpu_num + "_" + core_num))
146+
m = append(m, prometheus.MustNewConstMetric(cpuCoresIdle, prometheus.GaugeValue, float64(core.Idle), cpu_num + "_" + core_num))
147+
m = append(m, prometheus.MustNewConstMetric(cpuCoresIowait, prometheus.GaugeValue, float64(core.Iowait), cpu_num + "_" + core_num))
148+
}
149+
m = append(m, prometheus.MustNewConstMetric(cpuUser,prometheus.GaugeValue, float64(r.Cpu.User), cpu_num))
150+
m = append(m, prometheus.MustNewConstMetric(cpuSystem,prometheus.GaugeValue, float64(r.Cpu.System), cpu_num))
151+
m = append(m, prometheus.MustNewConstMetric(cpuNice,prometheus.GaugeValue, float64(r.Cpu.Nice), cpu_num))
152+
m = append(m, prometheus.MustNewConstMetric(cpuIdle,prometheus.GaugeValue, float64(r.Cpu.Idle), cpu_num))
153+
m = append(m, prometheus.MustNewConstMetric(cpuIowait,prometheus.GaugeValue, float64(r.Cpu.Iowait), cpu_num))
154+
m = append(m, prometheus.MustNewConstMetric(memTotal,prometheus.GaugeValue, float64(r.Mem.Total), mem_num))
155+
m = append(m, prometheus.MustNewConstMetric(memUsed,prometheus.GaugeValue, float64(r.Mem.Used), mem_num))
156+
m = append(m, prometheus.MustNewConstMetric(memFree,prometheus.GaugeValue, float64(r.Mem.Free), mem_num))
157+
m = append(m, prometheus.MustNewConstMetric(memFreeable,prometheus.GaugeValue, float64(r.Mem.Freeable), mem_num))
158+
}
159+
160+
return m, true
161+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
// Copyright 2025 The Prometheus Authors
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
package probe
15+
16+
import (
17+
"strings"
18+
"testing"
19+
20+
"github.com/prometheus/client_golang/prometheus"
21+
"github.com/prometheus/client_golang/prometheus/testutil"
22+
)
23+
24+
func TestSystemPerformanceStatus(t *testing.T) {
25+
c := newFakeClient()
26+
c.prepare("api/v2/monitor/system/performance/status", "testdata/system-performance-status.jsonnet")
27+
r := prometheus.NewPedanticRegistry()
28+
if !testProbe(probeSystemPerformanceStatus, c, r) {
29+
t.Errorf("probeSystemPerformanceStatus() returned non-success")
30+
}
31+
32+
em := `
33+
# 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.
34+
# TYPE fortigate_system_performance_status_cpu_cores_idle gauge
35+
fortigate_system_performance_status_cpu_cores_idle{label="cpu_0_core_0"} 0
36+
fortigate_system_performance_status_cpu_cores_idle{label="cpu_0_core_1"} 0
37+
fortigate_system_performance_status_cpu_cores_idle{label="cpu_0_core_2"} 0
38+
fortigate_system_performance_status_cpu_cores_idle{label="cpu_1_core_0"} 0
39+
# 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.
40+
# TYPE fortigate_system_performance_status_cpu_cores_iowait gauge
41+
fortigate_system_performance_status_cpu_cores_iowait{label="cpu_0_core_0"} 0
42+
fortigate_system_performance_status_cpu_cores_iowait{label="cpu_0_core_1"} 0
43+
fortigate_system_performance_status_cpu_cores_iowait{label="cpu_0_core_2"} 0
44+
fortigate_system_performance_status_cpu_cores_iowait{label="cpu_1_core_0"} 0
45+
# HELP fortigate_system_performance_status_cpu_cores_nice Percentage of CPU utilization that occurred while executing at the user level with nice priority.
46+
# TYPE fortigate_system_performance_status_cpu_cores_nice gauge
47+
fortigate_system_performance_status_cpu_cores_nice{label="cpu_0_core_0"} 0
48+
fortigate_system_performance_status_cpu_cores_nice{label="cpu_0_core_1"} 0
49+
fortigate_system_performance_status_cpu_cores_nice{label="cpu_0_core_2"} 0
50+
fortigate_system_performance_status_cpu_cores_nice{label="cpu_1_core_0"} 0
51+
# HELP fortigate_system_performance_status_cpu_cores_system Percentage of CPU utilization that occurred while executing at the system level.
52+
# TYPE fortigate_system_performance_status_cpu_cores_system gauge
53+
fortigate_system_performance_status_cpu_cores_system{label="cpu_0_core_0"} 13
54+
fortigate_system_performance_status_cpu_cores_system{label="cpu_0_core_1"} 14
55+
fortigate_system_performance_status_cpu_cores_system{label="cpu_0_core_2"} 0
56+
fortigate_system_performance_status_cpu_cores_system{label="cpu_1_core_0"} 0
57+
# HELP fortigate_system_performance_status_cpu_cores_user Percentage of CPU utilization that occurred at the user level.
58+
# TYPE fortigate_system_performance_status_cpu_cores_user gauge
59+
fortigate_system_performance_status_cpu_cores_user{label="cpu_0_core_0"} 0
60+
fortigate_system_performance_status_cpu_cores_user{label="cpu_0_core_1"} 1
61+
fortigate_system_performance_status_cpu_cores_user{label="cpu_0_core_2"} 2
62+
fortigate_system_performance_status_cpu_cores_user{label="cpu_1_core_0"} 0
63+
# 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.
64+
# TYPE fortigate_system_performance_status_cpu_idle gauge
65+
fortigate_system_performance_status_cpu_idle{label="cpu_0"} 0
66+
fortigate_system_performance_status_cpu_idle{label="cpu_1"} 0
67+
# 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.
68+
# TYPE fortigate_system_performance_status_cpu_iowait gauge
69+
fortigate_system_performance_status_cpu_iowait{label="cpu_0"} 0
70+
fortigate_system_performance_status_cpu_iowait{label="cpu_1"} 0
71+
# HELP fortigate_system_performance_status_cpu_nice Percentage of CPU utilization that occurred while executing at the user level with nice priority.
72+
# TYPE fortigate_system_performance_status_cpu_nice gauge
73+
fortigate_system_performance_status_cpu_nice{label="cpu_0"} 0
74+
fortigate_system_performance_status_cpu_nice{label="cpu_1"} 0
75+
# HELP fortigate_system_performance_status_cpu_system Percentage of CPU utilization that occurred while executing at the system level.
76+
# TYPE fortigate_system_performance_status_cpu_system gauge
77+
fortigate_system_performance_status_cpu_system{label="cpu_0"} 0
78+
fortigate_system_performance_status_cpu_system{label="cpu_1"} 0
79+
# HELP fortigate_system_performance_status_cpu_user Percentage of CPU utilization that occurred at the user level.
80+
# TYPE fortigate_system_performance_status_cpu_user gauge
81+
fortigate_system_performance_status_cpu_user{label="cpu_0"} 200
82+
fortigate_system_performance_status_cpu_user{label="cpu_1"} 0
83+
# HELP fortigate_system_performance_status_mem_free All the memory in RAM that is not being used for anything (even caches), in bytes.
84+
# TYPE fortigate_system_performance_status_mem_free gauge
85+
fortigate_system_performance_status_mem_free{label="mem_0"} 0
86+
fortigate_system_performance_status_mem_free{label="mem_1"} 0
87+
# HELP fortigate_system_performance_status_mem_freeable Freeable buffers/caches memory, in bytes.
88+
# TYPE fortigate_system_performance_status_mem_freeable gauge
89+
fortigate_system_performance_status_mem_freeable{label="mem_0"} 0
90+
fortigate_system_performance_status_mem_freeable{label="mem_1"} 0
91+
# HELP fortigate_system_performance_status_mem_total All the installed memory in RAM, in bytes.
92+
# TYPE fortigate_system_performance_status_mem_total gauge
93+
fortigate_system_performance_status_mem_total{label="mem_0"} 0
94+
fortigate_system_performance_status_mem_total{label="mem_1"} 0
95+
# HELP fortigate_system_performance_status_mem_used Memory are being used, in bytes.
96+
# TYPE fortigate_system_performance_status_mem_used gauge
97+
fortigate_system_performance_status_mem_used{label="mem_0"} 0
98+
fortigate_system_performance_status_mem_used{label="mem_1"} 0
99+
`
100+
101+
if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil {
102+
t.Fatalf("metric compare: err %v", err)
103+
}
104+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# api/v2/monitor/system/performance/status
2+
{
3+
"http_method":"GET",
4+
"results": [
5+
{
6+
"cpu": {
7+
"cores": [
8+
{
9+
"user": 0,
10+
"system": 13,
11+
"nice": 0,
12+
"idle": 0,
13+
"iowait": 0
14+
},
15+
{
16+
"user": 1,
17+
"system": 14,
18+
"nice": 0,
19+
"idle": 0,
20+
"iowait": 0
21+
},
22+
{
23+
"user": 2,
24+
"system": 0,
25+
"nice": 0,
26+
"idle": 0,
27+
"iowait": 0
28+
}
29+
],
30+
"user": 200,
31+
"system": 0,
32+
"nice": 0,
33+
"idle": 0,
34+
"iowait": 0
35+
},
36+
"mem": {
37+
"total": 0,
38+
"used": 0,
39+
"free": 0,
40+
"freeable": 0
41+
}
42+
},
43+
{
44+
"cpu": {
45+
"cores": [
46+
{
47+
"user": 0,
48+
"system": 0,
49+
"nice": 0,
50+
"idle": 0,
51+
"iowait": 0
52+
}
53+
],
54+
"user": 0,
55+
"system": 0,
56+
"nice": 0,
57+
"idle": 0,
58+
"iowait": 0
59+
},
60+
"mem": {
61+
"total": 0,
62+
"used": 0,
63+
"free": 0,
64+
"freeable": 0
65+
}
66+
}
67+
],
68+
"vdom":"root",
69+
"path":"system",
70+
"name":"fortimanager",
71+
"action":"status",
72+
"status":"success",
73+
"serial":"FGT61FT000000000",
74+
"version":"v6.0.10",
75+
"build":365
76+
}

0 commit comments

Comments
 (0)