Giter Site home page Giter Site logo

haysclark / nexus-plugin-prometheus Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 253 KB

A nexus-framework plugin for reporting basic GraphQL metrics through Prometheus (via prom-client)

Home Page: https://github.com/haysclark/nexus-plugin-prometheus

License: MIT License

JavaScript 19.16% TypeScript 80.84%
graphql server nexus-framework prom-client prometheus metrics nexus express

nexus-plugin-prometheus's Introduction

nexus-plugin-prometheus

Version Downloads Last commit License PRs Welcome Code of conduct

A nexus-framework plugin for reporting basic GraphQL metrics through Prometheus (via prom-client)


This nexus-framework plugin collects basics GraphQL metrics and reports them to a Prometheus server. The plugin utilizes the prom-client library to communicate with Prometheus and thus requires Nexus' instance of express to be provided to the plugin.

⚠️ This plugin does NOT support Nexus projects utilizing serverless Next.JS implementations!

Installation

This module is distributed via npm which is bundled with Node.js.

npm install --save nexus-plugin-prometheus

OR

yarn add nexus-plugin-prometheus

Usage

Find a full example in the examples/basic-prometheus folder, which also includes a basic Grafana Dashboard and docker-compose file to fully illustrate the plugin in use.

Setup

Due to the middleware architecture of Nexus-framework plugins, it is vital that one use the nexus-plugin-prometheus first, so that no requests are culled by another plugin.

// app.ts

import { use, server } from 'nexus'
import { prometheus } from 'nexus-plugin-prometheus'

// Enables the Prometheus reporting plugin
use(
  prometheus({
    express: server.express, // inject Nexus express instance
  })
)

Prometheus will now be able to collect metrics from the servers /metrics url.

Running collectDefaultMetrics for collecting server metrics

Executing prom-client's collectDefaultMetrics method can be done by providing the plugin with a custom configureRegistry method.

For more information on configuring prom-client, see it's usage documentation.

// app.ts

import { use, server } from 'nexus'
import { prometheus } from 'nexus-plugin-prometheus'
import { Registry, collectDefaultMetrics } from 'prom-client'

// Define custom configuration of prom-client
function configureRegistry(): Registry[] {
  const register = new Registry()
  collectDefaultMetrics({ register })
  return [register]
}

// Enables the Prometheus reporting plugin
use(
  prometheus({
    express: server.express,
    configureRegistry, // provide custom
  })
)

Adding a prefix to my metrics

Executing prom-client's collectDefaultMetrics method with any additional configuration, such as a prefix, can be done by providing the plugin with a custom configureRegistry method.

For more information on configuring prom-client, see it's usage documentation.

// app.ts

import { use, server } from 'nexus'
import { prometheus } from 'nexus-plugin-prometheus'
import { Registry, collectDefaultMetrics } from 'prom-client'

// Define custom configuration of prom-client
function configureRegistry(): Registry[] {
  const register = new Registry()
  const prefix = 'my_application_'
  collectDefaultMetrics({ register, prefix })
  return [register]
}

// Enables the Prometheus reporting plugin
use(
  prometheus({
    express: server.express,
    configureRegistry, // provide custom
  })
)

Contributing

Please read CONTRIBUTING.md

Related

Inspiration

Credits

Authored and maintained by Hays Clark.

To all contributors - Thank you!

License

Open-source under MIT License.

FAQ

Uh oh, something went wrong!

Sorry about that. It is recommended that you enable "debug" and "allowExternalErrors" in your plugin. Additionally, if you are using other Nexus plugins, you may want to do the same for them.

// app.ts

import { use, server } from 'nexus'
import { prometheus } from 'nexus-plugin-prometheus'

// Enables the Prometheus reporting plugin
use(
  prometheus({
    express: server.express,
    debug: true,
    allowExternalErrors: true,
  })
)

If you are still stuck, please submit a bug report using the GitHub issue tracker.

I wish something was different…

Keen to hear all ideas! Create an enhancement request using the GitHub issue tracker.

Can I contribute code?

Yes please! See DEVELOPING.md.

My question isn't answered :(

Ask away using the GitHub issue tracker.

nexus-plugin-prometheus's People

Contributors

haysclark avatar semantic-release-bot avatar

Stargazers

 avatar

Watchers

 avatar  avatar

nexus-plugin-prometheus's Issues

The automated release is failing 🚨

🚨 The automated release from the alpha branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this 💪.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the alpha branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two-Factor Authentication, make configure the auth-only level is supported. semantic-release cannot publish with the default auth-and-writes level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project ✨

Your semantic-release bot 📦🚀

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.