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

@opencensus/exporter-prometheus

Package Overview
Dependencies
Maintainers
7
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opencensus/exporter-prometheus - npm Package Compare versions

Comparing version 0.0.7 to 0.0.8

23

build/src/prometheus-stats.d.ts

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

/**
* Port number to Prometheus server
* Port number for Prometheus exporter server
* Default registered port is 9464:

@@ -27,6 +27,8 @@ * https://github.com/prometheus/prometheus/wiki/Default-port-allocations

port?: number;
/** Define if the Prometheus server will be started - default false */
/**
* Define if the Prometheus exporter server will be started - default false
*/
startServer?: boolean;
}
/** Format and sends Stats to Prometheus */
/** Format and sends Stats to Prometheus exporter */
export declare class PrometheusStatsExporter implements StatsEventListener {

@@ -45,2 +47,3 @@ static readonly DEFAULT_OPTIONS: {

private registry;
private static readonly RESERVED_HISTOGRAM_LABEL;
constructor(options: PrometheusExporterOptions);

@@ -77,7 +80,11 @@ /**

/**
* Get a string unit type based on measure unit
* @param view View used to get the unit
* Sanitize metric name
* @param name string The name of the metric.
*/
private getUnit(view);
private sanitizePrometheusMetricName(name);
/**
* Throws an error labels contain "le" label name in histogram label names.
*/
private validateDisallowedLeLabelForHistogram(labels);
/**
* Get the boundaries from buckets

@@ -89,7 +96,7 @@ * @param view View used to get the DistributionData

/**
* Start the Prometheus server
* Start the Prometheus exporter server
*/
startServer(callback?: () => void): void;
/**
* Stop the Prometheus server
* Stop the Prometheus exporter server
* @param callback

@@ -96,0 +103,0 @@ */

@@ -21,3 +21,3 @@ "use strict";

const prom_client_1 = require("prom-client");
/** Format and sends Stats to Prometheus */
/** Format and sends Stats to Prometheus exporter */
class PrometheusStatsExporter {

@@ -66,2 +66,3 @@ constructor(options) {

}
const labels = view.getColumns();
// Create a new metric if there is no one

@@ -71,3 +72,3 @@ const metricObj = {

help: view.description,
labelNames: view.getColumns()
labelNames: labels
};

@@ -84,6 +85,7 @@ // Creating the metric based on aggregation type

case core_1.AggregationType.DISTRIBUTION:
this.validateDisallowedLeLabelForHistogram(labels);
const distribution = {
name: metricName,
help: view.description,
labelNames: view.getColumns(),
labelNames: labels,
buckets: this.getBoundaries(view, tags)

@@ -130,27 +132,31 @@ };

getPrometheusMetricName(view) {
return `${this.prefix}_${view.name}_${this.getUnit(view)}`;
let metricName;
if (this.prefix) {
metricName = `${this.prefix}_${view.name}`;
}
else {
metricName = view.name;
}
return this.sanitizePrometheusMetricName(metricName);
}
/**
* Get a string unit type based on measure unit
* @param view View used to get the unit
* Sanitize metric name
* @param name string The name of the metric.
*/
getUnit(view) {
switch (view.measure.unit) {
case core_1.MeasureUnit.UNIT:
return 'total';
case core_1.MeasureUnit.BYTE:
return 'bytes';
case core_1.MeasureUnit.KBYTE:
return 'kbytes';
case core_1.MeasureUnit.SEC:
return 'seconds';
case core_1.MeasureUnit.MS:
return 'milliseconds';
case core_1.MeasureUnit.NS:
return 'nanoseconds';
default:
return '';
}
sanitizePrometheusMetricName(name) {
// replace all characters other than [A-Za-z0-9_].
return name.replace(/\W/g, '_');
}
/**
* Throws an error labels contain "le" label name in histogram label names.
*/
validateDisallowedLeLabelForHistogram(labels) {
labels.forEach(label => {
if (label === PrometheusStatsExporter.RESERVED_HISTOGRAM_LABEL) {
throw new Error(`${PrometheusStatsExporter
.RESERVED_HISTOGRAM_LABEL} is a reserved label keyword`);
}
});
}
/**
* Get the boundaries from buckets

@@ -165,3 +171,3 @@ * @param view View used to get the DistributionData

/**
* Start the Prometheus server
* Start the Prometheus exporter server
*/

@@ -182,3 +188,3 @@ startServer(callback) {

/**
* Stop the Prometheus server
* Stop the Prometheus exporter server
* @param callback

@@ -198,5 +204,7 @@ */

contentType: 'text/plain; text/plain; version=0.0.4; charset=utf-8',
prefix: 'opencensus'
prefix: ''
};
// Histogram cannot have a label named 'le'
PrometheusStatsExporter.RESERVED_HISTOGRAM_LABEL = 'le';
exports.PrometheusStatsExporter = PrometheusStatsExporter;
//# sourceMappingURL=prometheus-stats.js.map
{
"name": "@opencensus/exporter-prometheus",
"version": "0.0.7",
"version": "0.0.8",
"description": "OpenCensus Exporter Prometheus allows user to send collected stats to Prometheus",

@@ -21,3 +21,4 @@ "main": "build/src/index.js",

"nodejs",
"tracing",
"metrics",
"stats",
"profiling"

@@ -43,7 +44,7 @@ ],

"@types/express": "^4.11.1",
"@types/mocha": "^2.2.48",
"@types/mocha": "^5.2.5",
"@types/nock": "^9.1.3",
"@types/node": "^9.4.7",
"@types/node": "^10.12.12",
"axios": "^0.18.0",
"gts": "^0.5.1",
"gts": "^0.9.0",
"mocha": "^5.0.4",

@@ -53,7 +54,7 @@ "ncp": "^2.0.0",

"nyc": "^11.8.0",
"ts-node": "^4.0.0",
"ts-node": "^7.0.1",
"typescript": "~2.7.2"
},
"dependencies": {
"@opencensus/core": "^0.0.7",
"@opencensus/core": "^0.0.8",
"express": "^4.16.3",

@@ -60,0 +61,0 @@ "prom-client": "^11.1.1"

# OpenCensus Prometheus Exporter for Node.js
[![Gitter chat][gitter-image]][gitter-url]
[![Gitter chat][gitter-image]][gitter-url] ![Node Version][node-img] [![NPM Published Version][npm-img]][npm-url] ![dependencies Status][dependencies-status] ![devDependencies Status][devdependencies-status] ![Apache License][license-image]

@@ -12,3 +12,3 @@ The OpenCensus Prometheus Exporter allows the user to send collected stats with [OpenCensus Node.js](https://github.com/census-instrumentation/opencensus-node) to Prometheus.

```bash
npm install @opencensus/nodejs
npm install @opencensus/core
npm install @opencensus/exporter-prometheus

@@ -19,34 +19,51 @@ ```

Instance the exporter on your application. For javascript:
Instance the exporter on your application.
For javascript:
```javascript
var tracing = require('@opencensus/nodejs');
var prometheus = require('@opencensus/exporter-prometheus');
const { Stats } = require('@opencensus/core');
const { PrometheusStatsExporter } = require('@opencensus/exporter-prometheus');
var exporter = new prometheus.PrometheusTraceExporter();
tracing.registerExporter(exporter).start();
// Add your port and startServer to the Prometheus options
const exporter = new PrometheusStatsExporter({
port: 9464,
startServer: false
});
```
Similarly for Typescript:
Now, register the exporter.
```typescript
import * as tracing from '@opencensus/nodejs';
import { PrometheusTraceExporter } from '@opencensus/exporter-prometheus';
```javascript
// Our Stats manager
const stats = new Stats();
const exporter = new PrometheusTraceExporter();
// Pass the created exporter to Stats
stats.registerExporter(exporter);
// Run the server
exporter.startServer(function callback() {
// Callback
});
```
Now, register the exporter and start tracing.
Similarly for Typescript (Since the source is written in TypeScript):
```typescript
import { PrometheusStatsExporter } from '@opencensus/exporter-prometheus';
import { Stats } from '@opencensus/core';
```javascript
tracing.start({'exporter': exporter});
```
// Add your port and startServer to the Prometheus options
const options = {port: 9464, startServer: false};
const exporter = new PrometheusStatsExporter(options);
or
// Our Stats manager
const stats = new Stats();
```javascript
tracing.registerExporter(exporter).start();
// Pass the created exporter to Stats
stats.registerExporter(exporter);
```
Viewing your metrics:
With the above you should now be able to navigate to the Prometheus UI at: <http://localhost:9464/metrics>
## Useful links

@@ -60,1 +77,12 @@ - To learn more about Prometheus, visit: <https://prometheus.io/>

[gitter-url]: https://gitter.im/census-instrumentation/lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
[npm-url]: https://www.npmjs.com/package/@opencensus/exporter-prometheus
[npm-img]: https://badge.fury.io/js/%40opencensus%2Fexporter-prometheus.svg
[node-img]: https://img.shields.io/node/v/@opencensus/exporter-prometheus.svg
[license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat
[dependencies-status]: https://david-dm.org/census-instrumentation/opencensus-node/status.svg?path=packages/opencensus-exporter-prometheus
[devdependencies-status]:
https://david-dm.org/census-instrumentation/opencensus-node/dev-status.svg?path=packages/opencensus-exporter-prometheus
## LICENSE
Apache License 2.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