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

@meyer0x/adonisjs-prometheus

v1.2.2

Published

Prometheus wrapper for AdonisJS

Downloads

89

Readme

adonisjs-prometheus

📊 A Prometheus wrapper for AdonisJS 6 ( see here for AdonisJS 5 version )

Installation

pnpm i adonis5-prometheus
node ace configure @meyer0x/adonisjs-prometheus

Usage

After installation, a configuration file has been added in config/prometheus.ts.

By default the system metrics are collected ( systemMetrics.enabled: true ), so now you can call the endpoint {{host}}/metrics to get the measured metrics.

Here is an example scrape_config to add to prometheus.yml:

scrape_configs:
  - job_name: my-adonis-app
    static_configs:
      - targets: [my-adonis-app.com]
    scrape_interval: 5s

Built-in Metrics

Metrics collected by Adonis5-prometheus middleware | Type | Name | Description | | --- | --- | --- | | Histogram | adonis_http_request_durations | Total time each HTTP requests takes. | | Gauge | adonis_uptime_metrics | Uptime performance of the application (1 = up, 0 = down) | | Counter | adonis_throughput_metrics | No. of request handled. |

To enable them, simply register the CollectPerformanceMetrics as the first item in the start/kernel.ts:

Server.middleware.register([
  // Make it first in the list for reliable metrics.
  () => import('@ioc:Adonis/Prometheus/Middlewares/CollectPerformanceMetrics'),
  () => import('@ioc:Adonis/Core/BodyParser'),
  ...
])

Verify if the metrics are enabled in the config/prometheus.ts file. You can also configure the metrics there.

Custom Metrics

// Register your custom metrics in the separate file you want.
export const OrderMetric = new Prometheus.Counter({
  name: 'sent_orders',
  help: 'Total Orders Sent',
})

// OrderController.ts
import { OrderMetric } from 'App/Metrics'

export default class OrderController {
  public async store({ request }: HttpContextContract) {
    const order = await request.validate({ schema: OrderSchema })

    // ...
    OrderMetric.inc()
    // ...
  }
}

When hitting {{host}}/metrics you will now get the following:

# HELP send_orders Total Orders Sent
# TYPE send_orders counter
sent_orders 2

Grafana Dashboard

A basic ready to use dashboard is available in the grafana folder. Grafana 8 is required to be able to import the dashboard correctly, otherwise you'll have to tinker a bit to make it work. https://i.imgur.com/mD0UMhA.png?1 It includes :

  • Process CPU usage
  • Event loop lag
  • Node.JS version
  • Requests by second
  • Request volume rate by URL
  • Average response time
  • Response error rate by URL

To be fully functional, you need to enable systemMetrics, httpMetric and throughputMetric in the config/prometheus.ts file.

Documentation

This library is a wrapper for prom-client. The prom-client object can be imported with import Prometheus from '@ioc:Adonis/Prometheus'. Check out the documentation for more information.