Watchdog is a Go-based service that monitors OneBusAway (OBA) REST API servers. It exposes a comprehensive set of Prometheus metrics for monitoring:
- GTFS Static and GTFS-RT data integrity
- Vehicle telemetry
- Agency and stop coverage
- Overall operational health See the full list of metrics and interpretation guide here, and the client freshness contract in docs/FRESHNESS.md.
- Go 1.27.2+
Watchdog requires a configuration file (config.json) before running. Even placeholder data is necessary to start the service.
[
{
"server_name": "Test Server 1",
"oba_base_url": "https://test1.example.com",
"oba_api_key": "test-key-1",
"gtfs_static_feeds": ["https://gtfs1.example.com"],
"gtfs_rt_feeds": [{
"trip_update_url": "https://trip1.example.com",
"vehicle_position_url": "https://vehicle1.example.com",
"gtfs_rt_api_key": "api-key-1",
"gtfs_rt_api_value": "api-value-1"
}]
}
]The top-level agency_id decides what each entry observes: set it to track that agency. OBA API probes, static data, and realtime feed data are scoped to that agency; leave it out to track the server and every agency it serves. See Two observation modes below for both config shapes.
Each entry requires exactly one URL in gtfs_static_feeds and one source in gtfs_rt_feeds. The array field names remain unchanged, so existing single-feed v2 and legacy v1 configurations continue to work. A realtime source may include vehicle-position and trip-update URLs; Watchdog currently monitors vehicle positions.
Both feeds must already use the final IDs served by the OBA backend. A merged static feed may contain several agencies. Watchdog preserves IDs and does not merge sources or combine stops.
Vehicle-position vehicle IDs must be unique across the entire merged realtime feed, including across agencies. If two source agencies each use vehicle ID 101 for different vehicles, the upstream merger must give those vehicles distinct final IDs. A trip-update entity may reference the same vehicle ID as its vehicle-position entity; that reference is not a duplicate vehicle position.
To upgrade an existing multi-feed entry:
- Configure an external merger to produce the static and realtime artifacts consumed by your OBA backend.
- Replace
gtfs_static_feedswith the single merged static URL andgtfs_rt_feedswith the single merged realtime source, including its authentication fields. - Update any configured
agency_idto its final ID in the merged feed.
Multiple sources are rejected with a migration error. Watchdog does not keep the first source automatically. Invalid entries follow the existing config-loading policy and are excluded while valid entries continue to load. Check the dropped-server diagnostics and watchdog_configured_servers after upgrading.
Duplicate primary IDs in the static tables Watchdog consumes reject the new static snapshot, retain the last good snapshot, and produce a Sentry event and gtfs_static_feed_failure_info{reason="duplicate_id"}. Realtime duplicate entity IDs or vehicle-position IDs produce a Sentry event and gtfs_rt_feed_duplicate_id=1. Every entity carrying a conflicting ID is excluded, and the remaining entities are published as a successful fetch with gtfs_rt_feed_fetch_success=1. No duplicate winner is selected. Transport or decoding failures still preserve the cached realtime snapshot without processing it as a new observation.
- Copy or rename
config.json.template→config.json - Fill in your server values
- Run with:
go run ./cmd/watchdog/ --config-file path/to/config.jsonNote:
⚠️ The file must be namedconfig.jsonconfig.jsonis Git-ignored (to protect secrets)
- Prepare
config.jsonas above - Host it publicly (or on a private server)
- Run with:
go run ./cmd/watchdog/ --config-url http://example.com/config.jsonIf authentication is required, set:
export CONFIG_AUTH_USER="username"
export CONFIG_AUTH_PASS="password"There are two ways Watchdog can observe an OBA deployment. The choice is made per entry in config.json by whether you set agency_id — every other field (server_name, oba_base_url, oba_api_key, gtfs_static_feeds, gtfs_rt_feeds) is identical in both modes. Setting agency_id selects agency observation mode; agency_name must also be provided.
- Agency mode —
agency_idis set. Watchdog monitors only that one agency. - Server mode (recommended) —
agency_idis unset. Watchdog monitors the whole server and every agency it currently serves.
Observe a single agency — set agency_id (with its agency_name) on the entry. Watchdog uses that agency for agency-specific OBA API probes and retains only static and realtime data attributed to it:
{
"server_name": "Agency Example",
"agency_name": "Test Agency",
"agency_id": "agency-1",
"oba_base_url": "https://test1.example.com",
"oba_api_key": "test-key-1",
"gtfs_static_feeds": ["https://gtfs1.example.com"],
"gtfs_rt_feeds": [{
"trip_update_url": "https://trip1.example.com",
"vehicle_position_url": "https://vehicle1.example.com",
"gtfs_rt_api_key": "api-key-1",
"gtfs_rt_api_value": "api-value-1"
}]
}Observe the whole server — omit agency_id from the entry. Watchdog tracks the server and every agency it currently serves:
{
"server_name": "Server Example",
"oba_base_url": "https://test2.example.com",
"oba_api_key": "test-key-2",
"gtfs_static_feeds": ["https://gtfs2.example.com"],
"gtfs_rt_feeds": [{
"trip_update_url": "https://trip2.example.com",
"vehicle_position_url": "https://vehicle2.example.com",
"gtfs_rt_api_key": "api-key-2",
"gtfs_rt_api_value": "api-value-2"
}]
}| Agency mode | Server mode | |
|---|---|---|
agency_id |
set (paired with required agency_name) |
unset |
| Scope | one agency | whole OBA deployment |
| Agency set comes from | the config entry | each static feed's agency.txt, filtered by /api/where/metrics.json agency coverage |
| Typical source | hand-written config | OBACloud service discovery (one entry per OBA API server) |
Agency mode — agency_id is set. Watchdog monitors only that one agency; today's per-agency pipeline runs once per tick for that agency. agency_name is required (paired with agency_id).
Server mode — agency_id is absent. Watchdog probes /api/where/metrics.json every tick to learn which agencies are present in OBA's loaded static coverage, cross-references those agency IDs against the static feeds' agency.txt declarations, and runs the per-agency pipeline for every agency that has BOTH a static bundle AND is reported by OBA.
Multi-agency static feeds are accepted in server mode: one consolidated bundle pointer-shared across the serverKeys of every agency declared in its agency.txt. Agency mode instead stores an owned snapshot containing only the configured agency's routes, referenced services, stops, and parent stations. Feed-to-agency mapping metrics describe the agencies declared in the upstream artifact's agency.txt.
These metrics expose static agency coverage and source-feed mapping health:
gtfs_static_agency_reported_by_oba{agency_id, agency_name, server_name, server_url}— 1 if the agency has a static bundle AND is in/api/where/metrics.jsonentry.AgencyIDsin the current scrape; 0 otherwise.gtfs_static_feed_agency_mapping_info{feed_url, agency_id, agency_name, server_name, server_url}— always 1, with one series for each proven source-feed relationship. An explicit multi-agency feed produces one series per declared agency in server mode. Agency mode emits only its configured agency; a sole agency with omittedagency_idis associated with that configured agency as allowed by GTFS.gtfs_static_feed_agency_mapping_failure{feed_url, server_name, server_url, reason}— always 1 when a parsed feed cannot be fully mapped.reasonis one ofmissing_agency,ambiguous_agency, orunknown_agency.
In agency mode the RT fetch resolves each vehicle by route or trip and stores only vehicles attributed to the configured agency_id. Foreign or conflicting vehicles are dropped before the metric pass. Vehicles that cannot be resolved are kept when the static feed names only the configured agency, so quality checks can still report them. Until the first static snapshot loads, the realtime feed is stored unfiltered.
In server mode the single upstream-merged realtime feed can carry vehicles from several agencies. Watchdog attributes each vehicle using the route and trip IDs in the static feed, then checks that OBA reports the agency as live. Unknown IDs, conflicting route/trip ownership, and agencies absent from OBA coverage remain unattributed. Duplicate static primary IDs reject the new snapshot before publication.
This is a deliberate breaking change to the existing v2 format. Existing v2 entries without server_name become invalid — operators must add the field. The legacy v1 array-of-flat-objects format continues to work: id (int) is still ignored, name is repurposed as server_name, and a v1 entry with agency_id populates agency_name from name so the entry remains agency-scoped.
Watchdog used to accept a flat, single-server config schema. Legacy (v1) configs are still supported: they're silently converted to the current array-based schema (v2) at load time, so upgrading doesn't require changing your config or interrupt monitoring.
When a v1 entry is loaded, Watchdog maps it like this:
name→server_name; whenagency_idis present, it also populatesagency_namegtfs_url→ a single-entrygtfs_static_feedsvehicle_position_url/trip_update_url→ the matchinggtfs_rt_feedsentriesgtfs_rt_api_key/gtfs_rt_api_value→ the per-feed auth fieldsid→ ignored
One caveat: v1 and v2 fields can't be mixed in the same entry. If an entry contains both schemas (e.g. a legacy gtfs_url alongside gtfs_static_feeds), it's rejected and reported to Sentry. Each entry must use one schema or the other.
Both v1 and v2 configurations accept one static feed and one realtime source per entry. See Feed contract and migration when upgrading a v2 entry that previously listed multiple feeds.
- Fetch Interval → default
30s(--fetch-interval <seconds>) - Environment →
development(default),staging,production(--env <value>) - Port → default
4000(--port <number>)
9090 and Grafana on 3000. Don’t use those ports.
- Sentry DSN
export SENTRY_DSN="your_sentry_dsn"- Config Auth (for remote configs)
export CONFIG_AUTH_USER="username"
export CONFIG_AUTH_PASS="password"- Investigation database (optional)
export DATABASE_URL="postgres://user:password@host:5432/watchdog?sslmode=require"When DATABASE_URL is set, Watchdog connects to PostgreSQL at startup and applies any pending schema migrations. This database will hold durable investigation history (ADR 0001, schema). It is optional: if DATABASE_URL is unset, or the database is unreachable at startup, Watchdog logs it and keeps collecting and exporting Prometheus metrics without it. Docker Compose starts a local PostgreSQL and sets DATABASE_URL for you.
- Investigation API token (optional)
export INVESTIGATION_API_TOKEN="$(openssl rand -hex 32)"
export INVESTIGATION_API_TOKEN_NEXT="" # set only while rotatingThe Investigation API shows which stops, trips and vehicles had problems and when, so every request must send Authorization: Bearer <token>. A missing or wrong token gets 401. Watchdog accepts INVESTIGATION_API_TOKEN and, when set, INVESTIGATION_API_TOKEN_NEXT. When INVESTIGATION_API_TOKEN is unset, the API is disabled: its routes return 404 and Watchdog logs that at startup. Setting only INVESTIGATION_API_TOKEN_NEXT also leaves the API disabled and logs an error. Watchdog never logs the tokens.
To rotate the token without downtime:
- Set
INVESTIGATION_API_TOKEN_NEXTto the new token and restart Watchdog. Both tokens now work. - Update the client to send the new token.
- Move the new token to
INVESTIGATION_API_TOKEN, clearINVESTIGATION_API_TOKEN_NEXT, and restart Watchdog. The old token stops working.
It may take a few minutes for Watchdog to start exposing data to Prometheus, since initial setup includes tasks such as downloading the GTFS bundle.
Run Watchdog with Prometheus + Grafana:
docker compose up --buildServices:
- Watchdog →
4000 - Prometheus →
9090 - Grafana →
3000
Stop services:
docker compose downRestart services:
docker compose restartGrafana auto-loads a Go runtime dashboard. Prometheus is pre-configured to scrape Watchdog.
See Endpoints to access metrics, health checks, Grafana, and Prometheus.
go run ./cmd/watchdog/ --config-file path/to/config.jsongo run ./cmd/watchdog/ \
--config-url http://example.com/config.jsonSee Endpoints to access metrics and health checks.
docker build -t watchdog .docker run -d \
--name watchdog \
-v ./config.json:/app/config.json \
-p 4000:4000 \
watchdog \
--config-file /app/config.jsondocker run -d \
--name watchdog \
-e CONFIG_AUTH_USER=admin \
-e CONFIG_AUTH_PASS=password \
-p 4000:4000 \
watchdog \
--config-url http://example.com/config.jsonSee Endpoints to access metrics and health checks.
During development (using localhost):
- Watchdog Metrics: http://localhost:4000/metrics
- Watchdog Health Check: http://localhost:4000/v1/healthcheck
- Grafana: http://localhost:3000/login → default user/pass:
admin/admin - Prometheus Targets: http://localhost:9090/targets
- Prometheus Query: http://localhost:9090/query
During production (replace <server-ip-or-domain>):
- Watchdog Metrics:
http://<server-ip-or-domain>:4000/metrics - Watchdog Health Check:
http://<server-ip-or-domain>:4000/v1/healthcheck - Grafana:
http://<server-ip-or-domain>:3000/login - Prometheus Targets:
http://<server-ip-or-domain>:9090/targets - Prometheus Query:
http://<server-ip-or-domain>:9090/query
go test ./...The tests in internal/db apply the migrations and check the schema's constraints against a real PostgreSQL. They skip unless WATCHDOG_TEST_DATABASE_URL is set; each test creates and drops its own schema in that database.
WATCHDOG_TEST_DATABASE_URL="postgres://watchdog:watchdog@localhost:5432/watchdog?sslmode=disable" make test-dbAfter changing a query in internal/db/queries or adding a migration, regenerate the typed Go code with make sqlc.
- Copy
integration_config.json.template→integration_config.json - Fill in OBA server values
- Run:
go test -tags=integration ./internal/integration \
-integration-config path/to/integration_config.jsonNote:
⚠️ the file must be namedintegration_config.json- It’s Git-ignored for safety
Refer to CONTRIBUTING.md for detailed contribution guidelines.