Skip to content

Commit 9be60e4

Browse files
authored
Feature/system performance status (#336)
* Performance status probe added * Added vdoms --------- Signed-off-by: Örnfeldt Philip (66140321) <[email protected]> Signed-off-by: Philip Örnfeldt <[email protected]>
1 parent fdb0d3a commit 9be60e4

File tree

5 files changed

+663
-0
lines changed

5 files changed

+663
-0
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,21 @@ Global:
5555
* `fortigate_cpu_usage_ratio`
5656
* `fortigate_memory_usage_ratio`
5757
* `fortigate_current_sessions`
58+
* _System/Performance/status/_
59+
* `fortigate_system_performance_status_cpu_cores_idle_ratio`
60+
* `fortigate_system_performance_status_cpu_cores_iowait_ratio`
61+
* `fortigate_system_performance_status_cpu_cores_nice_ratio`
62+
* `fortigate_system_performance_status_cpu_cores_system_ratio`
63+
* `fortigate_system_performance_status_cpu_cores_user_ratio`
64+
* `fortigate_system_performance_status_cpu_idle_ratio`
65+
* `fortigate_system_performance_status_cpu_iowait_ratio`
66+
* `fortigate_system_performance_status_cpu_nice_ratio`
67+
* `fortigate_system_performance_status_cpu_system_ratio`
68+
* `fortigate_system_performance_status_cpu_user_ratio`
69+
* `fortigate_system_performance_status_mem_free_bytes`
70+
* `fortigate_system_performance_status_mem_freeable_bytes`
71+
* `fortigate_system_performance_status_mem_bytes_total`
72+
* `fortigate_system_performance_status_mem_used_bytes`
5873
* _System/HAChecksums_
5974
* `fortigate_ha_member_has_role`
6075
* _System/Ntp/Status_
@@ -449,6 +464,7 @@ To improve security, limit permissions to required ones only (least privilege pr
449464
|System/Interface | netgrp.cfg |api/v2/monitor/system/interface/select |
450465
|System/Interface/Transceivers| *any* |api/v2/monitor/system/interface/transceivers |
451466
|System/LinkMonitor | sysgrp.cfg |api/v2/monitor/system/link-monitor |
467+
|System/Performance/Status | sysgrp.cfg |api/v2/monitor/system/performance/status |
452468
|System/Ntp/Status | netgrp.cfg |api/v2/monitor/system/ntp/status |
453469
|System/Resource/Usage | sysgrp.cfg |api/v2/monitor/system/resource/usage |
454470
|System/Resource/Usage/VDOM | sysgrp.cfg |api/v2/monitor/system/resource/usage |

pkg/probe/probe.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ func (p *Collector) Probe(ctx context.Context, target map[string]string, hc *htt
150150
{"System/Interface", probeSystemInterface},
151151
{"System/Interface/Transceivers", probeSystemInterfaceTransceivers},
152152
{"System/LinkMonitor", probeSystemLinkMonitor},
153+
{"System/Performance/Status", probeSystemPerformanceStatus},
153154
{"System/Ntp/Status", probeSystemNtpStatus},
154155
{"System/Resource/Usage", probeSystemResourceUsage},
155156
{"System/Resource/Usage/VDOM", probeSystemResourceUsagePerVdom},
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
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/client_golang/prometheus"
21+
22+
"github.com/prometheus-community/fortigate_exporter/pkg/http"
23+
)
24+
25+
func probeSystemPerformanceStatus(c http.FortiHTTP, _ *TargetMetadata) ([]prometheus.Metric, bool) {
26+
var (
27+
cpuCoresUser = prometheus.NewDesc(
28+
"fortigate_system_performance_status_cpu_cores_user_ratio",
29+
"Percentage of CPU utilization that occurred at the user level.",
30+
[]string{"label", "vdom"}, nil,
31+
)
32+
cpuCoresSystem = prometheus.NewDesc(
33+
"fortigate_system_performance_status_cpu_cores_system_ratio",
34+
"Percentage of CPU utilization that occurred while executing at the system level.",
35+
[]string{"label", "vdom"}, nil,
36+
)
37+
cpuCoresNice = prometheus.NewDesc(
38+
"fortigate_system_performance_status_cpu_cores_nice_ratio",
39+
"Percentage of CPU utilization that occurred while executing at the user level with nice priority.",
40+
[]string{"label", "vdom"}, nil,
41+
)
42+
cpuCoresIdle = prometheus.NewDesc(
43+
"fortigate_system_performance_status_cpu_cores_idle_ratio",
44+
"Percentage of time that the CPU was idle and the system did not have an outstanding disk I/O request.",
45+
[]string{"label", "vdom"}, nil,
46+
)
47+
cpuCoresIowait = prometheus.NewDesc(
48+
"fortigate_system_performance_status_cpu_cores_iowait_ratio",
49+
"Percentage of time that the CPU was idle during which the system had an outstanding disk I/O request.",
50+
[]string{"label", "vdom"}, nil,
51+
)
52+
cpuUser = prometheus.NewDesc(
53+
"fortigate_system_performance_status_cpu_user_ratio",
54+
"Percentage of CPU utilization that occurred at the user level.",
55+
[]string{"vdom"}, nil,
56+
)
57+
cpuSystem = prometheus.NewDesc(
58+
"fortigate_system_performance_status_cpu_system_ratio",
59+
"Percentage of CPU utilization that occurred while executing at the system level.",
60+
[]string{"vdom"}, nil,
61+
)
62+
cpuNice = prometheus.NewDesc(
63+
"fortigate_system_performance_status_cpu_nice_ratio",
64+
"Percentage of CPU utilization that occurred while executing at the user level with nice priority.",
65+
[]string{"vdom"}, nil,
66+
)
67+
cpuIdle = prometheus.NewDesc(
68+
"fortigate_system_performance_status_cpu_idle_ratio",
69+
"Percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request.",
70+
[]string{"vdom"}, nil,
71+
)
72+
cpuIowait = prometheus.NewDesc(
73+
"fortigate_system_performance_status_cpu_iowait_ratio",
74+
"Percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request.",
75+
[]string{"vdom"}, nil,
76+
)
77+
memTotal = prometheus.NewDesc(
78+
"fortigate_system_performance_status_mem_bytes_total",
79+
"All the installed memory in RAM, in bytes.",
80+
[]string{"vdom"}, nil,
81+
)
82+
memUsed = prometheus.NewDesc(
83+
"fortigate_system_performance_status_mem_used_bytes",
84+
"Memory are being used, in bytes.",
85+
[]string{"vdom"}, nil,
86+
)
87+
memFree = prometheus.NewDesc(
88+
"fortigate_system_performance_status_mem_free_bytes",
89+
"All the memory in RAM that is not being used for anything (even caches), in bytes.",
90+
[]string{"vdom"}, nil,
91+
)
92+
memFreeable = prometheus.NewDesc(
93+
"fortigate_system_performance_status_mem_freeable_bytes",
94+
"Freeable buffers/caches memory, in bytes.",
95+
[]string{"vdom"}, nil,
96+
)
97+
)
98+
99+
type SystemPerformanceStatusCores struct {
100+
User int `json:"user"`
101+
System int `json:"system"`
102+
Nice int `json:"nice"`
103+
Idle int `json:"idle"`
104+
Iowait int `json:"iowait"`
105+
}
106+
107+
type SystemPerformanceStatusCPU struct {
108+
Cores []SystemPerformanceStatusCores `json:"cores"`
109+
User int `json:"user"`
110+
System int `json:"system"`
111+
Nice int `json:"nice"`
112+
Idle int `json:"idle"`
113+
Iowait int `json:"iowait"`
114+
}
115+
116+
type SystemPerformanceStatusMem struct {
117+
Total int `json:"total"`
118+
Used int `json:"used"`
119+
Free int `json:"free"`
120+
Freeable int `json:"freeable"`
121+
}
122+
123+
type SystemPerformanceStatus struct {
124+
CPU SystemPerformanceStatusCPU `json:"cpu"`
125+
Mem SystemPerformanceStatusMem `json:"mem"`
126+
}
127+
128+
type SystemPerformanceStatusResult struct {
129+
Results SystemPerformanceStatus `json:"results"`
130+
VDOM string `json:"vdom"`
131+
}
132+
133+
var res SystemPerformanceStatusResult
134+
if err := c.Get("api/v2/monitor/system/performance/status", "", &res); err != nil {
135+
log.Printf("Error: %v", err)
136+
return nil, false
137+
}
138+
m := []prometheus.Metric{}
139+
var coreNum string
140+
for i, core := range res.Results.CPU.Cores {
141+
coreNum = "core_" + strconv.Itoa(i)
142+
m = append(m, prometheus.MustNewConstMetric(cpuCoresUser, prometheus.GaugeValue, float64(core.User)*0.01, coreNum, res.VDOM))
143+
m = append(m, prometheus.MustNewConstMetric(cpuCoresSystem, prometheus.GaugeValue, float64(core.System)*0.01, coreNum, res.VDOM))
144+
m = append(m, prometheus.MustNewConstMetric(cpuCoresNice, prometheus.GaugeValue, float64(core.Nice)*0.01, coreNum, res.VDOM))
145+
m = append(m, prometheus.MustNewConstMetric(cpuCoresIdle, prometheus.GaugeValue, float64(core.Idle)*0.01, coreNum, res.VDOM))
146+
m = append(m, prometheus.MustNewConstMetric(cpuCoresIowait, prometheus.GaugeValue, float64(core.Iowait)*0.01, coreNum, res.VDOM))
147+
}
148+
m = append(m, prometheus.MustNewConstMetric(cpuUser, prometheus.GaugeValue, float64(res.Results.CPU.User)*0.01, res.VDOM))
149+
m = append(m, prometheus.MustNewConstMetric(cpuSystem, prometheus.GaugeValue, float64(res.Results.CPU.System)*0.01, res.VDOM))
150+
m = append(m, prometheus.MustNewConstMetric(cpuNice, prometheus.GaugeValue, float64(res.Results.CPU.Nice)*0.01, res.VDOM))
151+
m = append(m, prometheus.MustNewConstMetric(cpuIdle, prometheus.GaugeValue, float64(res.Results.CPU.Idle)*0.01, res.VDOM))
152+
m = append(m, prometheus.MustNewConstMetric(cpuIowait, prometheus.GaugeValue, float64(res.Results.CPU.Iowait)*0.01, res.VDOM))
153+
m = append(m, prometheus.MustNewConstMetric(memTotal, prometheus.GaugeValue, float64(res.Results.Mem.Total), res.VDOM))
154+
m = append(m, prometheus.MustNewConstMetric(memUsed, prometheus.GaugeValue, float64(res.Results.Mem.Used), res.VDOM))
155+
m = append(m, prometheus.MustNewConstMetric(memFree, prometheus.GaugeValue, float64(res.Results.Mem.Free), res.VDOM))
156+
m = append(m, prometheus.MustNewConstMetric(memFreeable, prometheus.GaugeValue, float64(res.Results.Mem.Freeable), res.VDOM))
157+
return m, true
158+
}

0 commit comments

Comments
 (0)