A simple and easy to use module for Prometheus metric exporting.
Go to file
Holly Stubbs 553cff0165
fix spelling and add readme
2024-07-03 00:45:37 +01:00
interfaces Guages and Counters 2024-07-02 23:51:53 +01:00
objects fix spelling and add readme 2024-07-03 00:45:37 +01:00
test fix spelling and add readme 2024-07-03 00:45:37 +01:00
.gitignore Guages and Counters 2024-07-02 23:51:53 +01:00
.npmignore fix spelling and add readme 2024-07-03 00:45:37 +01:00
LICENSE Initial commit 2024-07-01 12:41:03 +01:00
README.md fix spelling and add readme 2024-07-03 00:45:37 +01:00
index.ts Guages and Counters 2024-07-02 23:51:53 +01:00
package-lock.json fix spelling and add readme 2024-07-03 00:45:37 +01:00
package.json fix spelling and add readme 2024-07-03 00:45:37 +01:00
tsconfig.json Guages and Counters 2024-07-02 23:51:53 +01:00

README.md

simple-prom

A simple and easy to use module for Prometheus metric exporting.

Usage

Create an instance of SimpleProm using SimpleProm.init

import SimpleProm from "simple-prom";

const instance = SimpleProm.init({});

See IConfig for config values to use in SimpleProm.init

Self hosted usage

SimpleProm can self host it's own http server for metrics polling, simple pass "selfHost: true" in the init config.

const instance = SimpleProm.init({
	selfHost: true,
	selfHostPort: 1337 // Optional, defaults to 9100
});

Use your own http server

Simply passing an empty config {} will get you what you want here, to get the metrics data call getMetricText() on your SimpleProm instance. You can then use it as you normally would with anything, in this example with express:

const instance = SimpleProm.init({});

req.get("/metrics", (req, res) => res.end(instance.getMetricText()));

Creating metrics

To add a metric call the addMetric method on your SimpleProm instance, passing in a metric object.

Currently supported metric types are:

Support for all metric types is planned.

Example for Counter:

const instance = SimpleProm.init({});

const httpRequests = instance.addMetric(new Counter("app_http_requests_handled"));
httpRequests.setHelpText("The number of HTTP requests handled since startup");
httpRequests.add(1);

Example for Gauge:

const instance = SimpleProm.init({});

const onlineUsers = instance.addMetric(new Gauge("app_online_users"));
onlineUsers.setHelpText("The number of online users");
onlineUsers.Value = 1234;