Observability Internals
This page documents what the server exposes for monitoring: the Prometheus metrics registry (every metric, its type, labels and where it is recorded), log output and diagnostic environment variables, the health and status endpoints, the slow-query log, and what the monitoring configurations shipped in deploy/ actually scrape. Operator-facing guidance is in Operations; start-up and the memory log are in Server Runtime; per-connection accounting is in Connection Handling.
Metrics registry
Metrics use the prometheus crate (0.14) with a custom Registry named REGISTRY. Each metric is a lazy_static global. init_metrics registers all 23 metrics, ignores "already registered" errors, and logs at info (source: src/observability/metrics.rs, REGISTRY, init_metrics). export_metrics encodes the registry with TextEncoder in the Prometheus text format (source: src/observability/metrics.rs, export_metrics).
Only the custom registry is exported. No process collector is registered, so process_resident_memory_bytes, process_cpu_seconds_total and the other process_* series are not emitted (source: src/observability/metrics.rs, init_metrics).
Tests: test_init_metrics, test_export_metrics, test_query_timer, test_connection_tracker (source: src/observability/metrics.rs, tests).
All metrics
| Name | Type | Labels | Buckets (seconds) |
|---|---|---|---|
synergydb_connections_active |
GaugeVec | protocol |
|
synergydb_connections_total |
CounterVec | protocol |
|
synergydb_queries_total |
CounterVec |
language, status
|
|
synergydb_query_duration_seconds |
HistogramVec | language |
0.001, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10 |
synergydb_rows_returned_total |
Counter | ||
synergydb_rows_affected_total |
Counter | ||
synergydb_memtable_size_bytes |
Gauge | ||
synergydb_immutable_memtables |
Gauge | ||
synergydb_sst_files_total |
GaugeVec | level |
|
synergydb_compactions_total |
Counter | ||
synergydb_compaction_duration_seconds |
Histogram | 0.1, 0.5, 1, 5, 10, 30, 60, 300 | |
synergydb_bytes_written_total |
Counter | ||
synergydb_bytes_read_total |
Counter | ||
synergydb_transactions_active |
Gauge | ||
synergydb_transactions_committed_total |
Counter | ||
synergydb_transactions_aborted_total |
Counter | ||
synergydb_deadlocks_detected_total |
Counter | ||
synergydb_index_searches_total |
CounterVec | index_type |
|
synergydb_vector_searches_total |
Counter | ||
synergydb_vector_search_duration_seconds |
Histogram | 0.001, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1 | |
synergydb_auth_attempts_total |
CounterVec |
method, status
|
|
synergydb_replication_lag_seconds |
GaugeVec | replica |
|
synergydb_errors_total |
CounterVec | type |
Source: src/observability/metrics.rs, lazy_static! block.
Where each metric is recorded
| Metric | Recorded by | Notes |
|---|---|---|
connections_active, connections_total
|
ConnectionTracker::new increments both; Drop decrements active |
Labels in the next table |
queries_total, query_duration_seconds
|
QueryTimer::success / QueryTimer::failure
|
Only the PostgreSQL simple and extended query paths create a QueryTimer, always with language="sql". status is success or error. Other wires record no query metrics. |
rows_returned_total |
QueryTimer::success(rows) |
PostgreSQL only; many PostgreSQL paths pass 0 |
errors_total |
QueryTimer::failure(type) |
type values used: query_error, parse_error, no_storage, copy_error; PostgreSQL only |
rows_affected_total |
record_rows_affected |
PostgreSQL only |
compactions_total, compaction_duration_seconds, bytes_read_total, bytes_written_total
|
record_compaction in compaction |
Bytes count compaction input and output only, not client reads or writes |
memtable_size_bytes, immutable_memtables, sst_files_total
|
update_storage_metrics |
Called only inside the /api/v1/status handler, so these gauges change only when that endpoint is requested |
transactions_active, transactions_committed_total, transactions_aborted_total
|
MVCC transaction manager | |
deadlocks_detected_total |
record_deadlock in the lock manager |
|
index_searches_total |
record_index_search |
No callers; never incremented |
vector_searches_total, vector_search_duration_seconds
|
record_vector_search |
No callers |
auth_attempts_total |
record_auth_attempt |
No callers |
replication_lag_seconds |
REPLICATION_LAG |
Never set |
Source: src/observability/metrics.rs, QueryTimer, ConnectionTracker, record_*, update_storage_metrics; src/protocol/postgres/mod.rs, QueryTimer::new("sql") call sites; src/storage/compaction.rs, record_compaction; src/transaction/mvcc.rs; src/transaction/lock.rs, record_deadlock; src/protocol/http/routes.rs, server_status. Not verified: apart from the unit tests above, no test asserts that any production path changes a metric.
protocol label values
| Label | Where the tracker is created |
|---|---|
postgres, mysql, mongodb, redis, dynamodb, couchdb, influxdb, snowflake, oracle, memcached, cassandra, clickhouse (native only), mssql, prometheus
|
once per accepted connection |
sqlite |
per connection on the SQLite wire (protocol.rs); Hrana connections are not tracked |
http |
per HTTP request, by the track_connection middleware, not per TCP connection |
grpc |
once for the whole gRPC server when it starts, plus once per request in the gRPC service |
Bolt, Elasticsearch, Kafka, Schema Registry, S3, Gremlin, Arrow Flight and ClickHouse HTTP create no tracker, so their connections do not appear (source: each wire's start under src/protocol/; src/protocol/http/routes.rs, track_connection; src/protocol/grpc/mod.rs, start). The per-wire table in Connection Handling lists the label beside each accept loop.
get_active_connections and get_total_connections sum a fixed list of labels: postgres, mysql, mongodb, bolt, http, grpc, cassandra, clickhouse, dynamodb, elasticsearch, mssql, oracle, redis, snowflake, sqlite. memcached, couchdb, influxdb and prometheus are recorded but left out of these sums; bolt and elasticsearch are summed but never recorded (source: src/observability/metrics.rs, get_active_connections, get_total_connections).
get_allocated_memory_mb reads resident pages from /proc/self/statm and multiplies by 4 KiB, assuming that page size. It returns 0 on non-Linux systems (source: src/observability/metrics.rs, get_allocated_memory_mb).
HTTP endpoints
All of these are on the HTTP port (default 8080). See the configuration reference for http_port and the metrics token key.
Unauthenticated health routes
| Path | Handler | Response |
|---|---|---|
/health, /api/health, /api/v1/health
|
health_check |
Always HTTP 200. JSON {status, version, uptime_seconds, checks: {storage, query_engine, memory}} where status is healthy, degraded or unhealthy. Memory is degraded above 8192 MB of resident memory. |
/livez |
liveness_probe |
200 {"status":"ok"}
|
/readyz |
readiness_probe |
200 when ready; 503 not_ready when a storage probe read fails with an error other than not-found, or no query engine is attached |
/cluster/role |
cluster_role |
Always 200 {role, writable, leader}
|
/cluster/writable |
cluster_writable |
200 when this node accepts writes, 503 when read-only |
Source: src/protocol/http/routes.rs, health_check, liveness_probe, readiness_probe, cluster_role, cluster_writable. Because /health returns 200 even when status is unhealthy, a load balancer that checks only the status code does not see failures there; /readyz returns 503. Tests: metrics_token_keeps_health_routes_public (asserts /health 200, /livez 200, /readyz 503 without storage), test_health_paths_are_routed_without_auth (source: src/protocol/http/routes.rs, tests). Cluster roles are described in Cluster RPC and Routing.
/metrics and /api/v1/status
Both routes are gated by diagnostics_authorized:
| Metrics token configured | Request | Result |
|---|---|---|
| yes |
Authorization: Bearer <token> matching |
allowed; the SHA-256 of the presented token is compared in constant time with the subtle crate |
| yes | header missing or wrong | 401 with WWW-Authenticate: Bearer
|
| no | peer is loopback | allowed |
| no | no peer address (in-process request) | allowed |
| no | dev insecure-auth flag set | allowed |
| no | any other peer | 401 |
Source: src/protocol/http/routes.rs, diagnostics_authorized. /metrics (prometheus_metrics) returns export_metrics() with Content-Type: text/plain; version=0.0.4; charset=utf-8. Tests: metrics_without_configured_token_are_public, metrics_with_token_reject_missing_header, metrics_with_token_reject_wrong_token, metrics_with_token_accept_correct_token. The test name metrics_without_configured_token_are_public runs as an in-process request, which the no-peer rule allows.
When no token is configured, HTTP start logs the warning /metrics is unauthenticated; configure a metrics token to protect it (source: src/protocol/http/mod.rs, HttpHandler::start). Without a token the endpoint is reachable only from loopback, so the warning overstates the exposure.
/api/v1/status (server_status) returns uptime, version, connection counts, memory.used_bytes, and a storage block where disk_bytes is estimated as memtable size plus SST file count times 64 MiB, and total_rows is the storage sequence number, not a row count. It also calls update_storage_metrics (source: src/protocol/http/routes.rs, server_status).
Authenticated metric-style routes
| Route | Handler | What it returns |
|---|---|---|
/api/v1/system/metrics |
get_system_metrics |
Connection counts for six protocols, CPU fixed at 0, disk_used and write IOPS taken from synergydb_bytes_written_total (compaction bytes) |
/api/v1/databases/:name/metrics |
get_database_metrics |
cache_hit_ratio hard-coded to 0.95; connections from the postgres label only |
/api/v1/billing/usage, /usage/:user_id, /summary/:user_id, /history/:user_id
|
get_usage and related |
Reads USAGE_METER, which nothing feeds: meter_query, meter_transfer and meter_connection have no callers |
Source: src/protocol/http/routes.rs, get_system_metrics, get_database_metrics, get_billing_summary; src/observability/metering.rs. Not wired: the billing meter. Not verified: no tests for these handlers' values.
Logging
main installs a tracing_subscriber::fmt subscriber with an EnvFilter built from RUST_LOG, defaulting to warn, with targets shown, writing to stderr. It uses try_init, so a second initialisation is ignored (source: src/main.rs, main). There is no JSON formatter, no file appender and no log rotation in the server; output goes wherever the process's stderr goes.
Diagnostic environment variables
| Variable | Effect | Read in |
|---|---|---|
RUST_LOG |
EnvFilter directives; default warn
|
src/main.rs |
SYNERGYDB_LOG_QUERIES |
Logs each statement at warn with target querylog, prefix QUERYLOG, first 400 characters, verbatim (literals and any secrets in the SQL included) |
src/query/engine.rs |
SYNERGYDB_DEBUG_LOG |
Appends statements to /tmp/debug_queries.log; one site writes debug_queries.log in the working directory |
src/query/engine.rs |
SYNERGYDB_ORACLE_TRACE |
Oracle TNS/TTC packet trace |
src/protocol/oracle/mod.rs, src/protocol/oracle/plsql.rs
|
SYNERGYDB_TDS_TRACE |
Logs T-SQL statements after translation | src/protocol/mssql/tsql.rs |
SYNERGYDB_DEBUG_TYPED_AGG |
Explains why a typed aggregate fell back | src/query/engine.rs |
SYNERGYDB_MEMORY_LOG_SECS |
Periodic memory log; see Server Runtime |
src/main.rs, src/server/mod.rs, src/heap.rs
|
SYNERGYDB_SLOW_QUERY_US, SYNERGYDB_SLOW_QUERY_LOG
|
Slow-query log, below | src/query/slow_log.rs |
Not verified: none of these variables has a test.
Slow-query log
The slow-query log is off unless SYNERGYDB_SLOW_QUERY_US parses as an unsigned integer (microseconds). The file is SYNERGYDB_SLOW_QUERY_LOG, default /tmp/synergydb-slow.log, opened with create and append. If the file cannot be opened, the log silently records nothing. There is no rotation. The configuration is read once per process (source: src/query/slow_log.rs, config).
The only caller is QueryEngine::execute_with_timeout, so every wire that runs statements through the query engine is covered. The who field is <user>@<database> <client addr>, using - for a missing user or address (source: src/query/slow_log.rs, begin; src/query/engine.rs, execute_with_timeout).
Line format
<RFC 3339 UTC time, ms>\t<user>@<database> <client addr>\t<elapsed µs>\t<state>\t<sql>
Newlines in the SQL become spaces, and the SQL is cut at 4000 bytes on a character boundary (source: src/query/slow_log.rs, write, one_line).
state |
When |
|---|---|
ok / err
|
Statement finished over the threshold. When heap counting is on, followed by (stmt peak Y MB, alloc Z MB). |
running |
Written by the watcher for a statement still running past the threshold, then repeated every 60 s (REPEAT), with live heap figures when heap counting is on |
Source: src/query/slow_log.rs, Timer, mem_note, REPEAT.
Watcher thread
When the threshold is greater than zero, a thread named slow-query-watch starts. It wakes every threshold / 4, clamped to between 200 ms and 5 s, and writes running lines (source: src/query/slow_log.rs, spawn_watcher). A threshold of 0 logs every finished statement and starts no watcher. top_by_memory(3) lists the three running statements using the most memory; the server memory log uses it (source: src/query/slow_log.rs, top_by_memory).
Test: cuts_before_a_multibyte_char (source: src/query/slow_log.rs, slow_log_truncate_tests). Not verified: threshold handling, the watcher and the file format have no test.
Modules present but not wired
| Module | What it contains | Status |
|---|---|---|
src/observability/tracing.rs |
OpenTelemetry OTLP exporter: init_tracing, shutdown_tracing, OtelConfig (endpoint http://localhost:4317, sampling ratio 0.1, timeout 10 s, enabled false), macros db_span!, query_span!, storage_span!
|
Not wired: no callers of init_tracing or the macros. A comment says every query opens a query_span!; no such call exists in the query engine. Crates: opentelemetry, opentelemetry_sdk, opentelemetry-otlp, tracing-opentelemetry. |
src/observability/resources.rs |
ResourceManager: 100 connections per protocol, 500 total, 1000 transactions, 100 MB minimum free disk, 1 GB WAL, 80% pressure threshold |
Not wired: check_connection_allowed and the other checks have no callers |
src/observability/lineage.rs |
Data lineage tracking | Not wired |
src/observability/metering.rs |
USAGE_METER for billing routes |
Not wired: never fed |
Source: the files named.
Shipped monitoring configuration
deploy/monitoring/prometheus.yml
| Setting | Value |
|---|---|
| Scrape and evaluation interval | 15 s |
| External label | cluster: synergydb-prod |
| Alertmanager | one static target on port 9093 |
| Rule files | /etc/prometheus/rules/*.yml |
Job synergydb
|
static target on port 9091, with an instance relabel. A comment in the file says to scrape /metrics on the HTTP port 8080 with a bearer token instead. |
Job synergydb-swarm
|
Docker Swarm task discovery for service synergydb_db, keeping running tasks |
Job synergydb-k8s
|
Kubernetes pod discovery in namespace synergydb, using prometheus.io/* annotations |
Source: deploy/monitoring/prometheus.yml.
Port 9091 is the default prometheus_port, the Prometheus remote-storage wire. That wire serves /-/healthy, /-/ready, remote write and read, and PromQL query routes; it has no /metrics route, so a scrape of :9091/metrics gets an authentication error or 404, not the server's metrics (source: src/config.rs, prometheus_port; src/protocol/prometheus/mod.rs, route_request). The configuration reference also says /metrics is not served there. To scrape the registry, target /metrics on the HTTP port with a bearer token, or from loopback.
Kubernetes, Helm and Swarm
| File | Scrape setting |
|---|---|
deploy/kubernetes/statefulset.yaml |
Annotations for port 9091, path /metrics; container port named metrics on 9091 |
deploy/helm/synergydb/values.yaml |
metrics.enabled: true, metrics.port: 9091; serviceMonitor.enabled: false, interval 30s, scrape timeout 10s |
deploy/helm/synergydb/templates/servicemonitor.yaml |
Path /metrics on port metrics
|
deploy/swarm/synergydb-stack.yml |
A metrics service running synergydb-cli --metrics-export 0.0.0.0:9091
|
Source: the files named. All of these target port 9091, which has the problem described above. synergydb-cli has no --metrics-export option and ignores its arguments (see CLI Reference), so the Swarm metrics service starts an interactive prompt that exits at end of input.
Alert rules (deploy/monitoring/alerts.yml)
| Alert | Expression (summarised) | For | Series exists in code |
|---|---|---|---|
SynergyDBDown |
up == 0 |
1m |
up is produced by Prometheus |
HighMemory |
process_resident_memory_bytes > 7 GiB |
5m | no |
HighCPU |
rate(process_cpu_seconds_total) > 0.8 |
10m | no |
DiskSpaceLow / DiskSpaceCritical
|
synergydb_storage_disk_usage_bytes / synergydb_storage_disk_total_bytes > 0.8 / > 0.95 |
5m / 1m | no |
ConnectionPoolExhausted |
synergydb_connections_active / synergydb_connections_max > 0.9 |
5m |
connections_max does not exist |
HighQueryLatency |
p99 of synergydb_query_duration_seconds > 1 s |
10m | yes (PostgreSQL only) |
ReplicationLag |
synergydb_cluster_replication_lag_seconds > 10 |
5m | no; code has synergydb_replication_lag_seconds, never set |
ClusterMemberDown |
synergydb_cluster_members_healthy < synergydb_cluster_members_total |
2m | no |
Source: deploy/monitoring/alerts.yml; src/observability/metrics.rs. Only SynergyDBDown and HighQueryLatency can fire against the current code.
Grafana dashboard (deploy/monitoring/grafana-dashboard.json)
Panels query up, synergydb_query_duration_seconds (p50, p95, p99), process_resident_memory_bytes, process_cpu_seconds_total, synergydb_queries_total{type=~"select|insert|update|delete"}, sum(synergydb_queries_total), sum(synergydb_connections_active), and the disk usage and total series (source: deploy/monitoring/grafana-dashboard.json). The type label does not exist on synergydb_queries_total (its labels are language and status), so the per-statement-type panel is empty, as are the process and disk panels.
Sample server configs
docker/synergydb.prod.toml states that metrics are on /metrics on the HTTP port. docker/synergydb.toml and docker/synergydb.allwires.toml carry a commented-out metrics token key; the all-wires file also sets prometheus_port = 9091 (source: the files named).