bfmatei / apollo-prometheus-exporter

Plugin for Apollo Server to export metrics in Prometheus format
MIT License
55 stars 29 forks source link

Koa #5

Closed robross0606 closed 3 years ago

robross0606 commented 3 years ago

Is it possible to use this with Koa instead of Express?

robross0606 commented 3 years ago

Using the options, I was able to get this plugin at least partially running with:

createPrometheusExporterPlugin({ metricsEndpoint: false, defaultMetrics: false })

What I'm seeing on my endpoint now contains this:

# HELP apollo_server_starting The last timestamp when Apollo Server was starting.
# TYPE apollo_server_starting gauge
apollo_server_starting{version="v2.21.0",hostname="RROSS-XPS15"} 1614355537.831

# HELP apollo_server_closing The amount timestamp when Apollo Server was closing.
# TYPE apollo_server_closing gauge

# HELP apollo_query_started The amount of received queries.
# TYPE apollo_query_started counter

# HELP apollo_query_parse_started The amount of queries for which parsing has started.
# TYPE apollo_query_parse_started counter

# HELP apollo_query_parse_failed The amount of queries for which parsing has failed.
# TYPE apollo_query_parse_failed counter

# HELP apollo_query_validation_started The amount of queries for which validation has started.
# TYPE apollo_query_validation_started counter

# HELP apollo_query_validation_failed The amount of queries for which validation has failed.
# TYPE apollo_query_validation_failed counter

# HELP apollo_query_resolved The amount of queries which could be resolved.
# TYPE apollo_query_resolved counter

# HELP apollo_query_execution_started The amount of queries for which execution has started.
# TYPE apollo_query_execution_started counter

# HELP apollo_query_execution_failed The amount of queries for which execution has failed.
# TYPE apollo_query_execution_failed counter

# HELP apollo_query_failed The amount of queries that failed.
# TYPE apollo_query_failed counter

# HELP apollo_query_duration The total duration of a query.
# TYPE apollo_query_duration histogram

# HELP apollo_query_field_resolution_duration The total duration for resolving fields.
# TYPE apollo_query_field_resolution_duration histogram

However, I'm not seeing any actual statistics being gathered when I make Apollo queries.

bfmatei commented 3 years ago

Hello!

Yep, express is used only for exposing the metrics. What you can do:

import { register } from 'prom-client';

const app = new koa();
const router = new koaRouter();

const prometheusExporterPlugin = createPrometheusExporterPlugin({
  register, // this may not be needed but it ensures that the correct prom-client register is used
  metricsEndpoint: false // this will disable the integration between the plugin and express
});

// ... continue with the usual implementation of Apollo

router.get('/metrics', async (ctx) => {
  ctx.type = register.contentType; // set the correct content type from the prom-client register
  ctx.body = await actualRegister.metrics(); // set the body of the response to the data exposed by prom-client
});
bfmatei commented 3 years ago

Also, can you please post an example using StackBlitz or a GitHub repo to look over? It would help a lot.

Thanks!

bfmatei commented 3 years ago

I'm going to close this for no activity. Please feel free to reopen it if needed.

robross0606 commented 3 years ago

Finally had a chance to circle back on this. I does look like it is working now:

# HELP apollo_server_starting The last timestamp when Apollo Server was starting.
# TYPE apollo_server_starting gauge
apollo_server_starting{version="v2.22.2",hostname="RROSS-XPS15"} 1617279638.125

# HELP apollo_server_closing The amount timestamp when Apollo Server was closing.
# TYPE apollo_server_closing gauge

# HELP apollo_query_started The amount of received queries.
# TYPE apollo_query_started counter
apollo_query_started{operationName="IntrospectionQuery",hostname="RROSS-XPS15"} 2
apollo_query_started{hostname="RROSS-XPS15"} 9

# HELP apollo_query_parse_started The amount of queries for which parsing has started.
# TYPE apollo_query_parse_started counter
apollo_query_parse_started{operationName="IntrospectionQuery",hostname="RROSS-XPS15"} 1
apollo_query_parse_started{hostname="RROSS-XPS15"} 2

# HELP apollo_query_parse_failed The amount of queries for which parsing has failed.
# TYPE apollo_query_parse_failed counter

# HELP apollo_query_validation_started The amount of queries for which validation has started.
# TYPE apollo_query_validation_started counter
apollo_query_validation_started{operationName="IntrospectionQuery",hostname="RROSS-XPS15"} 1
apollo_query_validation_started{hostname="RROSS-XPS15"} 2

# HELP apollo_query_validation_failed The amount of queries for which validation has failed.
# TYPE apollo_query_validation_failed counter

# HELP apollo_query_resolved The amount of queries which could be resolved.
# TYPE apollo_query_resolved counter
apollo_query_resolved{operationName="IntrospectionQuery",operation="query",hostname="RROSS-XPS15"} 2
apollo_query_resolved{operation="query",hostname="RROSS-XPS15"} 9

# HELP apollo_query_execution_started The amount of queries for which execution has started.
# TYPE apollo_query_execution_started counter
apollo_query_execution_started{operationName="IntrospectionQuery",operation="query",hostname="RROSS-XPS15"} 2
apollo_query_execution_started{operation="query",hostname="RROSS-XPS15"} 9

# HELP apollo_query_execution_failed The amount of queries for which execution has failed.
# TYPE apollo_query_execution_failed counter

# HELP apollo_query_failed The amount of queries that failed.
# TYPE apollo_query_failed counter

# HELP apollo_query_duration The total duration of a query.
# TYPE apollo_query_duration histogram
apollo_query_duration_bucket{le="0.001",operationName="IntrospectionQuery",operation="query",success="true",hostname="RROSS-XPS15"} 0
apollo_query_duration_bucket{le="0.005",operationName="IntrospectionQuery",operation="query",success="true",hostname="RROSS-XPS15"} 0
apollo_query_duration_bucket{le="0.015",operationName="IntrospectionQuery",operation="query",success="true",hostname="RROSS-XPS15"} 0
apollo_query_duration_bucket{le="0.05",operationName="IntrospectionQuery",operation="query",success="true",hostname="RROSS-XPS15"} 3
apollo_query_duration_bucket{le="0.1",operationName="IntrospectionQuery",operation="query",success="true",hostname="RROSS-XPS15"} 3
apollo_query_duration_bucket{le="0.2",operationName="IntrospectionQuery",operation="query",success="true",hostname="RROSS-XPS15"} 3
apollo_query_duration_bucket{le="0.3",operationName="IntrospectionQuery",operation="query",success="true",hostname="RROSS-XPS15"} 3
apollo_query_duration_bucket{le="0.4",operationName="IntrospectionQuery",operation="query",success="true",hostname="RROSS-XPS15"} 3
apollo_query_duration_bucket{le="0.5",operationName="IntrospectionQuery",operation="query",success="true",hostname="RROSS-XPS15"} 3
apollo_query_duration_bucket{le="1",operationName="IntrospectionQuery",operation="query",success="true",hostname="RROSS-XPS15"} 3
apollo_query_duration_bucket{le="5",operationName="IntrospectionQuery",operation="query",success="true",hostname="RROSS-XPS15"} 3
apollo_query_duration_bucket{le="10",operationName="IntrospectionQuery",operation="query",success="true",hostname="RROSS-XPS15"} 3
apollo_query_duration_bucket{le="+Inf",operationName="IntrospectionQuery",operation="query",success="true",hostname="RROSS-XPS15"} 3
apollo_query_duration_sum{operationName="IntrospectionQuery",operation="query",success="true",hostname="RROSS-XPS15"} 0.082
apollo_query_duration_count{operationName="IntrospectionQuery",operation="query",success="true",hostname="RROSS-XPS15"} 3
apollo_query_duration_bucket{le="0.001",operation="query",success="true",hostname="RROSS-XPS15"} 8
apollo_query_duration_bucket{le="0.005",operation="query",success="true",hostname="RROSS-XPS15"} 10
apollo_query_duration_bucket{le="0.015",operation="query",success="true",hostname="RROSS-XPS15"} 10
apollo_query_duration_bucket{le="0.05",operation="query",success="true",hostname="RROSS-XPS15"} 10
apollo_query_duration_bucket{le="0.1",operation="query",success="true",hostname="RROSS-XPS15"} 10
apollo_query_duration_bucket{le="0.2",operation="query",success="true",hostname="RROSS-XPS15"} 10
apollo_query_duration_bucket{le="0.3",operation="query",success="true",hostname="RROSS-XPS15"} 10
apollo_query_duration_bucket{le="0.4",operation="query",success="true",hostname="RROSS-XPS15"} 10
apollo_query_duration_bucket{le="0.5",operation="query",success="true",hostname="RROSS-XPS15"} 10
apollo_query_duration_bucket{le="1",operation="query",success="true",hostname="RROSS-XPS15"} 10
apollo_query_duration_bucket{le="5",operation="query",success="true",hostname="RROSS-XPS15"} 10
apollo_query_duration_bucket{le="10",operation="query",success="true",hostname="RROSS-XPS15"} 10
apollo_query_duration_bucket{le="+Inf",operation="query",success="true",hostname="RROSS-XPS15"} 10
apollo_query_duration_sum{operation="query",success="true",hostname="RROSS-XPS15"} 0.008
apollo_query_duration_count{operation="query",success="true",hostname="RROSS-XPS15"} 10

# HELP apollo_query_field_resolution_duration The total duration for resolving fields.
# TYPE apollo_query_field_resolution_duration histogram
apollo_query_field_resolution_duration_bucket{le="0.001",operation="query",fieldName="pingStudyDesignService",parentType="Query",pathLength="1",hostname="RROSS-XPS15"} 8
apollo_query_field_resolution_duration_bucket{le="0.005",operation="query",fieldName="pingStudyDesignService",parentType="Query",pathLength="1",hostname="RROSS-XPS15"} 8
apollo_query_field_resolution_duration_bucket{le="0.015",operation="query",fieldName="pingStudyDesignService",parentType="Query",pathLength="1",hostname="RROSS-XPS15"} 8
apollo_query_field_resolution_duration_bucket{le="0.05",operation="query",fieldName="pingStudyDesignService",parentType="Query",pathLength="1",hostname="RROSS-XPS15"} 8
apollo_query_field_resolution_duration_bucket{le="0.1",operation="query",fieldName="pingStudyDesignService",parentType="Query",pathLength="1",hostname="RROSS-XPS15"} 8
apollo_query_field_resolution_duration_bucket{le="0.2",operation="query",fieldName="pingStudyDesignService",parentType="Query",pathLength="1",hostname="RROSS-XPS15"} 8
apollo_query_field_resolution_duration_bucket{le="0.3",operation="query",fieldName="pingStudyDesignService",parentType="Query",pathLength="1",hostname="RROSS-XPS15"} 8
apollo_query_field_resolution_duration_bucket{le="0.4",operation="query",fieldName="pingStudyDesignService",parentType="Query",pathLength="1",hostname="RROSS-XPS15"} 8
apollo_query_field_resolution_duration_bucket{le="0.5",operation="query",fieldName="pingStudyDesignService",parentType="Query",pathLength="1",hostname="RROSS-XPS15"} 8
apollo_query_field_resolution_duration_bucket{le="1",operation="query",fieldName="pingStudyDesignService",parentType="Query",pathLength="1",hostname="RROSS-XPS15"} 8
apollo_query_field_resolution_duration_bucket{le="5",operation="query",fieldName="pingStudyDesignService",parentType="Query",pathLength="1",hostname="RROSS-XPS15"} 8
apollo_query_field_resolution_duration_bucket{le="10",operation="query",fieldName="pingStudyDesignService",parentType="Query",pathLength="1",hostname="RROSS-XPS15"} 8
apollo_query_field_resolution_duration_bucket{le="+Inf",operation="query",fieldName="pingStudyDesignService",parentType="Query",pathLength="1",hostname="RROSS-XPS15"} 8
apollo_query_field_resolution_duration_sum{operation="query",fieldName="pingStudyDesignService",parentType="Query",pathLength="1",hostname="RROSS-XPS15"} 0
apollo_query_field_resolution_duration_count{operation="query",fieldName="pingStudyDesignService",parentType="Query",pathLength="1",hostname="RROSS-XPS15"} 8
apollo_query_field_resolution_duration_bucket{le="0.001",operation="query",fieldName="features",parentType="Query",pathLength="1",hostname="RROSS-XPS15"} 2
apollo_query_field_resolution_duration_bucket{le="0.005",operation="query",fieldName="features",parentType="Query",pathLength="1",hostname="RROSS-XPS15"} 2
apollo_query_field_resolution_duration_bucket{le="0.015",operation="query",fieldName="features",parentType="Query",pathLength="1",hostname="RROSS-XPS15"} 2
apollo_query_field_resolution_duration_bucket{le="0.05",operation="query",fieldName="features",parentType="Query",pathLength="1",hostname="RROSS-XPS15"} 2
apollo_query_field_resolution_duration_bucket{le="0.1",operation="query",fieldName="features",parentType="Query",pathLength="1",hostname="RROSS-XPS15"} 2
apollo_query_field_resolution_duration_bucket{le="0.2",operation="query",fieldName="features",parentType="Query",pathLength="1",hostname="RROSS-XPS15"} 2
apollo_query_field_resolution_duration_bucket{le="0.3",operation="query",fieldName="features",parentType="Query",pathLength="1",hostname="RROSS-XPS15"} 2
apollo_query_field_resolution_duration_bucket{le="0.4",operation="query",fieldName="features",parentType="Query",pathLength="1",hostname="RROSS-XPS15"} 2
apollo_query_field_resolution_duration_bucket{le="0.5",operation="query",fieldName="features",parentType="Query",pathLength="1",hostname="RROSS-XPS15"} 2
apollo_query_field_resolution_duration_bucket{le="1",operation="query",fieldName="features",parentType="Query",pathLength="1",hostname="RROSS-XPS15"} 2
apollo_query_field_resolution_duration_bucket{le="5",operation="query",fieldName="features",parentType="Query",pathLength="1",hostname="RROSS-XPS15"} 2
apollo_query_field_resolution_duration_bucket{le="10",operation="query",fieldName="features",parentType="Query",pathLength="1",hostname="RROSS-XPS15"} 2
apollo_query_field_resolution_duration_bucket{le="+Inf",operation="query",fieldName="features",parentType="Query",pathLength="1",hostname="RROSS-XPS15"} 2
apollo_query_field_resolution_duration_sum{operation="query",fieldName="features",parentType="Query",pathLength="1",hostname="RROSS-XPS15"} 0
apollo_query_field_resolution_duration_count{operation="query",fieldName="features",parentType="Query",pathLength="1",hostname="RROSS-XPS15"} 2
apollo_query_field_resolution_duration_bucket{le="0.001",operation="query",fieldName="studyActivityReorderingAllowed",parentType="FeatureResponse",pathLength="2",hostname="RROSS-XPS15"} 2
apollo_query_field_resolution_duration_bucket{le="0.005",operation="query",fieldName="studyActivityReorderingAllowed",parentType="FeatureResponse",pathLength="2",hostname="RROSS-XPS15"} 2
apollo_query_field_resolution_duration_bucket{le="0.015",operation="query",fieldName="studyActivityReorderingAllowed",parentType="FeatureResponse",pathLength="2",hostname="RROSS-XPS15"} 2
apollo_query_field_resolution_duration_bucket{le="0.05",operation="query",fieldName="studyActivityReorderingAllowed",parentType="FeatureResponse",pathLength="2",hostname="RROSS-XPS15"} 2
apollo_query_field_resolution_duration_bucket{le="0.1",operation="query",fieldName="studyActivityReorderingAllowed",parentType="FeatureResponse",pathLength="2",hostname="RROSS-XPS15"} 2
apollo_query_field_resolution_duration_bucket{le="0.2",operation="query",fieldName="studyActivityReorderingAllowed",parentType="FeatureResponse",pathLength="2",hostname="RROSS-XPS15"} 2
apollo_query_field_resolution_duration_bucket{le="0.3",operation="query",fieldName="studyActivityReorderingAllowed",parentType="FeatureResponse",pathLength="2",hostname="RROSS-XPS15"} 2
apollo_query_field_resolution_duration_bucket{le="0.4",operation="query",fieldName="studyActivityReorderingAllowed",parentType="FeatureResponse",pathLength="2",hostname="RROSS-XPS15"} 2
apollo_query_field_resolution_duration_bucket{le="0.5",operation="query",fieldName="studyActivityReorderingAllowed",parentType="FeatureResponse",pathLength="2",hostname="RROSS-XPS15"} 2
apollo_query_field_resolution_duration_bucket{le="1",operation="query",fieldName="studyActivityReorderingAllowed",parentType="FeatureResponse",pathLength="2",hostname="RROSS-XPS15"} 2
apollo_query_field_resolution_duration_bucket{le="5",operation="query",fieldName="studyActivityReorderingAllowed",parentType="FeatureResponse",pathLength="2",hostname="RROSS-XPS15"} 2
apollo_query_field_resolution_duration_bucket{le="10",operation="query",fieldName="studyActivityReorderingAllowed",parentType="FeatureResponse",pathLength="2",hostname="RROSS-XPS15"} 2
apollo_query_field_resolution_duration_bucket{le="+Inf",operation="query",fieldName="studyActivityReorderingAllowed",parentType="FeatureResponse",pathLength="2",hostname="RROSS-XPS15"} 2
apollo_query_field_resolution_duration_sum{operation="query",fieldName="studyActivityReorderingAllowed",parentType="FeatureResponse",pathLength="2",hostname="RROSS-XPS15"} 0
apollo_query_field_resolution_duration_count{operation="query",fieldName="studyActivityReorderingAllowed",parentType="FeatureResponse",pathLength="2",hostname="RROSS-XPS15"} 2