Skip to content

Commit cdb8db5

Browse files
PhilldomdSuperQ
andauthored
Adding new probe for vdom resources (#338)
* Adding new probe for vdom resources Signed-off-by: Örnfeldt Philip (66140321) <philip.ornfeldt@forsakringskassan.se> * Added Ratio to percentage metrics Signed-off-by: Philip Örnfeldt <philip.ornfeldt@outlook.com> Signed-off-by: Örnfeldt Philip (66140321) <philip.ornfeldt@forsakringskassan.se> * Lint fixing Signed-off-by: Örnfeldt Philip (66140321) <philip.ornfeldt@forsakringskassan.se> --------- Signed-off-by: Örnfeldt Philip (66140321) <philip.ornfeldt@forsakringskassan.se> Signed-off-by: Philip Örnfeldt <philip.ornfeldt@outlook.com> Signed-off-by: Ben Kochie <superq@gmail.com> Co-authored-by: Ben Kochie <superq@gmail.com>
1 parent 1013ae9 commit cdb8db5

7 files changed

Lines changed: 1071 additions & 6 deletions

File tree

README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Global:
7272

7373
Per-VDOM:
7474

75-
* _System/VDOMResources_
75+
* _System/Resource/Usage/VDOM_
7676
* `fortigate_vdom_cpu_usage_ratio`
7777
* `fortigate_vdom_memory_usage_ratio`
7878
* `fortigate_vdom_current_sessions`
@@ -106,6 +106,21 @@ Per-VDOM:
106106
* _System/SDNConnector_
107107
* `fortigate_system_sdn_connector_status`
108108
* `fortigate_system_sdn_connector_last_update_seconds`
109+
* _System/VDOMResource_
110+
* `fortigate_vdom_resource_cpu_usage`
111+
* `fortigate_vdom_resource_memory_usage`
112+
* `fortigate_vdom_resource_setup_rate`
113+
* `fortigate_vdom_resource_deletable`
114+
* `fortigate_vdom_resource_object_id`
115+
* `fortigate_vdom_resource_object_custom_max`
116+
* `fortigate_vdom_resource_object_custom_min_value`
117+
* `fortigate_vdom_resource_object_custom_max_value`
118+
* `fortigate_vdom_resource_object_guaranted`
119+
* `fortigate_vdom_resource_object_guaranted_max_value`
120+
* `fortigate_vdom_resource_object_guaranted_min_value`
121+
* `fortigate_vdom_resource_object_global_max`
122+
* `fortigate_vdom_resource_object_current_usage`
123+
* `fortigate_vdom_resource_object_usage_percentage`
109124
* _User/Fsso_
110125
* `fortigate_user_fsso_info`
111126
* _VPN/Ssl/Connections_
@@ -433,10 +448,11 @@ To improve security, limit permissions to required ones only (least privilege pr
433448
|System/LinkMonitor | sysgrp.cfg |api/v2/monitor/system/link-monitor |
434449
|System/Ntp/Status | netgrp.cfg |api/v2/monitor/system/ntp/status |
435450
|System/Resource/Usage | sysgrp.cfg |api/v2/monitor/system/resource/usage |
451+
|System/Resource/Usage/VDOM | sysgrp.cfg |api/v2/monitor/system/resource/usage |
436452
|System/SensorInfo | sysgrp.cfg |api/v2/monitor/system/sensor-info |
437453
|System/Status | *any* |api/v2/monitor/system/status |
438454
|System/Time/Clock | sysgrp.cfg |api/v2/monitor/system/time |
439-
|System/VDOMResources | sysgrp.cfg |api/v2/monitor/system/resource/usage |
455+
|System/System/VDOMResource | sysgrp.cfg |api/v2/monitor/system/vdom-resource |
440456
|User/Fsso | authgrp |api/v2/monitor/user/fsso |
441457
|VPN/IPSec | vpngrp |api/v2/monitor/vpn/ipsec |
442458
|VPN/Ssl/Connections | vpngrp |api/v2/monitor/vpn/ssl |

pkg/probe/probe.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,11 @@ func (p *Collector) Probe(ctx context.Context, target map[string]string, hc *htt
151151
{"System/LinkMonitor", probeSystemLinkMonitor},
152152
{"System/Ntp/Status", probeSystemNtpStatus},
153153
{"System/Resource/Usage", probeSystemResourceUsage},
154+
{"System/Resource/Usage/VDOM", probeSystemResourceUsagePerVdom},
154155
{"System/SDNConnector", probeSystemSDNConnector},
155156
{"System/SensorInfo", probeSystemSensorInfo},
156157
{"System/Status", probeSystemStatus},
157-
{"System/VDOMResources", probeSystemVDOMResources},
158+
{"System/VDOMResource",probeSystemVdomResource},
158159
{"System/HAChecksum", probeSystemHAChecksum},
159160
{"User/Fsso", probeUserFsso},
160161
{"VPN/IPSec", probeVPNIPSec},

pkg/probe/system_resources_usage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func probeSystemResourceUsage(c http.FortiHTTP, _ *TargetMetadata) ([]prometheus
8484
return m, true
8585
}
8686

87-
func probeSystemVDOMResources(c http.FortiHTTP, _ *TargetMetadata) ([]prometheus.Metric, bool) {
87+
func probeSystemResourceUsagePerVdom(c http.FortiHTTP, _ *TargetMetadata) ([]prometheus.Metric, bool) {
8888
var (
8989
mResCPU = prometheus.NewDesc(
9090
"fortigate_vdom_cpu_usage_ratio",

pkg/probe/system_resources_usage_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ func TestSystemVDOMResources(t *testing.T) {
5050
c := newFakeClient()
5151
c.prepare("api/v2/monitor/system/resource/usage", "testdata/usage-vdom.jsonnet")
5252
r := prometheus.NewPedanticRegistry()
53-
if !testProbe(probeSystemVDOMResources, c, r) {
54-
t.Errorf("probeSystemVDOMResources() returned non-success")
53+
if !testProbe(probeSystemResourceUsagePerVdom, c, r) {
54+
t.Errorf("probeSystemResourceUsagePerVdom() returned non-success")
5555
}
5656

5757
em := `

pkg/probe/system_vdom-resource.go

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
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+
19+
"github.com/prometheus-community/fortigate_exporter/pkg/http"
20+
"github.com/prometheus/client_golang/prometheus"
21+
)
22+
23+
func probeSystemVdomResource(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {
24+
25+
vdomDesc := make(map[string]*prometheus.Desc)
26+
vdomDesc["cpu"] = prometheus.NewDesc(
27+
"fortigate_vdom_resource_cpu_usage_ratio",
28+
"Current VDOM CPU usage in percentage",
29+
[]string{"vdom"}, nil,
30+
)
31+
vdomDesc["memory"] = prometheus.NewDesc(
32+
"fortigate_vdom_resource_memory_usage_ratio",
33+
"Current VDOM memory usage in percentage",
34+
[]string{"vdom"}, nil,
35+
)
36+
vdomDesc["setup_rate"] = prometheus.NewDesc(
37+
"fortigate_vdom_resource_setup_ratio",
38+
"Current VDOM memory usage in percentage",
39+
[]string{"vdom"}, nil,
40+
)
41+
vdomDesc["is_deletable"] = prometheus.NewDesc(
42+
"fortigate_vdom_resource_deletable",
43+
"1 if VDOM is deletable",
44+
[]string{"vdom"}, nil,
45+
)
46+
vdomDesc["id"] = prometheus.NewDesc(
47+
"fortigate_vdom_resource_object_id",
48+
"Object Resource ID",
49+
[]string{"vdom", "object"},nil,
50+
)
51+
vdomDesc["custom_max"] = prometheus.NewDesc(
52+
"fortigate_vdom_resource_object_custom_max",
53+
"Object Custom Max",
54+
[]string{"vdom", "object"},nil,
55+
)
56+
vdomDesc["min_custom_value"] = prometheus.NewDesc(
57+
"fortigate_vdom_resource_object_custom_min_value",
58+
"Object Minimum custom value",
59+
[]string{"vdom", "object"}, nil,
60+
)
61+
vdomDesc["max_custom_value"] = prometheus.NewDesc(
62+
"fortigate_vdom_resource_object_custom_max_value",
63+
"Object Maximum custom value",
64+
[]string{"vdom", "object"},nil,
65+
)
66+
vdomDesc["guaranteed"] = prometheus.NewDesc(
67+
"fortigate_vdom_resource_object_guaranteed",
68+
"Object Guaranteed",
69+
[]string{"vdom", "object"},nil,
70+
)
71+
vdomDesc["min_guaranteed_value"] = prometheus.NewDesc(
72+
"fortigate_vdom_resource_object_guaranteed_max_value",
73+
"Object Minimum guaranteed value",
74+
[]string{"vdom", "object"},nil,
75+
)
76+
vdomDesc["max_guaranteed_value"] = prometheus.NewDesc(
77+
"fortigate_vdom_resource_object_guaranteed_min_value",
78+
"Object Maximum guaranteed value",
79+
[]string{"vdom", "object"},nil,
80+
)
81+
vdomDesc["global_max"] = prometheus.NewDesc(
82+
"fortigate_vdom_resource_object_global_max",
83+
"Object Global max",
84+
[]string{"vdom", "object"},nil,
85+
)
86+
vdomDesc["current_usage"] = prometheus.NewDesc(
87+
"fortigate_vdom_resource_object_current_usage",
88+
"Object Current usage",
89+
[]string{"vdom", "object"},nil,
90+
)
91+
vdomDesc["usage_percent"] = prometheus.NewDesc(
92+
"fortigate_vdom_resource_object_usage_ratio",
93+
"Object Usage percentage",
94+
[]string{"vdom", "object"},nil,
95+
)
96+
97+
type VDOMResourceResult struct {
98+
Result interface{} `json:"results"`
99+
Vdom string `json:"vdom"`
100+
}
101+
102+
var res []VDOMResourceResult
103+
if err := c.Get("api/v2/monitor/system/vdom-resource", "vdom=*", &res); err != nil {
104+
log.Printf("Error: %v", err)
105+
return nil, false
106+
}
107+
108+
m := []prometheus.Metric{}
109+
for _, result := range res {
110+
for k, elem := range result.Result.(map[string]interface{}) {
111+
switch k {
112+
case "cpu", "memory", "setup_rate":
113+
m = append(m, prometheus.MustNewConstMetric(vdomDesc[k], prometheus.GaugeValue, elem.(float64), result.Vdom))
114+
case "is_deletable":
115+
if elem.(bool) {
116+
m = append(m, prometheus.MustNewConstMetric(vdomDesc[k], prometheus.GaugeValue, 1, result.Vdom))
117+
} else {
118+
m = append(m, prometheus.MustNewConstMetric(vdomDesc[k], prometheus.GaugeValue, 0, result.Vdom))
119+
}
120+
case "session",
121+
"ipsec-phase1",
122+
"ipsec-phase2",
123+
"ipsec-phase1-interface",
124+
"ipsec-phase2-interface",
125+
"dialup-tunnel",
126+
"firewall-policy",
127+
"firewall-address",
128+
"firewall-addrgrp",
129+
"custom-service",
130+
"service-group",
131+
"onetime-schedule",
132+
"recurring-schedule",
133+
"user",
134+
"user-group",
135+
"sslvpn",
136+
"proxy",
137+
"log-disk-quota":
138+
for val, e := range elem.(map[string]interface{}) {
139+
m = append(m, prometheus.MustNewConstMetric(vdomDesc[val], prometheus.GaugeValue, e.(float64), result.Vdom, k))
140+
}
141+
default:
142+
log.Printf("Missing handler for: %s", k)
143+
}
144+
}
145+
}
146+
return m, true
147+
}

0 commit comments

Comments
 (0)