Menu
Grafana Cloud

Apollo Server integration for Grafana Cloud

Apollo Server is an open-source, spec-compliant GraphQL server that’s compatible with any GraphQL client, including Apollo Client. It’s the best way to build a production-ready, self-documenting GraphQL API that can use data from any source. This integration enables the agent to send metrics to Grafana Cloud along with a useful default dashboard for visualization.

This integration includes 1 useful alert and 1 pre-built dashboard to help monitor and visualize Apollo Server metrics.

Before you begin

This integration monitors an Apollo Server app that exposes metrics through Apollo Prometheus Exporter.

To expose the metrics you need to instrument your Apollo server:

  • Install prom-client and @bmatei/apollo-prometheus-exporter
npm install prom-client @bmatei/apollo-prometheus-exporter
  • Create an instance of the plugin:
JavaScript
const app = express();
 
const prometheusExporterPlugin = createPrometheusExporterPlugin({ app });
 
  • Add the plugin to ApolloServer:
JavaScript
const server = new ApolloServer({
  plugins: [prometheusExporterPlugin]
});

For full instructions and possible setup options please follow the exporter guide.

Install Apollo Server integration for Grafana Cloud

  1. In your Grafana Cloud stack, click Connections in the left-hand menu.
  2. Find Apollo Server and click its tile to open the integration.
  3. Review the prerequisites in the Configuration Details tab and set up Grafana Agent to send Apollo Server metrics to your Grafana Cloud instance.
  4. Click Install to add this integration’s pre-built dashboard and alert to your Grafana Cloud instance, and you can start monitoring your Apollo Server setup.

Post-install configuration for the Apollo Server integration

After enabling the metrics generation, instruct Grafana Agent to scrape your Apollo Server nodes.

Apollo exposes a /metrics endpoint. To scrape it, add the provided snippet to your agent configuration file.

Make sure to change targets in the snippet according to your environment.

Configuration snippets for Grafana Agent

Below metrics.configs.scrape_configs, insert the following lines and change the URLs according to your environment:

yaml
    - job_name: integrations/apollo-server
      static_configs:
        - targets: ['localhost:4000']
      relabel_configs:
        - replacement: '<your-instance-name>'
          target_label: instance

Full example configuration for Grafana Agent

Refer to the following Grafana Agent configuration for a complete example that contains all the snippets used for the Apollo Server integration. This example also includes metrics that are sent to monitor your Grafana Agent instance.

yaml
integrations:
  prometheus_remote_write:
  - basic_auth:
      password: <your_prom_pass>
      username: <your_prom_user>
    url: <your_prom_url>
  agent:
    enabled: true
    relabel_configs:
    - action: replace
      source_labels:
      - agent_hostname
      target_label: instance
    - action: replace
      target_label: job
      replacement: "integrations/agent-check"
    metric_relabel_configs:
    - action: keep
      regex: (prometheus_target_sync_length_seconds_sum|prometheus_target_scrapes_.*|prometheus_target_interval.*|prometheus_sd_discovered_targets|agent_build.*|agent_wal_samples_appended_total|process_start_time_seconds)
      source_labels:
      - __name__
  # Add here any snippet that belongs to the `integrations` section.
  # For a correct indentation, paste snippets copied from Grafana Cloud at the beginning of the line.
logs:
  configs:
  - clients:
    - basic_auth:
        password: <your_loki_pass>
        username: <your_loki_user>
      url: <your_loki_url>
    name: integrations
    positions:
      filename: /tmp/positions.yaml
    scrape_configs:
      # Add here any snippet that belongs to the `logs.configs.scrape_configs` section.
      # For a correct indentation, paste snippets copied from Grafana Cloud at the beginning of the line.
metrics:
  configs:
  - name: integrations
    remote_write:
    - basic_auth:
        password: <your_prom_pass>
        username: <your_prom_user>
      url: <your_prom_url>
    scrape_configs:
      # Add here any snippet that belongs to the `metrics.configs.scrape_configs` section.
      # For a correct indentation, paste snippets copied from Grafana Cloud at the beginning of the line.
    - job_name: integrations/apollo-server
      static_configs:
        - targets: ['localhost:4000']
      relabel_configs:
        - replacement: '<your-instance-name>'
          target_label: instance
  global:
    scrape_interval: 60s
  wal_directory: /tmp/grafana-agent-wal

Dashboards

The Apollo Server integration installs the following dashboards in your Grafana Cloud instance to help monitor your system.

  • Apollo Server Overview

Overview

Overview

Alerts

The Apollo Server integration includes the following useful alerts:

AlertDescription
ApolloServerDownCritical: Apollo Server not up

Metrics

The most important metrics provided by the Apollo Server integration, which are used on the pre-built dashboard and Prometheus alert, are as follows:

  • apollo_query_duration_bucket
  • apollo_query_duration_count
  • apollo_query_duration_sum
  • apollo_query_failed
  • apollo_query_field_resolution_duration_count
  • apollo_query_field_resolution_duration_sum
  • apollo_query_started
  • apollo_server_starting
  • nodejs_external_memory_bytes
  • nodejs_heap_size_total_bytes
  • nodejs_heap_size_used_bytes
  • nodejs_version_info
  • process_cpu_seconds_total
  • process_cpu_system_seconds_total
  • process_cpu_user_seconds_total
  • process_resident_memory_bytes
  • process_start_time_seconds

Changelog

md
# 0.0.5 - August 2023

* New Filter Metrics option for configuring the Grafana Agent, which saves on metrics cost by dropping any metric not used by this integration. Beware that anything custom built using metrics that are not on the snippet will stop working.
* New hostname relabel option, which applies the instance name you write on the text box to the Grafana Agent configuration snippets, making it easier and less error prone to configure this mandatory label.

# 0.0.4 - June 2022

* Updated instructions to instrument Apollo server

# 0.0.3 - June 2022

* Update mixin to latest version:
  - Fixed labeling, and multi-select options for job and instance dashboard template variables
  - Added regex matching to job and instance promql matching

# 0.0.2 - October 2021

* Update all rate queries to use `$__rate_interval` so they respect the default resolution

# 0.0.1 - December 2020

* Initial release

Cost

By connecting your Apollo Server instance to Grafana Cloud, you might incur charges. To view information on the number of active series that your Grafana Cloud account uses for metrics included in each Cloud tier, see Active series and dpm usage and Cloud tier pricing.