Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_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_
Expand Down Expand Up @@ -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<br>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 |
Expand Down
1 change: 1 addition & 0 deletions pkg/probe/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/Performance/Status", probeSystemPerformanceStatus},
{"System/Resource/Usage", probeSystemResourceUsage},
{"System/SDNConnector", probeSystemSDNConnector},
{"System/SensorInfo", probeSystemSensorInfo},
Expand Down
157 changes: 157 additions & 0 deletions pkg/probe/system_performance_status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
// 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_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_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_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_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_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_ratio",
"Percentage of CPU utilization that occurred at the user level.",
[]string{"vdom"}, nil,
)
cpuSystem = prometheus.NewDesc(
"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_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_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_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_bytes_total",
"All the installed memory in RAM, in bytes.",
[]string{"vdom"}, nil,
)
memUsed = prometheus.NewDesc(
"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_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_bytes",
"Freeable buffers/caches memory, in bytes.",
[]string{"vdom"}, 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"`
VDOM string `json:"vdom"`
}

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 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))
}
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
}
Loading
Loading