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
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Global:

Per-VDOM:

* _System/VDOMResources_
* _System/Resource/Usage/VDOM_
* `fortigate_vdom_cpu_usage_ratio`
* `fortigate_vdom_memory_usage_ratio`
* `fortigate_vdom_current_sessions`
Expand Down Expand Up @@ -92,6 +92,21 @@ Per-VDOM:
* _System/SDNConnector_
* `fortigate_system_sdn_connector_status`
* `fortigate_system_sdn_connector_last_update_seconds`
* _System/VDOMResource_
* `fortigate_vdom_resource_cpu_usage`
* `fortigate_vdom_resource_memory_usage`
* `fortigate_vdom_resource_setup_rate`
* `fortigate_vdom_resource_deletable`
* `fortigate_vdom_resource_object_id`
* `fortigate_vdom_resource_object_custom_max`
* `fortigate_vdom_resource_object_custom_min_value`
* `fortigate_vdom_resource_object_custom_max_value`
* `fortigate_vdom_resource_object_guaranted`
* `fortigate_vdom_resource_object_guaranted_max_value`
* `fortigate_vdom_resource_object_guaranted_min_value`
* `fortigate_vdom_resource_object_global_max`
* `fortigate_vdom_resource_object_current_usage`
* `fortigate_vdom_resource_object_usage_percentage`
* _User/Fsso_
* `fortigate_user_fsso_info`
* _VPN/Ssl/Connections_
Expand Down Expand Up @@ -417,10 +432,11 @@ To improve security, limit permissions to required ones only (least privilege pr
|System/Interface | netgrp.cfg |api/v2/monitor/system/interface/select |
|System/LinkMonitor | sysgrp.cfg |api/v2/monitor/system/link-monitor |
|System/Resource/Usage | sysgrp.cfg |api/v2/monitor/system/resource/usage |
|System/Resource/Usage/VDOM | 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 |
|System/Time/Clock | sysgrp.cfg |api/v2/monitor/system/time |
|System/VDOMResources | sysgrp.cfg |api/v2/monitor/system/resource/usage |
|System/System/VDOMResource | sysgrp.cfg |api/v2/monitor/system/vdom-resource |
|User/Fsso | authgrp |api/v2/monitor/user/fsso |
|VPN/IPSec | vpngrp |api/v2/monitor/vpn/ipsec |
|VPN/Ssl/Connections | vpngrp |api/v2/monitor/vpn/ssl |
Expand Down
3 changes: 2 additions & 1 deletion pkg/probe/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,11 @@ func (p *ProbeCollector) Probe(ctx context.Context, target map[string]string, hc
{"System/Interface", probeSystemInterface},
{"System/LinkMonitor", probeSystemLinkMonitor},
{"System/Resource/Usage", probeSystemResourceUsage},
{"System/Resource/Usage/VDOM", probeSystemResourceUsagePerVdom},
{"System/SDNConnector", probeSystemSDNConnector},
{"System/SensorInfo", probeSystemSensorInfo},
{"System/Status", probeSystemStatus},
{"System/VDOMResources", probeSystemVDOMResources},
{"System/VDOMResource",probeSystemVdomResource},
{"System/HAChecksum", probeSystemHAChecksum},
{"User/Fsso", probeUserFsso},
{"VPN/IPSec", probeVPNIPSec},
Expand Down
2 changes: 1 addition & 1 deletion pkg/probe/system_resources_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func probeSystemResourceUsage(c http.FortiHTTP, meta *TargetMetadata) ([]prometh
return m, true
}

func probeSystemVDOMResources(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {
func probeSystemResourceUsagePerVdom(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {
var (
mResCPU = prometheus.NewDesc(
"fortigate_vdom_cpu_usage_ratio",
Expand Down
4 changes: 2 additions & 2 deletions pkg/probe/system_resources_usage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ func TestSystemVDOMResources(t *testing.T) {
c := newFakeClient()
c.prepare("api/v2/monitor/system/resource/usage", "testdata/usage-vdom.jsonnet")
r := prometheus.NewPedanticRegistry()
if !testProbe(probeSystemVDOMResources, c, r) {
t.Errorf("probeSystemVDOMResources() returned non-success")
if !testProbe(probeSystemResourceUsagePerVdom, c, r) {
t.Errorf("probeSystemResourceUsagePerVdom() returned non-success")
}

em := `
Expand Down
147 changes: 147 additions & 0 deletions pkg/probe/system_vdom-resource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
// 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"

"github.com/prometheus-community/fortigate_exporter/pkg/http"
"github.com/prometheus/client_golang/prometheus"
)

func probeSystemVdomResource(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {

vdomDesc := make(map[string]*prometheus.Desc)
vdomDesc["cpu"] = prometheus.NewDesc(
"fortigate_vdom_resource_cpu_usage",
"Current VDOM CPU usage in percentage",
[]string{"vdom"}, nil,
)
vdomDesc["memory"] = prometheus.NewDesc(
"fortigate_vdom_resource_memory_usage",
"Current VDOM memory usage in percentage",
[]string{"vdom"}, nil,
)
vdomDesc["setup_rate"] = prometheus.NewDesc(
"fortigate_vdom_resource_setup_rate",
"Current VDOM memory usage in percentage",
[]string{"vdom"}, nil,
)
vdomDesc["is_deletable"] = prometheus.NewDesc(
"fortigate_vdom_resource_deletable",
"1 if VDOM is deletable",
[]string{"vdom"}, nil,
)
vdomDesc["id"] = prometheus.NewDesc(
"fortigate_vdom_resource_object_id",
"Object Resource ID",
[]string{"vdom", "object"},nil,
)
vdomDesc["custom_max"] = prometheus.NewDesc(
"fortigate_vdom_resource_object_custom_max",
"Object Custom Max",
[]string{"vdom", "object"},nil,
)
vdomDesc["min_custom_value"] = prometheus.NewDesc(
"fortigate_vdom_resource_object_custom_min_value",
"Object Minimum custom value",
[]string{"vdom", "object"}, nil,
)
vdomDesc["max_custom_value"] = prometheus.NewDesc(
"fortigate_vdom_resource_object_custom_max_value",
"Object Maximum custom value",
[]string{"vdom", "object"},nil,
)
vdomDesc["guaranteed"] = prometheus.NewDesc(
"fortigate_vdom_resource_object_guaranted",
"Object Guaranted",
[]string{"vdom", "object"},nil,
)
vdomDesc["min_guaranteed_value"] = prometheus.NewDesc(
"fortigate_vdom_resource_object_guaranted_max_value",
"Object Minimum guaranteed value",
[]string{"vdom", "object"},nil,
)
vdomDesc["max_guaranteed_value"] = prometheus.NewDesc(
"fortigate_vdom_resource_object_guaranted_min_value",
"Object Maximum guaranteed value",
[]string{"vdom", "object"},nil,
)
vdomDesc["global_max"] = prometheus.NewDesc(
"fortigate_vdom_resource_object_global_max",
"Object Global max",
[]string{"vdom", "object"},nil,
)
vdomDesc["current_usage"] = prometheus.NewDesc(
"fortigate_vdom_resource_object_current_usage",
"Object Current usage",
[]string{"vdom", "object"},nil,
)
vdomDesc["usage_percent"] = prometheus.NewDesc(
"fortigate_vdom_resource_object_usage_percentage",
"Object Usage percentage",
[]string{"vdom", "object"},nil,
)

type VDOMResourceResult struct {
Result interface{} `json:"results"`
Vdom string `json:"vdom"`
}

var res []VDOMResourceResult
if err := c.Get("api/v2/monitor/system/vdom-resource", "vdom=*", &res); err != nil {
log.Printf("Error: %v", err)
return nil, false
}

m := []prometheus.Metric{}
for _, result := range res {
for k, elem := range result.Result.(map[string]interface{}) {
switch k {
case "cpu", "memory", "setup_rate":
m = append(m, prometheus.MustNewConstMetric(vdomDesc[k], prometheus.GaugeValue, elem.(float64), result.Vdom))
case "is_deletable":
if elem.(bool) {
m = append(m, prometheus.MustNewConstMetric(vdomDesc[k], prometheus.GaugeValue, 1, result.Vdom))
} else {
m = append(m, prometheus.MustNewConstMetric(vdomDesc[k], prometheus.GaugeValue, 0, result.Vdom))
}
case "session",
"ipsec-phase1",
"ipsec-phase2",
"ipsec-phase1-interface",
"ipsec-phase2-interface",
"dialup-tunnel",
"firewall-policy",
"firewall-address",
"firewall-addrgrp",
"custom-service",
"service-group",
"onetime-schedule",
"recurring-schedule",
"user",
"user-group",
"sslvpn",
"proxy",
"log-disk-quota":
for val, e := range elem.(map[string]interface{}) {
m = append(m, prometheus.MustNewConstMetric(vdomDesc[val], prometheus.GaugeValue, e.(float64), result.Vdom, k))
}
default:
log.Printf("Missing handler for: %s", k)
}
}
}
return m, true
}
Loading