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+
114package probe
215
316import (
417 "log"
518
619 "github.com/prometheus-community/fortigate_exporter/pkg/http"
720 "github.com/prometheus/client_golang/prometheus"
8- )
21+ )
22+
23+ func probeNetworkDnsLatency (c http.FortiHTTP , meta * TargetMetadata ) ([]prometheus.Metric , bool ) {
24+ var (
25+ dnsLatency = prometheus .NewDesc (
26+ "fortigate_network_dns_latency" ,
27+ "Network dns latency" ,
28+ []string {"service" , "ip" }, nil ,
29+ )
30+ dnsLastUpdate = prometheus .NewDesc (
31+ "fortigate_network_dns_latest_update" ,
32+ "Network dns last update" ,
33+ []string {"service" , "ip" }, nil ,
34+ )
35+ )
36+
37+ type DnsLatencty struct {
38+ Service string `json:"service"`
39+ Latency float64 `json:"latency"`
40+ LastUpdate float64 `json:"last_update"`
41+ Ip string `json:"ip"`
42+ }
43+
44+ type DnsLatencyResult struct {
45+ Results []DnsLatencty `json:"results"`
46+ }
47+
48+ var res DnsLatencyResult
49+ if err := c .Get ("api/v2/monitor/network/dns/latency" , "" , & res ); err != nil {
50+ log .Printf ("Warning: %v" , err )
51+ return nil , false
52+ }
53+ m := []prometheus.Metric {}
54+ for _ , r := range res .Results {
55+ m = append (m , prometheus .MustNewConstMetric (dnsLatency , prometheus .GaugeValue , r .Latency , r .Service , r .Ip ))
56+ m = append (m , prometheus .MustNewConstMetric (dnsLastUpdate , prometheus .GaugeValue , r .LastUpdate , r .Service , r .Ip ))
57+ }
58+
59+ return m , true
60+ }
0 commit comments