Skip to content

Commit b6fc942

Browse files
committed
Not supposed to run for all vdoms. Result not a list
1 parent 857c035 commit b6fc942

File tree

3 files changed

+92
-138
lines changed

3 files changed

+92
-138
lines changed

pkg/probe/system_performance_status.go

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -51,47 +51,47 @@ func probeSystemPerformanceStatus(c http.FortiHTTP, meta *TargetMetadata) ([]pro
5151
cpuUser = prometheus.NewDesc(
5252
"fortigate_system_performance_status_cpu_user",
5353
"Percentage of CPU utilization that occurred at the user level.",
54-
[]string{"label", "vdom"}, nil,
54+
[]string{"vdom"}, nil,
5555
)
5656
cpuSystem = prometheus.NewDesc(
5757
"fortigate_system_performance_status_cpu_system",
5858
"Percentage of CPU utilization that occurred while executing at the system level.",
59-
[]string{"label", "vdom"}, nil,
59+
[]string{"vdom"}, nil,
6060
)
6161
cpuNice = prometheus.NewDesc(
6262
"fortigate_system_performance_status_cpu_nice",
6363
"Percentage of CPU utilization that occurred while executing at the user level with nice priority.",
64-
[]string{"label", "vdom"}, nil,
64+
[]string{"vdom"}, nil,
6565
)
6666
cpuIdle = prometheus.NewDesc(
6767
"fortigate_system_performance_status_cpu_idle",
6868
"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", "vdom"}, nil,
69+
[]string{"vdom"}, nil,
7070
)
7171
cpuIowait = prometheus.NewDesc(
7272
"fortigate_system_performance_status_cpu_iowait",
7373
"Percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request.",
74-
[]string{"label", "vdom"}, nil,
74+
[]string{"vdom"}, nil,
7575
)
7676
memTotal = prometheus.NewDesc(
7777
"fortigate_system_performance_status_mem_total",
7878
"All the installed memory in RAM, in bytes.",
79-
[]string{"label", "vdom"}, nil,
79+
[]string{"vdom"}, nil,
8080
)
8181
memUsed = prometheus.NewDesc(
8282
"fortigate_system_performance_status_mem_used",
8383
"Memory are being used, in bytes.",
84-
[]string{"label", "vdom"}, nil,
84+
[]string{"vdom"}, nil,
8585
)
8686
memFree = prometheus.NewDesc(
8787
"fortigate_system_performance_status_mem_free",
8888
"All the memory in RAM that is not being used for anything (even caches), in bytes.",
89-
[]string{"label", "vdom"}, nil,
89+
[]string{"vdom"}, nil,
9090
)
9191
memFreeable = prometheus.NewDesc(
9292
"fortigate_system_performance_status_mem_freeable",
9393
"Freeable buffers/caches memory, in bytes.",
94-
[]string{"label", "vdom"}, nil,
94+
[]string{"vdom"}, nil,
9595
)
9696
)
9797

@@ -125,39 +125,33 @@ func probeSystemPerformanceStatus(c http.FortiHTTP, meta *TargetMetadata) ([]pro
125125
}
126126

127127
type SystemPerformanceStatusResult struct {
128-
Results []SystemPerformanceStatus `json:"results"`
129-
VDOM string `json:"vdom"`
128+
Results SystemPerformanceStatus `json:"results"`
129+
VDOM string `json:"vdom"`
130130
}
131131

132-
var result []SystemPerformanceStatusResult
133-
if err := c.Get("api/v2/monitor/system/performance/status", "vdom=*", &result); err != nil {
132+
var res SystemPerformanceStatusResult
133+
if err := c.Get("api/v2/monitor/system/performance/status", "", &res); err != nil {
134134
log.Printf("Error: %v", err)
135135
return nil, false
136136
}
137137
m := []prometheus.Metric{}
138-
var cpu_num, mem_num, core_num string
139-
for _, res := range result{
140-
for n, r := range res.Results {
141-
cpu_num = "cpu_" + strconv.Itoa(n)
142-
mem_num = "mem_" + strconv.Itoa(n)
143-
for i, core := range r.Cpu.Cores {
144-
core_num = "core_" + strconv.Itoa(i)
145-
m = append(m, prometheus.MustNewConstMetric(cpuCoresUser, prometheus.GaugeValue, float64(core.User), cpu_num + "_" + core_num, res.VDOM))
146-
m = append(m, prometheus.MustNewConstMetric(cpuCoresSystem, prometheus.GaugeValue, float64(core.System), cpu_num + "_" + core_num, res.VDOM))
147-
m = append(m, prometheus.MustNewConstMetric(cpuCoresNice, prometheus.GaugeValue, float64(core.Nice), cpu_num + "_" + core_num, res.VDOM))
148-
m = append(m, prometheus.MustNewConstMetric(cpuCoresIdle, prometheus.GaugeValue, float64(core.Idle), cpu_num + "_" + core_num, res.VDOM))
149-
m = append(m, prometheus.MustNewConstMetric(cpuCoresIowait, prometheus.GaugeValue, float64(core.Iowait), cpu_num + "_" + core_num, res.VDOM))
150-
}
151-
m = append(m, prometheus.MustNewConstMetric(cpuUser,prometheus.GaugeValue, float64(r.Cpu.User), cpu_num, res.VDOM))
152-
m = append(m, prometheus.MustNewConstMetric(cpuSystem,prometheus.GaugeValue, float64(r.Cpu.System), cpu_num, res.VDOM))
153-
m = append(m, prometheus.MustNewConstMetric(cpuNice,prometheus.GaugeValue, float64(r.Cpu.Nice), cpu_num, res.VDOM))
154-
m = append(m, prometheus.MustNewConstMetric(cpuIdle,prometheus.GaugeValue, float64(r.Cpu.Idle), cpu_num, res.VDOM))
155-
m = append(m, prometheus.MustNewConstMetric(cpuIowait,prometheus.GaugeValue, float64(r.Cpu.Iowait), cpu_num, res.VDOM))
156-
m = append(m, prometheus.MustNewConstMetric(memTotal,prometheus.GaugeValue, float64(r.Mem.Total), mem_num, res.VDOM))
157-
m = append(m, prometheus.MustNewConstMetric(memUsed,prometheus.GaugeValue, float64(r.Mem.Used), mem_num, res.VDOM))
158-
m = append(m, prometheus.MustNewConstMetric(memFree,prometheus.GaugeValue, float64(r.Mem.Free), mem_num, res.VDOM))
159-
m = append(m, prometheus.MustNewConstMetric(memFreeable,prometheus.GaugeValue, float64(r.Mem.Freeable), mem_num, res.VDOM))
160-
}
138+
var core_num string
139+
for i, core := range res.Results.Cpu.Cores {
140+
core_num = "core_" + strconv.Itoa(i)
141+
m = append(m, prometheus.MustNewConstMetric(cpuCoresUser, prometheus.GaugeValue, float64(core.User), core_num, res.VDOM))
142+
m = append(m, prometheus.MustNewConstMetric(cpuCoresSystem, prometheus.GaugeValue, float64(core.System), core_num, res.VDOM))
143+
m = append(m, prometheus.MustNewConstMetric(cpuCoresNice, prometheus.GaugeValue, float64(core.Nice), core_num, res.VDOM))
144+
m = append(m, prometheus.MustNewConstMetric(cpuCoresIdle, prometheus.GaugeValue, float64(core.Idle), core_num, res.VDOM))
145+
m = append(m, prometheus.MustNewConstMetric(cpuCoresIowait, prometheus.GaugeValue, float64(core.Iowait), core_num, res.VDOM))
161146
}
147+
m = append(m, prometheus.MustNewConstMetric(cpuUser,prometheus.GaugeValue, float64(res.Results.Cpu.User), res.VDOM))
148+
m = append(m, prometheus.MustNewConstMetric(cpuSystem,prometheus.GaugeValue, float64(res.Results.Cpu.System), res.VDOM))
149+
m = append(m, prometheus.MustNewConstMetric(cpuNice,prometheus.GaugeValue, float64(res.Results.Cpu.Nice), res.VDOM))
150+
m = append(m, prometheus.MustNewConstMetric(cpuIdle,prometheus.GaugeValue, float64(res.Results.Cpu.Idle), res.VDOM))
151+
m = append(m, prometheus.MustNewConstMetric(cpuIowait,prometheus.GaugeValue, float64(res.Results.Cpu.Iowait), res.VDOM))
152+
m = append(m, prometheus.MustNewConstMetric(memTotal,prometheus.GaugeValue, float64(res.Results.Mem.Total), res.VDOM))
153+
m = append(m, prometheus.MustNewConstMetric(memUsed,prometheus.GaugeValue, float64(res.Results.Mem.Used), res.VDOM))
154+
m = append(m, prometheus.MustNewConstMetric(memFree,prometheus.GaugeValue, float64(res.Results.Mem.Free), res.VDOM))
155+
m = append(m, prometheus.MustNewConstMetric(memFreeable,prometheus.GaugeValue, float64(res.Results.Mem.Freeable), res.VDOM))
162156
return m, true
163157
}

pkg/probe/system_performance_status_test.go

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -32,70 +32,56 @@ func TestSystemPerformanceStatus(t *testing.T) {
3232
em := `
3333
# 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.
3434
# TYPE fortigate_system_performance_status_cpu_cores_idle gauge
35-
fortigate_system_performance_status_cpu_cores_idle{label="cpu_0_core_0",vdom="root"} 0
36-
fortigate_system_performance_status_cpu_cores_idle{label="cpu_0_core_1",vdom="root"} 0
37-
fortigate_system_performance_status_cpu_cores_idle{label="cpu_0_core_2",vdom="root"} 0
38-
fortigate_system_performance_status_cpu_cores_idle{label="cpu_1_core_0",vdom="root"} 0
35+
fortigate_system_performance_status_cpu_cores_idle{label="core_0",vdom="root"} 0
36+
fortigate_system_performance_status_cpu_cores_idle{label="core_1",vdom="root"} 0
37+
fortigate_system_performance_status_cpu_cores_idle{label="core_2",vdom="root"} 0
3938
# 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.
4039
# TYPE fortigate_system_performance_status_cpu_cores_iowait gauge
41-
fortigate_system_performance_status_cpu_cores_iowait{label="cpu_0_core_0",vdom="root"} 0
42-
fortigate_system_performance_status_cpu_cores_iowait{label="cpu_0_core_1",vdom="root"} 0
43-
fortigate_system_performance_status_cpu_cores_iowait{label="cpu_0_core_2",vdom="root"} 0
44-
fortigate_system_performance_status_cpu_cores_iowait{label="cpu_1_core_0",vdom="root"} 0
40+
fortigate_system_performance_status_cpu_cores_iowait{label="core_0",vdom="root"} 0
41+
fortigate_system_performance_status_cpu_cores_iowait{label="core_1",vdom="root"} 0
42+
fortigate_system_performance_status_cpu_cores_iowait{label="core_2",vdom="root"} 0
4543
# HELP fortigate_system_performance_status_cpu_cores_nice Percentage of CPU utilization that occurred while executing at the user level with nice priority.
4644
# TYPE fortigate_system_performance_status_cpu_cores_nice gauge
47-
fortigate_system_performance_status_cpu_cores_nice{label="cpu_0_core_0",vdom="root"} 0
48-
fortigate_system_performance_status_cpu_cores_nice{label="cpu_0_core_1",vdom="root"} 0
49-
fortigate_system_performance_status_cpu_cores_nice{label="cpu_0_core_2",vdom="root"} 0
50-
fortigate_system_performance_status_cpu_cores_nice{label="cpu_1_core_0",vdom="root"} 0
45+
fortigate_system_performance_status_cpu_cores_nice{label="core_0",vdom="root"} 0
46+
fortigate_system_performance_status_cpu_cores_nice{label="core_1",vdom="root"} 0
47+
fortigate_system_performance_status_cpu_cores_nice{label="core_2",vdom="root"} 0
5148
# HELP fortigate_system_performance_status_cpu_cores_system Percentage of CPU utilization that occurred while executing at the system level.
5249
# TYPE fortigate_system_performance_status_cpu_cores_system gauge
53-
fortigate_system_performance_status_cpu_cores_system{label="cpu_0_core_0",vdom="root"} 13
54-
fortigate_system_performance_status_cpu_cores_system{label="cpu_0_core_1",vdom="root"} 14
55-
fortigate_system_performance_status_cpu_cores_system{label="cpu_0_core_2",vdom="root"} 0
56-
fortigate_system_performance_status_cpu_cores_system{label="cpu_1_core_0",vdom="root"} 0
50+
fortigate_system_performance_status_cpu_cores_system{label="core_0",vdom="root"} 13
51+
fortigate_system_performance_status_cpu_cores_system{label="core_1",vdom="root"} 14
52+
fortigate_system_performance_status_cpu_cores_system{label="core_2",vdom="root"} 0
5753
# HELP fortigate_system_performance_status_cpu_cores_user Percentage of CPU utilization that occurred at the user level.
5854
# TYPE fortigate_system_performance_status_cpu_cores_user gauge
59-
fortigate_system_performance_status_cpu_cores_user{label="cpu_0_core_0",vdom="root"} 0
60-
fortigate_system_performance_status_cpu_cores_user{label="cpu_0_core_1",vdom="root"} 1
61-
fortigate_system_performance_status_cpu_cores_user{label="cpu_0_core_2",vdom="root"} 2
62-
fortigate_system_performance_status_cpu_cores_user{label="cpu_1_core_0",vdom="root"} 0
55+
fortigate_system_performance_status_cpu_cores_user{label="core_0",vdom="root"} 0
56+
fortigate_system_performance_status_cpu_cores_user{label="core_1",vdom="root"} 1
57+
fortigate_system_performance_status_cpu_cores_user{label="core_2",vdom="root"} 2
6358
# 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.
6459
# TYPE fortigate_system_performance_status_cpu_idle gauge
65-
fortigate_system_performance_status_cpu_idle{label="cpu_0",vdom="root"} 0
66-
fortigate_system_performance_status_cpu_idle{label="cpu_1",vdom="root"} 0
60+
fortigate_system_performance_status_cpu_idle{vdom="root"} 0
6761
# 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.
6862
# TYPE fortigate_system_performance_status_cpu_iowait gauge
69-
fortigate_system_performance_status_cpu_iowait{label="cpu_0",vdom="root"} 0
70-
fortigate_system_performance_status_cpu_iowait{label="cpu_1",vdom="root"} 0
63+
fortigate_system_performance_status_cpu_iowait{vdom="root"} 0
7164
# HELP fortigate_system_performance_status_cpu_nice Percentage of CPU utilization that occurred while executing at the user level with nice priority.
7265
# TYPE fortigate_system_performance_status_cpu_nice gauge
73-
fortigate_system_performance_status_cpu_nice{label="cpu_0",vdom="root"} 0
74-
fortigate_system_performance_status_cpu_nice{label="cpu_1",vdom="root"} 0
66+
fortigate_system_performance_status_cpu_nice{vdom="root"} 0
7567
# HELP fortigate_system_performance_status_cpu_system Percentage of CPU utilization that occurred while executing at the system level.
7668
# TYPE fortigate_system_performance_status_cpu_system gauge
77-
fortigate_system_performance_status_cpu_system{label="cpu_0",vdom="root"} 0
78-
fortigate_system_performance_status_cpu_system{label="cpu_1",vdom="root"} 0
69+
fortigate_system_performance_status_cpu_system{vdom="root"} 0
7970
# HELP fortigate_system_performance_status_cpu_user Percentage of CPU utilization that occurred at the user level.
8071
# TYPE fortigate_system_performance_status_cpu_user gauge
81-
fortigate_system_performance_status_cpu_user{label="cpu_0",vdom="root"} 200
82-
fortigate_system_performance_status_cpu_user{label="cpu_1",vdom="root"} 0
72+
fortigate_system_performance_status_cpu_user{vdom="root"} 200
8373
# HELP fortigate_system_performance_status_mem_free All the memory in RAM that is not being used for anything (even caches), in bytes.
8474
# TYPE fortigate_system_performance_status_mem_free gauge
85-
fortigate_system_performance_status_mem_free{label="mem_0",vdom="root"} 0
86-
fortigate_system_performance_status_mem_free{label="mem_1",vdom="root"} 0
75+
fortigate_system_performance_status_mem_free{vdom="root"} 0
8776
# HELP fortigate_system_performance_status_mem_freeable Freeable buffers/caches memory, in bytes.
8877
# TYPE fortigate_system_performance_status_mem_freeable gauge
89-
fortigate_system_performance_status_mem_freeable{label="mem_0",vdom="root"} 0
90-
fortigate_system_performance_status_mem_freeable{label="mem_1",vdom="root"} 0
78+
fortigate_system_performance_status_mem_freeable{vdom="root"} 0
9179
# HELP fortigate_system_performance_status_mem_total All the installed memory in RAM, in bytes.
9280
# TYPE fortigate_system_performance_status_mem_total gauge
93-
fortigate_system_performance_status_mem_total{label="mem_0",vdom="root"} 0
94-
fortigate_system_performance_status_mem_total{label="mem_1",vdom="root"} 0
81+
fortigate_system_performance_status_mem_total{vdom="root"} 0
9582
# HELP fortigate_system_performance_status_mem_used Memory are being used, in bytes.
9683
# TYPE fortigate_system_performance_status_mem_used gauge
97-
fortigate_system_performance_status_mem_used{label="mem_0",vdom="root"} 0
98-
fortigate_system_performance_status_mem_used{label="mem_1",vdom="root"} 0
84+
fortigate_system_performance_status_mem_used{vdom="root"} 0
9985
`
10086

10187
if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil {
Lines changed: 38 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,44 @@
11
# api/v2/monitor/system/performance/status
2-
[{
2+
{
33
"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-
}
4+
"results": {
5+
"cpu": {
6+
"cores": [
7+
{
8+
"user": 0,
9+
"system": 13,
10+
"nice": 0,
11+
"idle": 0,
12+
"iowait": 0
13+
},
14+
{
15+
"user": 1,
16+
"system": 14,
17+
"nice": 0,
18+
"idle": 0,
19+
"iowait": 0
20+
},
21+
{
22+
"user": 2,
23+
"system": 0,
24+
"nice": 0,
25+
"idle": 0,
26+
"iowait": 0
27+
}
28+
],
29+
"user": 200,
30+
"system": 0,
31+
"nice": 0,
32+
"idle": 0,
33+
"iowait": 0
4234
},
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-
}
35+
"mem": {
36+
"total": 0,
37+
"used": 0,
38+
"free": 0,
39+
"freeable": 0
6640
}
67-
],
41+
},
6842
"vdom":"root",
6943
"path":"system",
7044
"name":"fortimanager",
@@ -73,4 +47,4 @@
7347
"serial":"FGT61FT000000000",
7448
"version":"v6.0.10",
7549
"build":365
76-
}]
50+
}

0 commit comments

Comments
 (0)