Off by default (stats in jarl.yaml). When enabled, Jarl adds a loopback statistics channel and a response log to named's configuration (merged into existing logging/statistics-channels statements) and switches response logging with rndc responselog, because the responselog option only counts when named starts. jarld polls named's counters every minute and tails the response log (resuming after restarts and across rotation). It stores aggregates, never individual queries, in a separate SQLite database: per-minute, hourly and daily counters (queries, result codes, record types, views, zones, cache hits, upstream latency, DNSSEC) and hourly/daily top lists (names, clients, NXDOMAIN and SERVFAIL names, refused clients), each with its own retention. Clients can be anonymized or excluded. - Web UI: Statistics page with KPI tiles, queries and failed answers over time, a weekday x hour heatmap, top lists and breakdowns; SVG charts with hover/keyboard readouts, a table view and light/dark palettes validated for colour-vision deficiency. - CLI: jarl stats status|summary|top|timeline|heatmap|breakdown. - API: /api/v1/stats/*, behind a new "stats" permission resource. - jarld brings named's configuration up to date with jarl.yaml at startup (engine.SyncConfig), never overwriting hand-edited files. - resync now refuses to overwrite drifted files without force, as documented. - tmpfiles.d creates /var/log/named (allowed by named's AppArmor profile on Debian 13 and Ubuntu). - The e2e harness runs named with -f like the Debian unit. - docs/stats.md, plus API, CLI, configuration, permissions and README updates. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
85 lines
2.9 KiB
Go
85 lines
2.9 KiB
Go
package render
|
|
|
|
import (
|
|
"net/netip"
|
|
"strings"
|
|
"testing"
|
|
|
|
"jarl/internal/model"
|
|
)
|
|
|
|
func statsHooks() *StatsHooks {
|
|
return &StatsHooks{Channel: netip.MustParseAddrPort("127.0.0.1:8058"), LogFile: "/var/log/named/jarl-responses.log", LogVersions: 2, LogSize: "20m"}
|
|
}
|
|
|
|
func TestStatsHooksAdded(t *testing.T) {
|
|
s := sampleState(t)
|
|
// Without a logging statement of its own, Jarl adds one.
|
|
for id, o := range s.Options {
|
|
if o.Name == "logging" {
|
|
delete(s.Options, id)
|
|
}
|
|
}
|
|
p := Paths{ConfigDir: "/etc/bind/jarl", ZoneDir: "/var/lib/bind/jarl", CacheDir: "/var/cache/bind/jarl"}
|
|
conf := string(Render(s, p, Extras{Stats: statsHooks()}).File(p.MainConfig()).Content)
|
|
for _, want := range []string{
|
|
"statistics-channels {\n\tinet 127.0.0.1 port 8058 allow { 127.0.0.1; };\n};",
|
|
`file "/var/log/named/jarl-responses.log" versions 2 size 20m;`,
|
|
"\tcategory responses { jarl_responses; };",
|
|
"\tresponselog yes;\n",
|
|
} {
|
|
if !strings.Contains(conf, want) {
|
|
t.Errorf("named.conf lacks %q:\n%s", want, conf)
|
|
}
|
|
}
|
|
// Counters only: no logging, no responselog.
|
|
h := statsHooks()
|
|
h.LogFile = ""
|
|
conf = string(Render(s, p, Extras{Stats: h}).File(p.MainConfig()).Content)
|
|
if !strings.Contains(conf, "statistics-channels") || strings.Contains(conf, "responselog") || strings.Contains(conf, "jarl_responses") {
|
|
t.Errorf("counters-only config:\n%s", conf)
|
|
}
|
|
// Disabled: nothing.
|
|
conf = string(Render(s, p, Extras{}).File(p.MainConfig()).Content)
|
|
if strings.Contains(conf, "statistics-channels") || strings.Contains(conf, "responselog") {
|
|
t.Errorf("stats disabled but present:\n%s", conf)
|
|
}
|
|
}
|
|
|
|
func TestStatsHooksMerged(t *testing.T) {
|
|
s := sampleState(t)
|
|
add := func(scope, name, value string) {
|
|
id := int64(10000 + len(s.Options))
|
|
s.Options[id] = &model.Option{ID: id, Scope: scope, Name: name, Value: value, Position: int(id)}
|
|
}
|
|
for _, o := range s.Options {
|
|
if o.Name == "logging" {
|
|
o.Value = `{ channel default_log { stderr; severity info; }; category default { default_log; }; category responses { default_log; }; }`
|
|
}
|
|
}
|
|
add(model.ScopeTopLevel, "statistics-channels", `{ inet 127.0.0.1 port 8080 allow { 127.0.0.1; }; }`)
|
|
add(model.ScopeOptions, "responselog", "no")
|
|
out := checkWithNamed(t, s, Extras{Stats: statsHooks()})
|
|
var conf string
|
|
for _, f := range out.Files {
|
|
if f.Kind == KindConfig {
|
|
conf = string(f.Content)
|
|
}
|
|
}
|
|
if strings.Count(conf, "logging {") != 1 || strings.Count(conf, "statistics-channels {") != 1 {
|
|
t.Errorf("statements duplicated instead of merged:\n%s", conf)
|
|
}
|
|
for _, want := range []string{"port 8080", "port 8058", "category responses { default_log; jarl_responses; };", "responselog no;"} {
|
|
if !strings.Contains(conf, want) {
|
|
t.Errorf("named.conf lacks %q:\n%s", want, conf)
|
|
}
|
|
}
|
|
if strings.Contains(conf, "responselog yes") {
|
|
t.Errorf("Jarl overrode the user's responselog:\n%s", conf)
|
|
}
|
|
}
|
|
|
|
func TestStatsHooksWithNamed(t *testing.T) {
|
|
checkWithNamed(t, sampleState(t), Extras{Stats: statsHooks()})
|
|
}
|