-
Notifications
You must be signed in to change notification settings - Fork 119
Feature/dns latency #334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
SuperQ
merged 11 commits into
prometheus-community:main
from
Philldomd:feature/dns-latency
Nov 14, 2025
Merged
Feature/dns latency #334
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
81722bb
Init
Philldomd 8471644
Network latency implementation, tested in 7.4
Philldomd df8c266
Better metric names and description
Philldomd 5211b71
Merge branch 'main' into feature/dns-latency
Philldomd 8d24fc3
Merge branch 'main' into feature/dns-latency
Philldomd ce2ebb4
Merge branch 'main' into feature/dns-latency
Philldomd d33031b
Merge branch 'main' into feature/dns-latency
Philldomd a2067e0
Removed fortigate_network_dns_latest_update
Philldomd 186a15b
Lint error solved
Philldomd 968d0c9
Corrected Error
Philldomd 9db53b2
Linter installed and run with --fix
Philldomd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| // 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 probeNetworkDnsLatency(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) { | ||
| var ( | ||
| dnsLatency = prometheus.NewDesc( | ||
| "fortigate_network_dns_latency", | ||
| "Network dns latency", | ||
| []string{"service", "ip"}, nil, | ||
| ) | ||
| dnsLastUpdate = prometheus.NewDesc( | ||
| "fortigate_network_dns_latest_update", | ||
|
Philldomd marked this conversation as resolved.
Outdated
|
||
| "Network dns last update", | ||
| []string{"service", "ip"}, nil, | ||
| ) | ||
| ) | ||
|
|
||
| type DnsLatencty struct { | ||
| Service string `json:"service"` | ||
| Latency float64 `json:"latency"` | ||
| LastUpdate float64 `json:"last_update"` | ||
| Ip string `json:"ip"` | ||
| } | ||
|
|
||
| type DnsLatencyResult struct { | ||
| Results []DnsLatencty `json:"results"` | ||
| } | ||
|
|
||
| var res DnsLatencyResult | ||
| if err := c.Get("api/v2/monitor/network/dns/latency", "", &res); err != nil { | ||
| log.Printf("Warning: %v", err) | ||
| return nil, false | ||
| } | ||
| m := []prometheus.Metric{} | ||
| for _, r := range res.Results { | ||
| m = append(m, prometheus.MustNewConstMetric(dnsLatency, prometheus.GaugeValue, r.Latency, r.Service, r.Ip)) | ||
| m = append(m, prometheus.MustNewConstMetric(dnsLastUpdate, prometheus.GaugeValue, r.LastUpdate, r.Service, r.Ip)) | ||
| } | ||
|
|
||
| return m, true | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // 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 ( | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/prometheus/client_golang/prometheus" | ||
| "github.com/prometheus/client_golang/prometheus/testutil" | ||
| ) | ||
|
|
||
| func TestNetworkDnsLatency(t *testing.T) { | ||
| c := newFakeClient() | ||
| c.prepare("api/v2/monitor/network/dns/latency", "testdata/network-dns-latency.jsonnet") | ||
| r := prometheus.NewPedanticRegistry() | ||
| if !testProbe(probeNetworkDnsLatency, c, r) { | ||
| t.Errorf("probeNetworkDnsLatency() returned non-success") | ||
| } | ||
|
|
||
| em := ` | ||
| # HELP fortigate_network_dns_latency Network dns latency | ||
| # TYPE fortigate_network_dns_latency gauge | ||
| fortigate_network_dns_latency{ip="8.8.8.8",service="dns_server"} 10 | ||
| # HELP fortigate_network_dns_latest_update Network dns last update | ||
| # TYPE fortigate_network_dns_latest_update gauge | ||
| fortigate_network_dns_latest_update{ip="8.8.8.8",service="dns_server"} 1040 | ||
| ` | ||
|
|
||
| if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil { | ||
| t.Fatalf("metric compare: err %v", err) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # api/v2/monitor/network/dns/latency | ||
| { | ||
| "http_method": "GET", | ||
| "results": [ | ||
| { | ||
| "service": "dns_server", | ||
| "latency": 10, | ||
| "last_update": 1040, | ||
| "ip": "8.8.8.8" | ||
| } | ||
| ], | ||
| "vdom": "root", | ||
| "path": "network", | ||
| "name": "dns", | ||
| "action": "latency", | ||
| "status": "success", | ||
| "serial": "FTK", | ||
| "version": "v7.4.8", | ||
| "build": 2795 | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.