npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@dreamit/graphql-prom-metrics

v1.2.7

Published

MetricsClient for @dreamit/graphql-server using prom-client library

Downloads

31

Readme

graphql-prom-metrics

MetricsClient for @dreamit/graphql-server using prom-client library.

Installation

npm install --save @dreamit/graphql-prom-metrics

TypeScript declarations are provided within the project.

Compatibility

graphql-prom-metrics is compatible with @dreamit/graphql-server version ^3.2.1 and prom-client version ^14.0.1.

Features

  • Provides out-of-the-box metrics for GraphQLServer
  • Provides 3 custom as well as NodeJS related metrics.
  • Uses only 2 peerDependencies: @dreamit/graphql-server version 3 and prom-client version 14 (no other production dependencies)

Metrics

The PromMetricsClient uses prom-client library to provide NodeJS metrics like cpu and memory usage as well as GraphQLServer related metrics.

Warning!: If you are using PromMetricsClient you should avoid creating multiple GraphQLServer instances that all use the PromMetricsClient. Because of the usage of a global object in the prom-client library this might result in unexpected behaviour or malfunction. You can set another metrics client like SimpleMetricsClient by calling GraphQLServer setOptions() or GraphQLServer setMetricsClient().

The PromMetricsClient provides three custom metrics for the GraphQL server:

  • graphql_server_availability: Availability gauge with status 0 (unavailable) and 1 (available)
  • graphql_server_request_throughput: The number of incoming requests
  • graphql_server_errors: The number of errors that are encountered while running the GraphQLServer. The counter uses the errorName field as label so errors could be differentiated. At the moment the following labels are available and initialized with 0:
    • FetchError
    • GraphQLError
    • SchemaValidationError
    • MethodNotAllowedError
    • InvalidSchemaError
    • MissingQueryParameterError
    • ValidationError
    • SyntaxError
    • IntrospectionDisabledError

A simple metrics endpoint can be created by using getMetricsContentType and getMetrics functions from the GraphQLServer instance. In the example below a second route is used to return metrics data.

const graphQLServerPort = 3592
const graphQLServerExpress = express()
const customGraphQLServer = new GraphQLServer({
    schema: someExampleSchema,
    metricsClient: new PromMetricsClient(),
})
graphQLServerExpress.use(bodyParser.text({ type: '*/*' }))
graphQLServerExpress.all('/graphql', (req, res) => {
    return customGraphQLServer.handleRequestAndSendResponse(req, res)
})
graphQLServerExpress.get('/metrics', async (req, res) => {
    return res
        .contentType(customGraphQLServer.getMetricsContentType())
        .send(await customGraphQLServer.getMetrics())
})
graphQLServerExpress.listen({ port: graphQLServerPort })
console.info(`Starting GraphQL server on port ${graphQLServerPort}`)

Contact

If you have questions or issues please visit our Issue page and open a new issue if there are no fitting issues for your topic yet.

License

graphql-server is under MIT-License.