Skip to content

Commit 857c035

Browse files
committed
Added vdoms
Signed-off-by: Örnfeldt Philip (66140321) <philip.ornfeldt@forsakringskassan.se>
1 parent 6f7f897 commit 857c035

File tree

3 files changed

+78
-76
lines changed

3 files changed

+78
-76
lines changed

pkg/probe/system_performance_status.go

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,72 +26,72 @@ func probeSystemPerformanceStatus(c http.FortiHTTP, meta *TargetMetadata) ([]pro
2626
cpuCoresUser = prometheus.NewDesc(
2727
"fortigate_system_performance_status_cpu_cores_user",
2828
"Percentage of CPU utilization that occurred at the user level.",
29-
[]string{"label"}, nil,
29+
[]string{"label", "vdom"}, nil,
3030
)
3131
cpuCoresSystem = prometheus.NewDesc(
3232
"fortigate_system_performance_status_cpu_cores_system",
3333
"Percentage of CPU utilization that occurred while executing at the system level.",
34-
[]string{"label"}, nil,
34+
[]string{"label", "vdom"}, nil,
3535
)
3636
cpuCoresNice = prometheus.NewDesc(
3737
"fortigate_system_performance_status_cpu_cores_nice",
3838
"Percentage of CPU utilization that occurred while executing at the user level with nice priority.",
39-
[]string{"label"}, nil,
39+
[]string{"label", "vdom"}, nil,
4040
)
4141
cpuCoresIdle = prometheus.NewDesc(
4242
"fortigate_system_performance_status_cpu_cores_idle",
4343
"Percentage of time that the CPU was idle and the system did not have an outstanding disk I/O request.",
44-
[]string{"label"}, nil,
44+
[]string{"label", "vdom"}, nil,
4545
)
4646
cpuCoresIowait = prometheus.NewDesc(
4747
"fortigate_system_performance_status_cpu_cores_iowait",
4848
"Percentage of time that the CPU was idle during which the system had an outstanding disk I/O request.",
49-
[]string{"label"}, nil,
49+
[]string{"label", "vdom"}, nil,
5050
)
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"}, nil,
54+
[]string{"label", "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"}, nil,
59+
[]string{"label", "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"}, nil,
64+
[]string{"label", "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"}, nil,
69+
[]string{"label", "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"}, nil,
74+
[]string{"label", "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"}, nil,
79+
[]string{"label", "vdom"}, nil,
8080
)
8181
memUsed = prometheus.NewDesc(
8282
"fortigate_system_performance_status_mem_used",
8383
"Memory are being used, in bytes.",
84-
[]string{"label"}, nil,
84+
[]string{"label", "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"}, nil,
89+
[]string{"label", "vdom"}, nil,
9090
)
9191
memFreeable = prometheus.NewDesc(
9292
"fortigate_system_performance_status_mem_freeable",
9393
"Freeable buffers/caches memory, in bytes.",
94-
[]string{"label"}, nil,
94+
[]string{"label", "vdom"}, nil,
9595
)
9696
)
9797

@@ -126,36 +126,38 @@ func probeSystemPerformanceStatus(c http.FortiHTTP, meta *TargetMetadata) ([]pro
126126

127127
type SystemPerformanceStatusResult struct {
128128
Results []SystemPerformanceStatus `json:"results"`
129+
VDOM string `json:"vdom"`
129130
}
130131

131-
var res SystemPerformanceStatusResult
132-
if err := c.Get("api/v2/monitor/system/performance/status", "", &res); err != nil {
132+
var result []SystemPerformanceStatusResult
133+
if err := c.Get("api/v2/monitor/system/performance/status", "vdom=*", &result); err != nil {
133134
log.Printf("Error: %v", err)
134135
return nil, false
135136
}
136137
m := []prometheus.Metric{}
137138
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))
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))
148160
}
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))
158161
}
159-
160162
return m, true
161163
}

pkg/probe/system_performance_status_test.go

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -32,70 +32,70 @@ 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"} 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
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
3939
# 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.
4040
# 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
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
4545
# HELP fortigate_system_performance_status_cpu_cores_nice Percentage of CPU utilization that occurred while executing at the user level with nice priority.
4646
# 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
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
5151
# HELP fortigate_system_performance_status_cpu_cores_system Percentage of CPU utilization that occurred while executing at the system level.
5252
# 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
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
5757
# HELP fortigate_system_performance_status_cpu_cores_user Percentage of CPU utilization that occurred at the user level.
5858
# 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
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
6363
# 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.
6464
# 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
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
6767
# 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.
6868
# 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
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
7171
# HELP fortigate_system_performance_status_cpu_nice Percentage of CPU utilization that occurred while executing at the user level with nice priority.
7272
# 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
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
7575
# HELP fortigate_system_performance_status_cpu_system Percentage of CPU utilization that occurred while executing at the system level.
7676
# 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
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
7979
# HELP fortigate_system_performance_status_cpu_user Percentage of CPU utilization that occurred at the user level.
8080
# 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
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
8383
# HELP fortigate_system_performance_status_mem_free All the memory in RAM that is not being used for anything (even caches), in bytes.
8484
# 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
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
8787
# HELP fortigate_system_performance_status_mem_freeable Freeable buffers/caches memory, in bytes.
8888
# 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
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
9191
# HELP fortigate_system_performance_status_mem_total All the installed memory in RAM, in bytes.
9292
# 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
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
9595
# HELP fortigate_system_performance_status_mem_used Memory are being used, in bytes.
9696
# 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
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
9999
`
100100

101101
if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil {

pkg/probe/testdata/system-performance-status.jsonnet

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# api/v2/monitor/system/performance/status
2-
{
2+
[{
33
"http_method":"GET",
44
"results": [
55
{
@@ -73,4 +73,4 @@
7373
"serial":"FGT61FT000000000",
7474
"version":"v6.0.10",
7575
"build":365
76-
}
76+
}]

0 commit comments

Comments
 (0)