@storyous/monitoring
v1.1.2
Published
## Usage of Prometheus
Downloads
126
Keywords
Readme
monitoring
Usage of Prometheus
import Koa from 'koa';
import { middleware, prometheus } from '@storyous/monitoring';
// Register middlewate into Koa app
const app = new Koa();
app.use(middleware.getRouterAuthorizationMiddleware('token'));
app.use(middleware.getRequestDurationMetricsMiddleware({ appName: 'test', env: 'testing' }));
// Initialize of Prometheus
prometheus.init({ url: 'https://my.prometheus.com', appName: 'test', pushInterval: 1 });
// Manualy truncate metrics
await prometheus.truncatePushGateway();
Usage of UsageTracker
import { createLogger } from 'winston';
import KoaRouter from 'koa-router';
import { init, watchLineUsage, watchUrlUsage } from '@storyous/monitoring';
// Track usage of all routes in current router
const router = new KoaRouter();
watchUrlUsage(router);
// Init the usage Tracker to periodically log information about usage
init(createLogger(), { publishIntervalInSeconds: 1, allowsObjectsInExtraData: true });
// Whenever this is executed, it remembers it and later log that the `name` was called
watchLineUsage('name', 'matricsName', 'matricsValue');