Newansage v0.4.0 is out
Guides / Metrics and API

Metrics and API

Scrape ansage with Prometheus, alert on sessions and drains, and feed a dashboard.

metrics_listen = "127.0.0.1:9179"
PathWhat
/metricsPrometheus metrics, see Metrics
/api/summarythe same as ansage show summary --json
/api/peersall peers, or one with ?peer=
/api/rib?prefix=, or ?family=ipv4&limit=N
/api/fibkernel routes and next hops
/api/eventsServer-Sent Events: summary at once and every 5 s, peer on every session change

The JSON is the same as ansage show ... --json; details in the HTTP API.

Scrape with Prometheus

prometheus.yml
scrape_configs:
  - job_name: ansage
    static_configs:
      - targets: ["srv-a.example.net:9179", "srv-b.example.net:9179"]

For a Prometheus on another host, bind metrics_listen to an address on your management network (e.g. "10.255.0.21:9179"), not 0.0.0.0.

Alerts

ansage.rules.yml
groups:
  - name: ansage
    rules:
      - alert: AnsageSessionDown
        expr: ansage_peer_up == 0 and ansage_peer_disabled == 0
        for: 2m
        annotations:
          summary: "{{ $labels.instance }}: BGP session to {{ $labels.neighbor }} is down"

      - alert: AnsageNotAnnouncing
        expr: ansage_peer_up == 1 and on (instance, neighbor) sum by (instance, neighbor) (ansage_peer_prefixes_advertised) == 0
        for: 5m
        annotations:
          summary: "{{ $labels.instance }} announces nothing to {{ $labels.neighbor }}"

      - alert: AnsageDrainedTooLong
        expr: ansage_drained == 1
        for: 2h
        annotations:
          summary: "{{ $labels.instance }} has been drained for 2 hours (ansage undrain?)"

      - alert: AnsageKernelErrors
        expr: increase(ansage_fib_errors_total[10m]) > 0
        annotations:
          summary: "{{ $labels.instance }}: the kernel refused route changes ({{ $labels.reason }})"

      - alert: AnsageDown
        expr: up{job="ansage"} == 0
        for: 1m

AnsageNotAnnouncing catches a session that is up but carries none of our prefixes: a runtime ansage withdraw by a health check, or a missing next hop. Drop it if your health checks withdraw on purpose.

Useful queries

QuestionPromQL
Sessions up per serversum by (instance) (ansage_peer_up)
Flapping sessionsincrease(ansage_peer_established_total[1h]) > 3
How long in the current statetime() - ansage_peer_state_since_seconds
Routes learnedsum by (instance, family) (ansage_peer_prefixes_received)
Graceful Restart negotiated where configuredansage_peer_graceful_restart_enabled - ansage_peer_graceful_restart (1 = the neighbor does not do it)

Quick checks with curl

curl -s localhost:9179/metrics | grep '^ansage_peer_up'
curl -s localhost:9179/api/summary | jq '.peers[] | {address, state}'
curl -N localhost:9179/api/events        # live, Ctrl-C to stop

Esc to close