NUXT Prometheus exporter makes it possible to monitor NUXT using Prometheus.
- download latest version from release
- runas service
[Unit]
Description=NUXT Prometheus Exporter
After=network.target
[Service]
User=nuxt-exp
Group=nuxt-exp
ExecStart=/usr/local/bin/nuxt-prometheus-exporter
- 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
- enable server middleware in
nuxt.config.js
{
// ...
serverMiddleware: [
// ...
'~/server-middleware/prometheus',
// ...
]
// ...
}