@thecodenebula/apollo-prometheus-plugin

An Apollo plugin to expose GraphQL metrics as prometheus metrics

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
@thecodenebula/apollo-prometheus-plugin
3231.0.13 years ago3 years agoMinified + gzip package size for @thecodenebula/apollo-prometheus-plugin in KB

Readme

Apollo Prometheus Plugin Tests npm (scoped)

Install

npm install @thecodenebula/apollo-prometheus-plugin

Usage

import { ApolloServer, gql } from 'apollo-server-express';
import { prometheusPlugin } from 'apollo-prometheus-plugin';
import { Registry } from 'prom-client';
import { prometheusPlugin } from '@thecodenebula/apollo-prometheus-plugin';

const register = new Registry();

const app = express();

app.get('/metrics', (_, res) => res.send(register.metrics()));

const server = new ApolloServer({
  typeDefs,
  resolvers,
  plugins: [prometheusPlugin(register, { enableNodeMetrics: true })],
});

server.applyMiddleware({ app, path: '/' });
app.listen({ port: 8080 }, () => {
  console.log('Listening');
});

Available metrics and labels

| metric | type | labels | |---------------------- |----------- |--------------------------------------- | | errorsencountered | Counter | operationName
operation
error | | requests
resolved | Counter | operationName
operation | | attributesrequested | Counter | fieldName
parentType | | resolver
time | Histogram | fieldName
parentType
returnType | | totalrequesttime | Histogram | operationName
operation |