Skip to content

Latest commit

 

History

History
65 lines (50 loc) · 1.2 KB

readme.md

File metadata and controls

65 lines (50 loc) · 1.2 KB

NUXT Prometheus Exporter

NUXT Prometheus exporter makes it possible to monitor NUXT using Prometheus.

Getting Started

  1. download latest version from release
  2. runas service
[Unit]
Description=NUXT Prometheus Exporter
After=network.target

[Service]
User=nuxt-exp
Group=nuxt-exp

ExecStart=/usr/local/bin/nuxt-prometheus-exporter
  1. add server middleware to nuxt server-middleware/prometheus.js, example with axios
import axios from 'axios';

export default function (req, res, next) {
  const start = +new Date();
  res.once('finish', () => {
    const end = +new Date();
    axios.post('http://localhost:45555/nodejs-requests', {
      route: req._parsedUrl.pathname ?? req.originalUrl,
      code: res.statusCode.toString(),
      method: req.method,
      date: start.toString(),
      duration: (end - start).toString(),
    }, {
      headers: {
        'Content-Type': 'application/json',
      },
    });
  });
  next();
}

all values must be string

by analogy, can be used with any other project

  1. enable server middleware in nuxt.config.js
{
    // ...
    serverMiddleware: [
        // ...
        '~/server-middleware/prometheus',
        // ...
    ]
    // ...
}