1.0.5 • Published 2 years ago

@subosito/apollo-prometheus-exporter v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Apollo Prometheus Exporter

GitHub Workflow Status npm

Plugin for Apollo Server to export metrics in Prometheus format.

It uses prom-client under the hood the export the metrics.

Metrics

NameDescriptionType
apollo_server_startingThe amount of times Apollo Server is starting.Counter
apollo_server_closingThe amount of times Apollo Server is closing.Counter
apollo_query_startedThe amount of GraphQL queries received by Apollo Server.Counter
apollo_query_failedThe amount of GraphQL queries which failed.Counter
apollo_query_parse_startedThe amount of GraphQL queries for which parsing has failed.Counter
apollo_query_parse_failedThe amount of GraphQL queries for which validation has started.Counter
apollo_query_validation_startedThe amount of GraphQL queries for which validation has failed.Counter
apollo_query_validation_failedThe amount of GraphQL queries which could be resolved.Counter
apollo_query_resolvedThe amount of GraphQL queries for which execution has started.Counter
apollo_query_execution_startedThe amount of GraphQL queries for which execution has failed.Counter
apollo_query_execution_failedThe amount of GraphQL queries that failed.Counter
apollo_query_durationThe total duration of GraphQL queries.Histogram
apollo_query_field_resolution_durationThe total duration for resolving fields.Histogram

For default metrics, please refer to prom-client default metrics.

Usage

  1. Install prom-client and @bmatei/apollo-prometheus-exporter

    npm install prom-client @bmatei/apollo-prometheus-exporter
  2. Create an instance of the plugin

    const app = express();
    
    const prometheusExporterPlugin = createPrometheusExporterPlugin({ app });
  3. Add the plugin to ApolloServer and, optionally, enable tracing

    const server = new ApolloServer({
      plugins: [prometheusExporterPlugin],
      tracing: true
    });

If tracing is not enabled in ApolloServer, some metrics like apollo_query_duration and apollo_query_field_resolution_duration won't be available.

For a complete working example, please have a look over the example project in this repository.

Options

NameDescriptionTypeDefault Value
appExpress instance. For the moment it is used for defining the metrics endpoint. It is mandatory unless metricsEndpoint is set to false.Expressundefined
defaultLabelsAn object containing default labels to be sent with each metric.Object{}
defaultMetricsFlag to enable/disable the default metrics registered by prom-client.Booleantrue
defaultMetricsOptionsConfiguration object for the default metrics.DefaultMetricsCollectorConfiguration{}
disabledMetricsA list of metrics to be skipped.MetricsNames[][]
hostnameLabelFlag to enable/disable hostname label.Booleantrue
hostnameLabelNameThe name of the hostname label.Stringhostname
metricsEndpointFlag to enable/disable the metrics endpoint. If you disable this, you can use the registerPrometheusMetricsEndpoint method to enable the metrics endpoint.Booleantrue
metricsEndpointPathHTTP path where the metrics will be published.String"/metrics"
registerPrometheus client registry to be used by Apollo Metrics. By default, it is also used by the default metrics.Registryregister

Thanks