Code Monkey home page Code Monkey logo

adonis-prometheus's Introduction

Adonis Prometheus ๐Ÿง

Provides a simple way to easily montior your AdonisJS application via Prometheus.

This is simply a wrapper around the NodeJS prom-client library, along with extra in-built metrics tailored for AdonisJS.

You can also build your custom metrics with this library just as you would have done with prom-client. Check out building custom metrics.

Installation

Step 1

Run this command to install:

adonis install adonis-prometheus

Step 2

Register the Adonis Prometheus provider in your AdonisJS application's start/app.js:

const providers = [
  // ...,
  "adonis-prometheus/providers/PrometheusProvider",
];

Step 3 (Optional)

There currently exists in-built metrics such as:

  • HTTP Metric: Total time each HTTP request takes.
  • Uptime Metric: Uptime performance of the application.
  • Throughput metric: No. of request handled.

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

const globalMiddleware = [
  // Make it first in the list for reliable metric.
  "Adonis/Prometheus/Middlewares/CollectPerformanceMetric",
  "Adonis/Middleware/BodyParser",
];

Configure In-Built Metrics

There are scenarios were you want to:

  • Configure the in-built metrics (e.g. change prefix, etc)
  • Disable one or all the metrics entirely (and build yours from scratch).

To simply do that, simply modify the available configuration in config/prometheus.js.

Building Custom Metrics

Track total emails sent.

/** @type {typeof import('prom-client')} */
const Prometheus = use("Prometheus");

// Step 1: Create the metrics counter.
const emailMetric = new Prometheus.Counter({
  name: "send_emails",
  help: "Total Emails sent.",
  labels: ["success", "failed"],
  prefix: "",
});

const sendEmail = async () => {
  try {
    // Implement logic to send Email here.

    // Step 2: Increment success counter (if success).
    emailMetric.inc({ success: 1 });
  } catch (err) {
    // Step 2: Increment failed counter (if failed).
    emailMetric.inc({ failed: 1 });
  }
};

// Step 3: Send the Email
sendEmail().then((_) => console.log("Email Sent & Metric Captured"));

Documentation

This libary is simply a wrapper over prom-client. Hence, you can do everything prom-client does with this library.

Contributing

If you find any issue, bug or missing feature, please kindly create an issue or submit a pull request.

License

Adonis Prometheus is open-sourced software under MIT license.

adonis-prometheus's People

Contributors

toksdotdev avatar mateus4k avatar

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.