prometheus-tracking
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -0,1 +1,4 @@ | ||
import { Counter } from './tracker.counter'; | ||
import { Gauge } from './tracker.gauge'; | ||
import { Histogram } from './tracker.historgram'; | ||
export declare class Tracker { | ||
@@ -14,4 +17,25 @@ private name; | ||
private constructor(); | ||
trackResponseTime(uri: string, method: string, status: number, seconds: number): void; | ||
trackRequest(uri: string, method: string, status: number, seconds: number): void; | ||
/** | ||
* creates a new counter metric | ||
* @param name name of the counter (used as metric key) | ||
* @param description helpful description for the metric | ||
* @param labels define a list of labels for this metric | ||
*/ | ||
createCounter(name: string, description: string, labels: string[]): Counter; | ||
/** | ||
* creates a new gauge metric | ||
* @param name name of the gauge (used as metric key) | ||
* @param description helpful description for the metric | ||
* @param labels define a list of labels for this metric | ||
*/ | ||
createGauge(name: string, description: string, labels: string[]): Gauge; | ||
/** | ||
* creates a new histogram metric | ||
* @param name name of the histogram (used as metric key) | ||
* @param description helpful description for the metric | ||
* @param labels define a list of labels for this metric | ||
*/ | ||
createHistogram(name: string, description: string, labels: string[]): Histogram; | ||
getMetrics(): any; | ||
} |
@@ -5,2 +5,5 @@ "use strict"; | ||
const client = require("prom-client"); | ||
const tracker_counter_1 = require("./tracker.counter"); | ||
const tracker_gauge_1 = require("./tracker.gauge"); | ||
const tracker_historgram_1 = require("./tracker.historgram"); | ||
const NS_PER_SEC = 1000000000; | ||
@@ -10,12 +13,4 @@ class Tracker { | ||
this.name = name; | ||
this.responseTime = new client.Histogram({ | ||
name: 'response_time_histogram', | ||
help: 'Response time histogram', | ||
labelNames: ['name', 'uri', 'method', 'status'], | ||
}); | ||
this.requestCounter = new client.Counter({ | ||
name: 'request_counter', | ||
help: 'Counter of all requests', | ||
labelNames: ['name', 'uri', 'method', 'status'], | ||
}); | ||
this.responseTime = this.createHistogram('response_time_histogram', 'Response time histogram', ['name', 'uri', 'method', 'status']); | ||
this.requestCounter = this.createCounter('request_counter', 'Counter of all requests', ['name', 'uri', 'method', 'status']); | ||
if (collectDefaultMetrics) { | ||
@@ -50,6 +45,33 @@ // Probe every 5th second. | ||
} | ||
trackResponseTime(uri, method, status, seconds) { | ||
trackRequest(uri, method, status, seconds) { | ||
this.responseTime.labels(this.name, uri, method, status.toString()).observe(seconds); | ||
this.requestCounter.labels(this.name, uri, method, status.toString()).inc(); | ||
} | ||
/** | ||
* creates a new counter metric | ||
* @param name name of the counter (used as metric key) | ||
* @param description helpful description for the metric | ||
* @param labels define a list of labels for this metric | ||
*/ | ||
createCounter(name, description, labels) { | ||
return new tracker_counter_1.Counter(name, description, labels); | ||
} | ||
/** | ||
* creates a new gauge metric | ||
* @param name name of the gauge (used as metric key) | ||
* @param description helpful description for the metric | ||
* @param labels define a list of labels for this metric | ||
*/ | ||
createGauge(name, description, labels) { | ||
return new tracker_gauge_1.Gauge(name, description, labels); | ||
} | ||
/** | ||
* creates a new histogram metric | ||
* @param name name of the histogram (used as metric key) | ||
* @param description helpful description for the metric | ||
* @param labels define a list of labels for this metric | ||
*/ | ||
createHistogram(name, description, labels) { | ||
return new tracker_historgram_1.Histogram(name, description, labels); | ||
} | ||
getMetrics() { | ||
@@ -56,0 +78,0 @@ return client.register.metrics(); |
{ | ||
"name": "prometheus-tracking", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "prometheus-tracking", | ||
@@ -5,0 +5,0 @@ "author": "", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
12786
13
345
2