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

nexus-plugin-prometheus

v0.1.0

Published

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

Downloads

5

Readme

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.