Initial commit
This commit is contained in:
commit
6c66afc85f
25 changed files with 3049 additions and 0 deletions
111
checker/evaluate.go
Normal file
111
checker/evaluate.go
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
package checker
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
sdk "git.happydns.org/checker-sdk-go/checker"
|
||||
)
|
||||
|
||||
// Implements sdk.CheckerMetricsReporter.
|
||||
func (p *authoritativeConsistencyProvider) ExtractMetrics(ctx sdk.ReportContext, collectedAt time.Time) ([]sdk.CheckMetric, error) {
|
||||
var data ObservationData
|
||||
if err := json.Unmarshal(ctx.Data(), &data); err != nil {
|
||||
return nil, fmt.Errorf("checker: decoding observation: %w", err)
|
||||
}
|
||||
|
||||
var out []sdk.CheckMetric
|
||||
|
||||
for name, r := range data.Results {
|
||||
labels := map[string]string{"zone": data.Zone, "ns": name}
|
||||
|
||||
up := float64(0)
|
||||
if r.UDPReachable && r.Authoritative {
|
||||
up = 1
|
||||
}
|
||||
out = append(out, sdk.CheckMetric{
|
||||
Name: "authoritative_consistency_ns_up",
|
||||
Value: up,
|
||||
Labels: labels,
|
||||
Timestamp: collectedAt,
|
||||
})
|
||||
|
||||
tcp := float64(0)
|
||||
if r.TCPReachable {
|
||||
tcp = 1
|
||||
}
|
||||
out = append(out, sdk.CheckMetric{
|
||||
Name: "authoritative_consistency_ns_tcp",
|
||||
Value: tcp,
|
||||
Labels: labels,
|
||||
Timestamp: collectedAt,
|
||||
})
|
||||
|
||||
if r.LatencyMs > 0 {
|
||||
out = append(out, sdk.CheckMetric{
|
||||
Name: "authoritative_consistency_ns_latency_ms",
|
||||
Value: float64(r.LatencyMs),
|
||||
Unit: "ms",
|
||||
Labels: labels,
|
||||
Timestamp: collectedAt,
|
||||
})
|
||||
}
|
||||
|
||||
if r.Serial > 0 {
|
||||
out = append(out, sdk.CheckMetric{
|
||||
Name: "authoritative_consistency_ns_serial",
|
||||
Value: float64(r.Serial),
|
||||
Labels: labels,
|
||||
Timestamp: collectedAt,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
uniqueSerials := map[uint32]struct{}{}
|
||||
for _, r := range data.Results {
|
||||
if r.Serial != 0 {
|
||||
uniqueSerials[r.Serial] = struct{}{}
|
||||
}
|
||||
}
|
||||
out = append(out, sdk.CheckMetric{
|
||||
Name: "authoritative_consistency_unique_serials",
|
||||
Value: float64(len(uniqueSerials)),
|
||||
Labels: map[string]string{"zone": data.Zone},
|
||||
Timestamp: collectedAt,
|
||||
})
|
||||
|
||||
// Severity counters: skipped entirely when the host doesn't provide
|
||||
// states (metrics-only render path), rather than re-deriving from data.
|
||||
states := ctx.States()
|
||||
if states != nil {
|
||||
var crit, warn, info int
|
||||
for _, st := range states {
|
||||
switch st.Status {
|
||||
case sdk.StatusCrit:
|
||||
crit++
|
||||
case sdk.StatusWarn:
|
||||
warn++
|
||||
case sdk.StatusInfo:
|
||||
info++
|
||||
}
|
||||
}
|
||||
for _, x := range []struct {
|
||||
name string
|
||||
val int
|
||||
}{
|
||||
{"authoritative_consistency_findings_critical", crit},
|
||||
{"authoritative_consistency_findings_warning", warn},
|
||||
{"authoritative_consistency_findings_info", info},
|
||||
} {
|
||||
out = append(out, sdk.CheckMetric{
|
||||
Name: x.name,
|
||||
Value: float64(x.val),
|
||||
Labels: map[string]string{"zone": data.Zone},
|
||||
Timestamp: collectedAt,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return out, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue