Collecting metrics in the Apollo Router
The Apollo Router provides built-in support for metrics collection via Prometheus and OpenTelemetry Collector.
Using Prometheus
You can use Prometheus and Grafana to collect metrics and visualize the router metrics.
router.yaml
telemetry:metrics:prometheus:# By setting this endpoint you enable the prometheus exporter# All our endpoints exposed by plugins are namespaced by the name of the plugin# Then to access to this prometheus endpoint, the full url path will be `/plugins/apollo.telemetry/prometheus`enabled: true
Assuming you are running locally:
- Run a query against the router.
- Navigate to http://localhost:4000/plugins/apollo.telemetry/prometheus to see something like:
# HELP http_request_duration_seconds Total number of HTTP requests made.# TYPE http_request_duration_seconds histogramhttp_request_duration_seconds_bucket{le="0.5"} 1http_request_duration_seconds_bucket{le="0.9"} 1---SNIP---
Note that if you have not run a query against the router you will see a blank page as no metrics will have been generated yet!
Here is the list of available metrics you'll have using Prometheus:
- HTTP router request duration
- HTTP request duration by subgraph
- Total number of HTTP requests by HTTP Status
- Total number of HTTP requests in error
Using OpenTelemetry Collector
You may send metrics to OpenTelemetry Collector for processing and eporting metrics.
router.yaml
telemetry:metrics:otlp:# Either 'default' or a URLendpoint: default# Optional protocol. Only grpc is supported currently.# Setting to http will result in configuration failure.protocol: grpc# Optional Grpc configurationgrpc:domain_name: "my.domain"key:file: ""# env: ""ca:file: ""# env: ""cert:file: ""# env: ""metadata:foo: bar# Optional timeout in humatime formtimeout: 2s