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

kuzzle-plugin-prometheus

v4.2.1

Published

Kuzzle plugin: monitoring Kuzzle using Prometheus

Downloads

254

Readme

About

Kuzzle Prometheus Plugin

This is the official Prometheus monitoring plugin for the free and open-source backend Kuzzle. It provides you features such as:

Kuzzle

Kuzzle is an open-source backend that includes a scalable server, a multiprotocol API, an administration console and a set of plugins that provide advanced functionalities like real-time pub/sub, blazing fast search and geofencing.

Compatibility matrix

| Kuzzle Version | Plugin Version | | -------------- | -------------- | | 1.10.x | 1.x.x | | 2.x.x | 2.x.x | | 3.x.x | >= 2.11.x | | 4.x.x | >= 2.16.9 |

Installation

To install this plugin on your Kuzzle stack (for each of your Kuzzle nodes), you will first need a Kuzzle Application like so. (see Getting Started)

import { Backend } from 'kuzzle';

const app = new Backend('kuzzle');

app.start()
  .then(() => {
    app.log.info('Application started');
  })
  .catch(console.error);

Once you have it, you will need to:

  • Import the Prometheus plugin,
  • Create a new instance of the plugin
  • And then use it in your application.

You will end up with something like this:

import { Backend } from 'kuzzle';
import { PrometheusPlugin } from 'kuzzle-plugin-prometheus'; // Import the prometheus plugin

const app = new Backend('kuzzle');

const prometheusPlugin = new PrometheusPlugin(); // Create a new instance of the prometheus plugin

app.plugin.use(prometheusPlugin); // Add the plugin to your application

app.start()
  .then(() => {
    app.log.info('Application started');
  })
  .catch(console.error);

Configuration

You can find sample configuration files for this plugin and the Prometheus scraping job in the demo folder.

Plugin

This plugin is configurable using the kuzzlerc Kuzzle configuration file.

 {
 "plugins": {
    "prometheus": {
      "default": {
        "enabled": true,
        "prefix": "",
        "eventLoopMonitoringPrecision": 10,
        "gcDurationBuckets": [0.001, 0.01, 0.1, 1, 2, 5]
      },
      "core": {
        "monitorRequestDuration": true,
        "prefix": "kuzzle_"
      },
      "labels": {
        "project": "mySuperProject",
        "environment": "development"
      }
    }
  }
}
  • default: Default Node.js metrics retrieved by the Prom Client library
    • enabled: Enable/Disable the default Node.js metrics (default: true)
    • prefix: String to use to prefix metrics name (default: an empty string to avoid conflicts when using official Grafana dashboards)
    • eventLoopMonitoringPrecision: Node.js Event Loop sampling rate in milliseconds. Must be greater than zero (default: 10)
    • gcDurationBuckets: Custom Prometheus buckets for Node.js GC duration histogram in seconds (default: [0.001, 0.01, 0.1, 1, 2, 5])
  • core: Kuzzle Core metrics directly extract from the server:metrics API action or from plugin inner logic.
    • monitorRequestDuration: Enable/Disable request duration sampling (default: true)
    • prefix: String to use to prefix metrics name (default: kuzzle_)
  • labels: Additional labels to apply on all the different metrics (default: {})

Prometheus

With only one Kuzzle node

global:
  scrape_interval:     10s # Set the scrape interval to every 10 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.

scrape_configs:
  - job_name: 'kuzzle'
    metrics_path: /_metrics
    params:
      format: ['prometheus']
    static_configs:
      - targets: ['kuzzle:7512'] # the address of an application that exposes metrics for prometheus

With an authentified user

If you use an other user than anonymous to expose the server:metrics API action, you will need to create a Kuzzle API Key (see API Keys) and use it to authentify the Prometheus scaper:

global:
  scrape_interval:     10s # Set the scrape interval to every 10 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.

scrape_configs:
  - job_name: 'kuzzle'
    metrics_path: /_metrics
    params:
      format: ['prometheus']
    authorization:
      type: 'Bearer'
      credentials: 'my-api-key'
    static_configs:
      - targets: ['kuzzle:7512'] # the address of an application that exposes metrics for prometheus

With multiple Kuzzle nodes and using Docker Compose

If you use Docker Compose you'll need to provide the IP/Docker DNS name of each Kuzzle node as targets:

global:
  scrape_interval:     10s # Set the scrape interval to every 10 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.

scrape_configs:
  - job_name: 'kuzzle'
    metrics_path: /_metrics
    params:
      format: ['prometheus']
    static_configs:
      - targets: 
        - 'kuzzle-plugin-prometheus-kuzzle-1:7512' 
        - 'kuzzle-plugin-prometheus-kuzzle-2:7512'
        - 'kuzzle-plugin-prometheus-kuzzle-3:7512'

Using Kubernetes annotations

If your Prometheus inside a Kubernetes cluster, you must use the helper HTTP route /_/metrics since Prometheus params configuration is not supported. Your Pods annotations should look like this:

metadata:
  annotations:
    prometheus.io/scrape: "true"
    prometheus.io/path: /_/metrics
    prometheus.io/port: "7512"
spec:
...

Dashboards

Features

You could find two dashboards in the config/grafana/dashboards folder:

  • kuzzle.json: a dashboard with all the metrics exposed by the server:metrics API action with a nodeId filter and including:

    • Active connections
    • Active Realtime subscriptions
    • Concurrent requests
    • Pending requests
    • Request per second
    • Request duration
    • Internal Errors
  • nodejs.json: Node.js metrics dashboard with a nodeId filter and including:

    • Process CPU Usage
    • Process Memory Usage
    • Process Restarts
    • Event Loop Latency
    • Heap Usage

You can import them both using the Grafana API, Web UI or the provisionning system (see the docker-compose.yml file).

Screenshots

Local development

You can run a local development stack using Docker Compose

$ docker-compose up

This will start a demonstration stack composed with:

  • A Kuzzle server proxified by a Traefik router
  • A Prometheus container configured to scrap metrics.
  • A Grafana container.

Once started, go to http://localhost:3000 and log in with the default Grafana credentials:

  • username: admin
  • password: admin

Make several requests using Kuzzle's HTTP API or SDKs, or by using the Admin Console.

NOTE: You can also increase the number of Kuzzle nodes to test a cluster configuration. Use the Docker Compose --scale option to increase the number of replicas:

docker-compose up -d --scale kuzzle=<number-of-replicas>

Notice that you need to update the config/prometheus.yml file to reflect the new number of nodes and restart the prometheus container using docker restart <prometheus-container-id>

Migrations

From version 3.x to 4.x

This new version 4.0.0 introduce numerous changes in the way metrics are collected and reported:

  • The plugin now uses the server:metrics API action to retrieve metrics from Kuzzle Core. Calling the server:metrics API action with the format parameter set to prometheus will return metrics in the Prometheus format.
  • The configuration of the plugin is now more flexible (see Configuration section for more details):
    • More control on the default Node.js metrics (set the Event Loop sample precision to custom value or adapt the Garbage Collector Prometheus bucket rates to fit your usecase).
    • You can set different prefixes for Kuzzle Core metrics and Node.js metrics.
    • The nodeIP, nodeMAC and nodeHost labels have beem removed in favor of the nodeId label.
    • You can now disable the request recording job.
  • Most of the metric names have been changed to be more consistent with Kuzzle Core metrics.

Migration steps