Skip to content

Commit 8233b94

Browse files
authored
Merge branch 'main' into feature/system-ha-peer
2 parents 4076976 + fdb0d3a commit 8233b94

5 files changed

Lines changed: 117 additions & 0 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Supported metrics right now as follows.
3737

3838
Global:
3939

40+
* _Network/Dns/Latency_
41+
* `fortigate_network_dns_latency_`
4042
* _System/SensorInfo_
4143
* `fortigate_sensor_alarm_status`
4244
* `fortigate_sensor_fan_rpm`
@@ -442,6 +444,7 @@ To improve security, limit permissions to required ones only (least privilege pr
442444
|Log/Fortianalyzer/Status | loggrp.config |api/v2/monitor/log/fortianalyzer |
443445
|Log/Fortianalyzer/Queue | loggrp.config |api/v2/monitor/log/fortianalyzer-queue |
444446
|Log/DiskUsage | loggrp.config |api/v2/monitor/log/current-disk-usage |
447+
|Network/Dns/Latency | sysgrp.cfg |api/v2/monitor/network/dns/latency |
445448
|System/AvailableCertificates | *any* |api/v2/monitor/system/available-certificates |
446449
|System/Fortimanager/Status | sysgrp.cfg |api/v2/monitor/system/fortimanager/status |
447450
|System/HAStatistics | sysgrp.cfg |api/v2/monitor/system/ha-statistics<br>api/v2/cmdb/system/ha |

pkg/probe/network_dns_latency.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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/client_golang/prometheus"
20+
21+
"github.com/prometheus-community/fortigate_exporter/pkg/http"
22+
)
23+
24+
func probeNetworkDNSLatency(c http.FortiHTTP, _ *TargetMetadata) ([]prometheus.Metric, bool) {
25+
dnsLatency := prometheus.NewDesc(
26+
"fortigate_network_dns_latency_seconds",
27+
"Network dns latency",
28+
[]string{"service", "ip"}, nil,
29+
)
30+
31+
type DNSLatencty struct {
32+
Service string `json:"service"`
33+
Latency float64 `json:"latency"`
34+
LastUpdate float64 `json:"last_update"`
35+
IP string `json:"ip"`
36+
}
37+
38+
type DNSLatencyResult struct {
39+
Results []DNSLatencty `json:"results"`
40+
}
41+
42+
var res DNSLatencyResult
43+
if err := c.Get("api/v2/monitor/network/dns/latency", "", &res); err != nil {
44+
log.Printf("Warning: %v", err)
45+
return nil, false
46+
}
47+
m := []prometheus.Metric{}
48+
for _, r := range res.Results {
49+
m = append(m, prometheus.MustNewConstMetric(dnsLatency, prometheus.GaugeValue, r.Latency*0.001, r.Service, r.IP))
50+
}
51+
52+
return m, true
53+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
package probe
14+
15+
import (
16+
"strings"
17+
"testing"
18+
19+
"github.com/prometheus/client_golang/prometheus"
20+
"github.com/prometheus/client_golang/prometheus/testutil"
21+
)
22+
23+
func TestNetworkDnsLatency(t *testing.T) {
24+
c := newFakeClient()
25+
c.prepare("api/v2/monitor/network/dns/latency", "testdata/network-dns-latency.jsonnet")
26+
r := prometheus.NewPedanticRegistry()
27+
if !testProbe(probeNetworkDNSLatency, c, r) {
28+
t.Errorf("probeNetworkDNSLatency() returned non-success")
29+
}
30+
31+
em := `
32+
# HELP fortigate_network_dns_latency_seconds Network dns latency
33+
# TYPE fortigate_network_dns_latency_seconds gauge
34+
fortigate_network_dns_latency_seconds{ip="8.8.8.8",service="dns_server"} 0.01
35+
`
36+
37+
if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil {
38+
t.Fatalf("metric compare: err %v", err)
39+
}
40+
}

pkg/probe/probe.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ func (p *Collector) Probe(ctx context.Context, target map[string]string, hc *htt
143143
{"Log/Fortianalyzer/Status", probeLogAnalyzer},
144144
{"Log/Fortianalyzer/Queue", probeLogAnalyzerQueue},
145145
{"Log/DiskUsage", probeLogCurrentDiskUsage},
146+
{"Network/Dns/Latency", probeNetworkDNSLatency},
146147
{"System/AvailableCertificates", probeSystemAvailableCertificates},
147148
{"System/Fortimanager/Status", probeSystemFortimanagerStatus},
148149
{"System/HAStatistics", probeSystemHAStatistics},
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# api/v2/monitor/network/dns/latency
2+
{
3+
"http_method": "GET",
4+
"results": [
5+
{
6+
"service": "dns_server",
7+
"latency": 10,
8+
"last_update": 1040,
9+
"ip": "8.8.8.8"
10+
}
11+
],
12+
"vdom": "root",
13+
"path": "network",
14+
"name": "dns",
15+
"action": "latency",
16+
"status": "success",
17+
"serial": "FTK",
18+
"version": "v7.4.8",
19+
"build": 2795
20+
}

0 commit comments

Comments
 (0)