The Admin API provides runtime management and monitoring capabilities for the Lazy DNS server without requiring a restart. This document covers all available endpoints, configuration, and usage examples.
The Admin API is a separate HTTP server that runs alongside your main DNS servers. It provides endpoints for:
Enable the Admin API in your config.yaml:
admin:
enabled: true
addr: "127.0.0.1:8080"
| Option | Type | Default | Description |
|---|---|---|---|
enabled |
boolean | false |
Enable/disable the admin API |
addr |
string | 127.0.0.1:8080 |
Listen address and port |
You can override the admin configuration using environment variables:
# Enable the admin API
export ADMIN_ENABLED=true
# Set the listen address
export ADMIN_ADDR=0.0.0.0:8080
# Start the server
lazydns
Supported boolean values for ADMIN_ENABLED: true, 1, yes (case-insensitive)
admin:
enabled: true
addr: "127.0.0.1:8080"
admin:
enabled: true
addr: "192.168.1.100:8080"
admin:
enabled: true
addr: "0.0.0.0:8080"
Important: The Admin API has no built-in authentication. Anyone who can connect to the configured address can:
127.0.0.1:8080 (default) for single-machine setupslocation /api/ {
auth_basic "Admin API";
auth_basic_user_file /etc/nginx/.htpasswd;
proxy_pass http://127.0.0.1:8080;
}
server {
listen 8443 ssl http2;
server_name admin.example.com;
# SSL configuration
ssl_certificate /etc/ssl/certs/cert.pem;
ssl_certificate_key /etc/ssl/private/key.pem;
location / {
auth_basic "Admin API";
auth_basic_user_file /etc/nginx/.htpasswd;
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
Endpoint: GET /api/server/status
Returns basic information about the server’s operational status.
curl http://127.0.0.1:8080/api/server/status
{
"status": "running",
"version": "0.2.8"
}
200 OK - Server is operationalEndpoint: GET /api/cache/stats
Retrieves detailed statistics about cache performance and utilization.
curl http://127.0.0.1:8080/api/cache/stats
{
"size": 245,
"hits": 5800,
"misses": 1200,
"evictions": 42,
"hit_rate": 82.86
}
| Field | Type | Description |
|---|---|---|
size |
number | Current number of entries in the cache |
hits |
number | Total cache hits since server start |
misses |
number | Total cache misses since server start |
evictions |
number | Entries removed by LRU eviction policy |
hit_rate |
number | Cache hit rate as percentage (0-100) |
200 OK - Statistics retrieved successfully404 Not Found - Cache plugin not configured500 Internal Server Error - Plugin access failedThe hit rate tells you how often cached results are used:
hit_rate = (hits / (hits + misses)) * 100
Endpoint: POST /api/cache/control
Perform control operations on the cache system.
Clear Cache
curl -X POST http://127.0.0.1:8080/api/cache/control \
-H "Content-Type: application/json" \
-d '{"action": "clear"}'
{
"action": "clear"
}
{
"message": "Cache cleared successfully"
}
{
"error": "Cache not configured"
}
200 OK - Operation completed successfully400 Bad Request - Unknown action or invalid request404 Not Found - Cache not configured500 Internal Server Error - Plugin access failed| Action | Description |
|---|---|
clear |
Remove all entries from the cache |
Endpoint: POST /api/config/reload
Reload configuration from a file and validate it. This is a hot-reload operation that updates the in-memory configuration.
With Custom Path
curl -X POST http://127.0.0.1:8080/api/config/reload \
-H "Content-Type: application/json" \
-d '{"path": "/etc/lazydns/config.yaml"}'
With Default Path
curl -X POST http://127.0.0.1:8080/api/config/reload \
-H "Content-Type: application/json" \
-d '{"path": null}'
Or:
curl -X POST http://127.0.0.1:8080/api/config/reload \
-H "Content-Type: application/json" \
-d '{}'
{
"path": "/etc/lazydns/config.yaml"
}
{
"message": "Configuration reloaded from /etc/lazydns/config.yaml"
}
{
"error": "Configuration validation failed: invalid port number"
}
200 OK - Configuration reloaded and validated successfully400 Bad Request - Configuration validation failed500 Internal Server Error - Failed to load filecurl -s http://127.0.0.1:8080/api/server/status | jq .
curl -s http://127.0.0.1:8080/api/cache/stats | jq .
curl -s http://127.0.0.1:8080/api/cache/stats | jq .hit_rate
curl -s -X POST http://127.0.0.1:8080/api/cache/control \
-H "Content-Type: application/json" \
-d '{"action": "clear"}' | jq .
watch -n 5 'curl -s http://127.0.0.1:8080/api/cache/stats | jq .'
response=$(curl -s -w "\n%{http_code}" -X POST \
http://127.0.0.1:8080/api/config/reload \
-H "Content-Type: application/json" \
-d '{}')
body=$(echo "$response" | head -n -1)
code=$(echo "$response" | tail -n 1)
if [ "$code" = "200" ]; then
echo "Config reloaded successfully"
echo "$body" | jq .
else
echo "Config reload failed with code $code"
echo "$body" | jq .error
fi
| Code | Meaning | Common Causes |
|---|---|---|
200 |
OK | Request succeeded |
400 |
Bad Request | Invalid action, malformed JSON, validation error |
404 |
Not Found | Cache not configured, plugin not available |
500 |
Internal Server Error | Plugin downcast failed, file I/O errors |
Request fails?
├─ Network error → Retry with backoff
├─ 404 Not Found → Check configuration
├─ 400 Bad Request → Check request format and action
├─ 500 Internal Server Error → Check logs and plugin status
└─ 200 OK → Operation succeeded
The Admin API complements the separate Monitoring Server which provides:
/metricsFor production monitoring, use both:
admin:
enabled: true
addr: "127.0.0.1:8080"
monitoring:
enabled: true
addr: "127.0.0.1:9090"
global:
scrape_interval: 15s
scrape_configs:
- job_name: "lazydns"
static_configs:
- targets: ["localhost:9090"]
You can create dashboards using metrics from the monitoring server:
dns_queries_total - Total DNS queriesdns_responses_total - DNS responses by statusdns_query_duration_seconds - Query latency histogramdns_cache_hits_total - Cache hitsdns_cache_misses_total - Cache missesdns_cache_size - Current cache sizeFor real-time management, use Admin API endpoints directly in dashboard plugins.
The cache subsystem exposes the following Prometheus metrics when the crate is built with the metrics feature (enabled by default):
dns_cache_hits_total (counter): total number of cache hits recorded by the CachePlugin.dns_cache_misses_total (counter): total number of cache misses recorded by the CachePlugin.dns_cache_size (gauge): current number of entries in the cache (updated on insert/evict/clear).Notes:
CachePlugin implementation and are only available when the metrics feature is enabled.GET /api/cache/stats returns a snapshot (size, hits, misses, evictions, hit_rate). Use Prometheus metrics for time-series and alerting, and the Admin API for on-demand inspection or control.(sum(rate(dns_cache_hits_total[5m]))
/ (sum(rate(dns_cache_hits_total[5m])) + sum(rate(dns_cache_misses_total[5m]))))
- alert: LowCacheHitRate
expr: (sum(rate(dns_cache_hits_total[5m]))
/ (sum(rate(dns_cache_hits_total[5m])) + sum(rate(dns_cache_misses_total[5m])))) < 0.7
for: 5m
labels:
severity: warning
annotations:
summary: "Cache hit rate below 70%"
description: "Cache hit rate is below 70% for at least 5 minutes."
- alert: HighCacheSize
expr: max(dns_cache_size) > 10000
for: 10m
labels:
severity: warning
annotations:
summary: "Cache size exceeds threshold"
description: "Cache size is larger than expected (threshold = 10000)."
For quick, on-demand verification you can cross-check Prometheus metrics against the Admin API snapshot:
curl http://127.0.0.1:8080/api/cache/stats | jq .
# compare size/hits/misses with Prometheus values for sanity checks
- alert: LowCacheHitRate
expr: cache_hit_rate < 0.7
for: 5m
annotations:
summary: "Cache hit rate below 70%"
- alert: HighEvictions
expr: increase(cache_evictions_total[5m]) > 1000
for: 5m
annotations:
summary: "High number of cache evictions"
Problem: curl: (7) Failed to connect
Causes:
Solution:
# Verify enabled in config
grep -A 2 'admin:' config.yaml
# Check if port is listening
netstat -tlnp | grep 8080
# Check firewall
sudo ufw allow 8080
Problem: {"error": "Cache not configured"}
Causes:
Solution:
# Ensure cache is in plugin chain
plugins:
- type: cache
args:
size: 10000
Problem: DNS queries slow after clearing cache
Expected Behavior: This is normal. Cache clear forces upstream queries for all domains.
Solution:
curl http://127.0.0.1:8080/api/cache/statsProblem: Admin API hangs or times out
Diagnostic Steps:
# Test connectivity
timeout 5 curl -v http://127.0.0.1:8080/api/server/status
# Check server logs
tail -f /var/log/lazydns/main.log
# Check system resources
ps aux | grep lazydns
free -h
df -h
If you see mojibake (garbled characters) in responses, it’s likely a terminal encoding issue:
# Force UTF-8
export LANG=en_US.UTF-8
curl http://127.0.0.1:8080/api/cache/stats | jq .