Skip to content

Commit cd65349

Browse files
committed
Added dns duration metric
1 parent 8c5d24c commit cd65349

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
README.md

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ In order to discover other agents, and enrich the agent information with metadat
4242

4343
`kmoncon` agents by default will perform 5 x 4 byte UDP packet tests between every other agent, every 5 seconds. Each test waits for a response from the destination agent. The RTT timeout is 250ms, anything longer than that and we consider the packets lost in the abyss. The metrics output from UDP tests are:
4444

45-
- `GAUGE kconmon_udp_duration_milliseconds`: The total RTT from sending the packet to receiving a response
46-
- `GAUGE kconmon_udp_duration_variance_milliseconds`: The variance between the slowest and the fastest packet
47-
- `GAUGE kconmon_udp_loss`: The percentage of requests from the batch that failed
45+
- `GAUGE kconmon_udp_duration_milliseconds`: The total RTT from sending the packet to receiving a response
46+
- `GAUGE kconmon_udp_duration_variance_milliseconds`: The variance between the slowest and the fastest packet
47+
- `GAUGE kconmon_udp_loss`: The percentage of requests from the batch that failed
4848
- `COUNTER kconmon_udp_results_total`: A Counter of test results, pass and fail
4949

5050
### TCP Testing
@@ -53,8 +53,8 @@ In order to discover other agents, and enrich the agent information with metadat
5353

5454
The metrics output from TCP tests are:
5555

56-
- `GAUGE kconmon_tcp_connect_milliseconds`: The duration from socket assignment to successful TCP connection
57-
- `GAUGE kconmon_tcp_duration_milliseconds`: The total RTT of the request
56+
- `GAUGE kconmon_tcp_connect_milliseconds`: The duration from socket assignment to successful TCP connection of the last test run
57+
- `GAUGE kconmon_tcp_duration_milliseconds`: The total RTT of the request
5858
- `COUNTER kconmon_tcp_results_total`: A Counter of test results, pass and fail
5959

6060
### DNS Testing
@@ -63,6 +63,7 @@ The metrics output from TCP tests are:
6363

6464
The metrics output from DNS tests are:
6565

66+
- `GAUGE kconmon_dns_duration_milliseconds`: The duration of the last test run
6667
- `COUNTER kconmon_dns_results_total`: A Counter of test results, pass and fail
6768

6869
## Prometheus Metrics

lib/apps/agent/metrics.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export default class Metrics implements IMetrics {
2222
private UDPLoss: client.Gauge<string>
2323

2424
private DNS: client.Counter<string>
25+
private DNSDuration: client.Gauge<string>
2526

2627
constructor(config: IConfig) {
2728
client.register.clear()
@@ -38,7 +39,7 @@ export default class Metrics implements IMetrics {
3839
})
3940

4041
this.UDPDuration = new client.Gauge<string>({
41-
help: ' Average duration per packet',
42+
help: 'Average duration per packet',
4243
labelNames: ['source', 'destination', 'source_zone', 'destination_zone'],
4344
name: `${config.metricsPrefix}_udp_duration_milliseconds`
4445
})
@@ -61,6 +62,12 @@ export default class Metrics implements IMetrics {
6162
name: `${config.metricsPrefix}_dns_results_total`
6263
})
6364

65+
this.DNSDuration = new client.Gauge<string>({
66+
help: 'Total time taken to complete the DNS test',
67+
labelNames: ['source', 'source_zone', 'host'],
68+
name: `${config.metricsPrefix}_dns_duration_milliseconds`
69+
})
70+
6471
this.UDP = new client.Counter<string>({
6572
help: 'UDP Test Results',
6673
labelNames: [
@@ -91,6 +98,11 @@ export default class Metrics implements IMetrics {
9198
this.DNS.labels(source, result.source.zone, result.host, result.result).inc(
9299
1
93100
)
101+
this.DNSDuration.labels(
102+
result.source.nodeName,
103+
result.source.zone,
104+
result.host
105+
).set(result.duration)
94106
}
95107

96108
public resetTCPTestResults() {

lib/tester/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ interface ITestResult {
2424
export interface IDNSTestResult {
2525
source: IAgent
2626
host: string
27+
duration: number
2728
result: 'pass' | 'fail'
2829
}
2930

@@ -111,20 +112,25 @@ export default class Tester implements ITester {
111112
public async runDNSTests(): Promise<IDNSTestResult[]> {
112113
const promises = this.config.testConfig.dns.hosts.map(
113114
async (host): Promise<IDNSTestResult> => {
115+
const hrstart = process.hrtime()
114116
try {
115117
const result = await this.resolver.resolve4(host)
118+
const hrend = process.hrtime(hrstart)
116119
const mapped: IDNSTestResult = {
117120
source: this.me,
118121
host,
122+
duration: hrend[1] / 1000000,
119123
result: result && result.length > 0 ? 'pass' : 'fail'
120124
}
121125
this.metrics.handleDNSTestResult(mapped)
122126
return mapped
123127
} catch (ex) {
124128
this.logger.error(`dns test for ${host} failed`, ex)
129+
const hrend = process.hrtime(hrstart)
125130
const mapped: IDNSTestResult = {
126131
source: this.me,
127132
host,
133+
duration: hrend[1] / 1000000,
128134
result: 'fail'
129135
}
130136
this.metrics.handleDNSTestResult(mapped)

0 commit comments

Comments
 (0)