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.

Configuration snippets for Grafana Alloy

Simple mode

These snippets are configured to scrape a single Apollo Server instance running locally with default ports.

First, manually copy and append the following snippets into your alloy configuration file.

Metrics snippets

alloy
discovery.relabel "metrics_integrations_integrations_apollo_server" {
	targets = [{
		__address__ = "localhost:4000",
	}]

	rule {
		target_label = "instance"
		replacement  = constants.hostname
	}
}

prometheus.scrape "metrics_integrations_integrations_apollo_server" {
	targets    = discovery.relabel.metrics_integrations_integrations_apollo_server.output
	forward_to = [prometheus.remote_write.metrics_service.receiver]
	job_name   = "integrations/apollo-server"
}

Advanced mode

The following snippets provide examples to guide you through the configuration process.

To instruct Grafana Alloy to scrape your Apollo Server instances, manually copy and append the snippets to your alloy configuration file, then follow subsequent instructions.

Advanced metrics snippets

alloy
discovery.relabel "metrics_integrations_integrations_apollo_server" {
	targets = [{
		__address__ = "localhost:4000",
	}]

	rule {
		target_label = "instance"
		replacement  = constants.hostname
	}
}

prometheus.scrape "metrics_integrations_integrations_apollo_server" {
	targets    = discovery.relabel.metrics_integrations_integrations_apollo_server.output
	forward_to = [prometheus.remote_write.metrics_service.receiver]
	job_name   = "integrations/apollo-server"
}

To monitor your Apollo Server instance, you must use a discovery.relabel component to discover your Apollo Server Prometheus endpoint and apply appropriate labels, followed by a prometheus.scrape component to scrape it.

Configure the following properties within each discovery.relabel component:

  • __address__: The address to your Apollo Server Prometheus metrics endpoint.
  • instance label: constants.hostname sets the instance label to your Grafana Alloy server hostname. If that is not suitable, change it to a value uniquely identifies this Apollo Server instance.

If you have multiple Apollo Server servers to scrape, configure one discovery.relabel for each and scrape them by including each under targets within the prometheus.scrape component.

Grafana Agent static configuration (deprecated)

The following section shows configuration for running Grafana Agent in static mode which is deprecated. You should use Grafana Alloy for all new deployments.

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
  • up

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.