Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

adonis5-prometheus

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

adonis5-prometheus - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

build/adonis-typings/prometheus.d.ts

1

build/adonis-typings/index.d.ts

@@ -0,1 +1,2 @@

/// <reference path="prometheus.d.ts" />
/// <reference path="PrometheusProvider.d.ts" />

@@ -0,1 +1,2 @@

/// <reference path="./prometheus.ts" />
/// <reference path="./PrometheusProvider.ts" />

3

build/adonis-typings/PrometheusProvider.d.ts
/// <reference types="@adonisjs/application/build/adonis-typings" />
/// <reference types="@adonisjs/http-server/build/adonis-typings" />
declare module '@ioc:Adonis/Prometheus' {
export * from 'prom-client';
}
declare module '@ioc:Adonis/Prometheus/Middlewares/CollectPerformanceMetrics' {

@@ -7,0 +4,0 @@ import { ApplicationContract } from '@ioc:Adonis/Core/Application';

/// <reference types="@adonisjs/http-server/build/adonis-typings" />
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext';
import { PrometheusConfig } from '@ioc:Adonis/Prometheus';
import { Metrics } from './Metrics';
export declare class CollectPerformanceMetrics {
protected metrics: Metrics;
protected config: any;
constructor(metrics: Metrics, config: any);
handle({ request, response, route }: HttpContextContract, next: () => Promise<void>): Promise<void>;
protected config: PrometheusConfig;
constructor(metrics: Metrics, config: PrometheusConfig);
handle(ctx: HttpContextContract, next: () => Promise<void>): Promise<void>;
private afterRequest;
/**
* Check if current route is excluded by the user in the configuration
*/
private isRouteExcluded;
}

@@ -9,3 +9,4 @@ "use strict";

}
async handle({ request, response, route }, next) {
async handle(ctx, next) {
const { request, response, route } = ctx;
const httpMetricOptions = this.config.httpMetric;

@@ -21,4 +22,3 @@ /**

const includeQueryParams = httpMetricOptions.includeQueryParams;
const excludedRoutes = httpMetricOptions.excludedRoutes || [];
if (!excludedRoutes.includes(route?.pattern)) {
if (this.isRouteExcluded(ctx)) {
let url = includeRouteParams ? request.url() : route?.pattern;

@@ -37,3 +37,3 @@ if (includeQueryParams && request.parsedUrl.query) {

* If the request fails with any error, we have to catch
* this errror, track metricks, then rethrow the error.
* this error, track metrics, then rethrow the error.
*/

@@ -68,3 +68,13 @@ try {

}
/**
* Check if current route is excluded by the user in the configuration
*/
isRouteExcluded(ctx) {
const excludedRoutes = this.config.httpMetric.excludedRoutes || [];
if (typeof excludedRoutes === 'function') {
return excludedRoutes(ctx);
}
return excludedRoutes.includes(ctx.route.pattern);
}
}
exports.CollectPerformanceMetrics = CollectPerformanceMetrics;

@@ -1,2 +0,4 @@

const prometheusConfig = {
import { PrometheusConfig } from '@ioc:Adonis/Prometheus'
const prometheusConfig: PrometheusConfig = {
/*

@@ -45,3 +47,3 @@ |--------------------------------------------------------------------------

prefix: '',
excludedRoutes: ["/metrics", "/health"],
excludedRoutes: ['/metrics', '/health'],
},

@@ -48,0 +50,0 @@

{
"name": "adonis5-prometheus",
"version": "0.0.4",
"version": "0.0.5",
"description": "Prometheus wrapper for Adonis 5",

@@ -13,2 +13,17 @@ "main": "build/providers/PrometheusProvider.js",

],
"scripts": {
"mrm": "mrm --preset=@adonisjs/mrm-preset",
"pretest": "npm run lint",
"test": "node .bin/test.js",
"lint": "eslint . --ext=.ts",
"clean": "del-cli build",
"copyfiles": "copyfiles \"templates/**/*.txt\" build",
"compile": "npm run lint && npm run clean && tsc",
"build": "npm run compile && npm run copyfiles",
"prepublishOnly": "npm run build",
"format": "prettier --write .",
"release": "np --message=\"🔖 %s\"",
"version": "npm run build",
"sync-labels": "github-label-sync --labels ./node_modules/@adonisjs/mrm-preset/gh-labels.json Julien-R44/adonis5-prometheus"
},
"repository": {

@@ -103,18 +118,3 @@ "type": "git",

}
},
"scripts": {
"mrm": "mrm --preset=@adonisjs/mrm-preset",
"pretest": "npm run lint",
"test": "node .bin/test.js",
"lint": "eslint . --ext=.ts",
"clean": "del build",
"copyfiles": "copyfiles \"templates/**/*.txt\" build",
"compile": "npm run lint && npm run clean && tsc",
"build": "npm run compile && npm run copyfiles",
"format": "prettier --write .",
"release": "np --message=\"🔖 %s\"",
"version": "npm run build",
"sync-labels": "github-label-sync --labels ./node_modules/@adonisjs/mrm-preset/gh-labels.json Julien-R44/adonis5-prometheus"
},
"readme": "<div align=\"center\">\n <img src=\"https://i.imgur.com/QZf8jrj.png\" width=\"300px\" /> \n <br/>\n <h3>Adonis5-Prometheus</h3>\n <p>Simple Prometheus Wrapper for Adonis</p>\n <a href=\"https://www.npmjs.com/package/adonis5-prometheus\">\n <img src=\"https://img.shields.io/npm/v/adonis5-prometheus.svg?style=for-the-badge&logo=npm\" />\n </a>\n <img src=\"https://img.shields.io/npm/l/adonis5-prometheus?color=blueviolet&style=for-the-badge\" />\n <img src=\"https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript\" />\n</div>\n\n## Installation\n```\nnpm i adonis5-prometheus\nnode ace configure adonis5-prometheus\n```\n\n## Usage\n\nA configuration file has been added in `config/prometheus.ts`.\n\nBy default the system metrics are collected ( `systemMetrics.enabled: true` ), so now you can call the endpoint `{{host}}/metrics` to get the measured metrics.\n\nHere is an example scrape_config to add to prometheus.yml:\n```yaml\nscrape_configs:\n - job_name: 'my-adonis-app'\n static_configs:\n - targets: ['my-adonis-app.com:3333']\n scrape_interval: 5s\n```\n\n## Built-in Metrics\nMetrics collected by Adonis5-prometheus middleware\n| Type | Name | Description |\n| --- | --- | --- |\n| Histogram | `adonis_http_request_durations` | Total time each HTTP requests takes. |\n| Gauge | `adonis_uptime_metrics` | Uptime performance of the application (1 = up, 0 = down) |\n| Counter | `adonis_throughput_metrics` | No. of request handled. |\n\nTo enable them, simply register the `CollectPerformanceMetrics` as the first item in the start/kernel.ts:\n```typescript\nServer.middleware.register([\n // Make it first in the list for reliable metrics.\n () => import('@ioc:Adonis/Prometheus/Middlewares/CollectPerformanceMetrics'),\n () => import('@ioc:Adonis/Core/BodyParser'),\n ...\n])\n```\nVerify if the metrics are enabled in the `config/prometheus.ts` file. You can also configure the metrics there.\n\n## Custom Metrics\n```typescript\n// Register your custom metrics in the separate file you want.\nexport const OrderMetric = new Prometheus.Counter({\n name: 'sent_orders',\n help: 'Total Orders Sent',\n})\n\n// OrderController.ts\nimport { OrderMetric } from 'App/Metrics'\n\nexport default class OrderController {\n public async store({ request }: HttpContextContract) {\n const order = await request.validate({ schema: OrderSchema })\n\n // ...\n OrderMetric.inc()\n // ...\n }\n}\n```\nWhen hitting `{{host}}/metrics` you will now get the following:\n```\n# HELP send_orders Total Orders Sent\n# TYPE send_orders counter\nsent_orders 2\n```\n\n## Grafana Dashboard\nA basic ready to use dashboard is available in the `grafana` folder.\n![https://i.imgur.com/mD0UMhA.png?1](https://i.imgur.com/mD0UMhA.png?1)\nIt includes :\n- Process CPU usage\n- Event loop lag\n- Node.JS version\n- Requests by second\n- Request volume rate by URL\n- Average response time\n- Response error rate by URL\n\nTo be fully functional, you need to enable `systemMetrics`, `httpMetric` and `throughputMetric` in the `config/prometheus.ts` file.\n\n## Documentation\nThis library is a wrapper for prom-client. The prom-client object can be imported with `import Prometheus from '@ioc:Adonis/Prometheus'`. Check out the [documentation](https://github.com/siimon/prom-client) for more information.\n\n## Acknowledgments\n- [tnkemdilim/adonis-prometheus](https://github.com/tnkemdilim/adonis-prometheus) - At first, I just adapted his library to support Adonis5.\n"
}
}
}

@@ -30,3 +30,3 @@ <div align="center">

static_configs:
- targets: ['my-adonis-app.com:3333']
- targets: ['my-adonis-app.com']
scrape_interval: 5s

@@ -33,0 +33,0 @@ ```

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc