Skip to content

Commit 4c5c7f7

Browse files
committed
feat: add max connections metric for each lb real server
1 parent 4099e2a commit 4c5c7f7

5 files changed

Lines changed: 78 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ To improve security, limit permissions to required ones only (least privilege pr
168168
|BGP/Neighbors/IPv4 | netgrp.route-cfg |api/v2/monitor/router/bgp/neighbors |
169169
|BGP/Neighbors/IPv6 | netgrp.route-cfg |api/v2/monitor/router/bgp/neighbors6 |
170170
|Firewall/IpPool | fwgrp.policy |api/v2/monitor/firewall/ippool |
171-
|Firewall/LoadBalance | fwgrp.others |api/v2/monitor/firewall/load-balance |
171+
|Firewall/LoadBalance | fwgrp.others |api/v2/monitor/firewall/load-balance<br>api/v2/cmdb/firewall/vip |
172172
|Firewall/Policies | fwgrp.policy |api/v2/monitor/firewall/policy/select<br>api/v2/monitor/firewall/policy6/select<br>api/v2/cmdb/firewall/policy<br>api/v2/cmdb/firewall/policy6 |
173173
|License/Status | *any* |api/v2/monitor/license/status/select |
174174
|Log/Fortianalyzer/Status | loggrp.config |api/v2/monitor/log/fortianalyzer |

metrics.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ Per-VDOM:
209209
* `fortigate_lb_real_server_active_sessions`
210210
* `fortigate_lb_real_server_rtt_seconds`
211211
* `fortigate_lb_real_server_processed_bytes_total`
212+
* `fortigate_lb_real_server_max_connections`
212213

213214
Per-Certificate:
214215
* _System/AvailableCertificates_

pkg/probe/firewall_load_balance.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ func probeFirewallLoadBalance(c fortigatehttpclient.FortiHTTP, meta *TargetMetad
6565
"Number of bytes processed by this real server",
6666
[]string{"vdom", "virtual_server", "id"}, nil,
6767
)
68+
realServerMaxConnections = prometheus.NewDesc(
69+
"fortigate_lb_real_server_max_connections",
70+
"Configured maximum concurrent connections for this real server (0 = unlimited)",
71+
[]string{"vdom", "virtual_server", "id"}, nil,
72+
)
6873
)
6974

7075
type RealServer struct {
@@ -106,6 +111,40 @@ func probeFirewallLoadBalance(c fortigatehttpclient.FortiHTTP, meta *TargetMetad
106111
return nil, false
107112
}
108113

114+
type vipRealServer struct {
115+
ID int `json:"id"`
116+
MaxConnections int `json:"max-connections"`
117+
}
118+
type vipConfig struct {
119+
Name string `json:"name"`
120+
RealServers []vipRealServer `json:"realservers"`
121+
}
122+
type vipResponse struct {
123+
Results []vipConfig
124+
VDOM string
125+
}
126+
127+
var vips []vipResponse
128+
if err := c.Get("api/v2/cmdb/firewall/vip", "vdom=*", &vips); err != nil {
129+
log.Printf("Error: %v", err)
130+
return nil, false
131+
}
132+
133+
maxConnections := map[string]map[int]int{}
134+
for _, v := range vips {
135+
for _, vc := range v.Results {
136+
key := v.VDOM + "\x00" + vc.Name
137+
rsMap, ok := maxConnections[key]
138+
if !ok {
139+
rsMap = map[int]int{}
140+
maxConnections[key] = rsMap
141+
}
142+
for _, rs := range vc.RealServers {
143+
rsMap[rs.ID] = rs.MaxConnections
144+
}
145+
}
146+
}
147+
109148
m := []prometheus.Metric{}
110149

111150
for _, r := range rs {
@@ -157,6 +196,7 @@ func probeFirewallLoadBalance(c fortigatehttpclient.FortiHTTP, meta *TargetMetad
157196
m = append(m, prometheus.MustNewConstMetric(realServerSessions, prometheus.GaugeValue, realServer.ActiveSessions, r.VDOM, virtualServer.Name, strconv.Itoa(realServer.ID)))
158197
m = append(m, prometheus.MustNewConstMetric(realServerRTT, prometheus.GaugeValue, realServerRTTValue, r.VDOM, virtualServer.Name, strconv.Itoa(realServer.ID)))
159198
m = append(m, prometheus.MustNewConstMetric(realServerBytesProcessed, prometheus.CounterValue, realServer.BytesProcessed, r.VDOM, virtualServer.Name, strconv.Itoa(realServer.ID)))
199+
m = append(m, prometheus.MustNewConstMetric(realServerMaxConnections, prometheus.GaugeValue, float64(maxConnections[r.VDOM+"\x00"+virtualServer.Name][realServer.ID]), r.VDOM, virtualServer.Name, strconv.Itoa(realServer.ID)))
160200
}
161201
}
162202
}

pkg/probe/firewall_load_balance_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
func TestFirewallLoadBalance(t *testing.T) {
2525
c := newFakeClient()
2626
c.prepare("api/v2/monitor/firewall/load-balance?vdom=*&start=0&count=1000", "testdata/fw-loadbalancers.jsonnet")
27+
c.prepare("api/v2/cmdb/firewall/vip?vdom=*", "testdata/fw-loadbalancers-vip-config.jsonnet")
2728
r := prometheus.NewPedanticRegistry()
2829
if !testProbe(probeFirewallLoadBalance, c, r) {
2930
t.Errorf("testLoadBalanceServers() returned non-success")
@@ -42,6 +43,12 @@ func TestFirewallLoadBalance(t *testing.T) {
4243
fortigate_lb_real_server_info{id="2",ip="10.10.0.2",port="8080",vdom="root",virtual_server="LB-EXAMPLE"} 1
4344
fortigate_lb_real_server_info{id="3",ip="10.10.0.3",port="8080",vdom="root",virtual_server="LB-EXAMPLE"} 1
4445
fortigate_lb_real_server_info{id="4",ip="10.10.0.4",port="8080",vdom="root",virtual_server="LB-EXAMPLE"} 1
46+
# HELP fortigate_lb_real_server_max_connections Configured maximum concurrent connections for this real server (0 = unlimited)
47+
# TYPE fortigate_lb_real_server_max_connections gauge
48+
fortigate_lb_real_server_max_connections{id="1",vdom="root",virtual_server="LB-EXAMPLE"} 10000
49+
fortigate_lb_real_server_max_connections{id="2",vdom="root",virtual_server="LB-EXAMPLE"} 5000
50+
fortigate_lb_real_server_max_connections{id="3",vdom="root",virtual_server="LB-EXAMPLE"} 0
51+
fortigate_lb_real_server_max_connections{id="4",vdom="root",virtual_server="LB-EXAMPLE"} 2000
4552
# HELP fortigate_lb_real_server_mode Mode of this real server: active, standby or disabled
4653
# TYPE fortigate_lb_real_server_mode gauge
4754
fortigate_lb_real_server_mode{id="1",mode="active",vdom="root",virtual_server="LB-EXAMPLE"} 1
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# api/v2/cmdb/firewall/vip?vdom=*
2+
[
3+
{
4+
"results":[
5+
{
6+
"name":"LB-EXAMPLE",
7+
"realservers":[
8+
{
9+
"id":1,
10+
"max-connections":10000
11+
},
12+
{
13+
"id":2,
14+
"max-connections":5000
15+
},
16+
{
17+
"id":3,
18+
"max-connections":0
19+
},
20+
{
21+
"id":4,
22+
"max-connections":2000
23+
}
24+
]
25+
}
26+
],
27+
"vdom":"root"
28+
}
29+
]

0 commit comments

Comments
 (0)