All Projects → shopyourway → metrics-js

shopyourway / metrics-js

Licence: MIT license
A reporting framework for data point information (measurements and time series) to aggregators like Graphite

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to metrics-js

Carbon Clickhouse
Graphite metrics receiver with ClickHouse as storage
Stars: ✭ 139 (+321.21%)
Mutual labels:  graphite
Moira
Realtime Alerting for Graphite
Stars: ✭ 222 (+572.73%)
Mutual labels:  graphite
opsbro
Ops Best friend
Stars: ✭ 37 (+12.12%)
Mutual labels:  graphite
Ohmgraphite
Export Open Hardware sensor data to Graphite / InfluxDB / Prometheus / Postgres / Timescaledb
Stars: ✭ 155 (+369.7%)
Mutual labels:  graphite
Kenshin
Kenshin: A time-series database alternative to Graphite Whisper with 40x improvement in IOPS
Stars: ✭ 203 (+515.15%)
Mutual labels:  graphite
Carbonapi
Implementation of graphite API (graphite-web) in golang
Stars: ✭ 243 (+636.36%)
Mutual labels:  graphite
Icinga2
Icinga is a monitoring system which checks the availability of your network resources, notifies users of outages, and generates performance data for reporting.
Stars: ✭ 1,670 (+4960.61%)
Mutual labels:  graphite
fossil
Fossil is a proxy for securing unencrypted Graphite metrics collection
Stars: ✭ 21 (-36.36%)
Mutual labels:  graphite
Graphite exporter
Server that accepts metrics via the Graphite protocol and exports them as Prometheus metrics
Stars: ✭ 217 (+557.58%)
Mutual labels:  graphite
nanotube
High-performance router for Graphite.
Stars: ✭ 56 (+69.7%)
Mutual labels:  graphite
Graphite
Development repository for the graphite cookbook
Stars: ✭ 160 (+384.85%)
Mutual labels:  graphite
Icingaweb2 Module Grafana
Grafana module for Icinga Web 2 (supports InfluxDB & Graphite)
Stars: ✭ 190 (+475.76%)
Mutual labels:  graphite
Icinga Vagrant
Vagrant boxes for Icinga 2, Icinga Web 2, modules, themes and integrations (Graphite, InfluxDB, Elastic, Graylog, etc.)
Stars: ✭ 248 (+651.52%)
Mutual labels:  graphite
Appmetrics
App Metrics is an open-source and cross-platform .NET library used to record and report metrics within an application.
Stars: ✭ 1,986 (+5918.18%)
Mutual labels:  graphite
dyndnsd
A small, lightweight and extensible DynDNS server written with Ruby and Rack.
Stars: ✭ 69 (+109.09%)
Mutual labels:  graphite
Glaucus
An independent Linux® distribution built from scratch
Stars: ✭ 130 (+293.94%)
Mutual labels:  graphite
Graphouse
Graphouse allows you to use ClickHouse as a Graphite storage.
Stars: ✭ 241 (+630.3%)
Mutual labels:  graphite
aerospike-graphite
Aerospike monitoring for Graphite - a community driven open source project
Stars: ✭ 13 (-60.61%)
Mutual labels:  graphite
promate
Graphite On VictoriaMetrics
Stars: ✭ 68 (+106.06%)
Mutual labels:  graphite
Netdata
Real-time performance monitoring, done right! https://www.netdata.cloud
Stars: ✭ 57,056 (+172796.97%)
Mutual labels:  graphite

Metrics

Metrics is a reporting framework for data point information (measurements and time series) to aggregators such as Graphite

Highlights

  • Time series reporting
  • Support pluggable reporters
  • Built in reporters:
    • Graphite
    • String
    • Console
    • InMemory (for testing)
  • Simple, easy to use API

Getting started

Installation

npm (scoped)

Configuration

Import metrics package:

const Metrics = require('@shopyourway/metrics').Metrics;

Initialize the metrics instance with the required reporters:

const stringReporter = new require('@shopyourway/metrics').StringReporter(metricString => {
	// Do something
});
const consoleReporter = new require('@shopyourway/metrics').ConsoleReporter();

const metrics = new Metrics([stringReporter, consoleReporter], errorHandler);

Reporting execution time

Use the Metrics instance to report execution time of a function:

metrics.space('users.get').meter(function(userIds, callback) {
	// read users from database
	callback(...);
});
  • You may use the space function to define the namespace key that will be used to aggregate the time
  • when you wish to meter a function, use the meter function and pass a function with you code into it. the meter function will run your code, while measuring the time it took to execute, and report it to the configured reporters

Note that the metrics is reported only after the callback is called.

Reporters

Metrics comes with several built-in reporters

Graphite

Reports metrics to a graphite server:

const metrics = require('@shopyourway/metrics').Metrics;

const graphiteHost = '1.1.1.1'; // Graphite server IP address
const graphitePort = 2003; // Optional - port number. Defaults to 2003
const spacePrefix = 'My.Project'; // Optional - prefix to all metrics spaces

const graphiteReporter = new require('@shopyourway/metrics').GraphiteReporter({
		host: graphiteHost,
		port: graphitePort,
		prefix: spacePrefix
	});

const metrics = new Metrics([graphiteReporter], errorHandler);

Console

Console reporter comes in handy when you need to debug metrics calls:

const Metrics = require('@shopyourway/metrics').Metrics;

const consoleReporter = new require('@shopyourway/metrics').ConsoleReporter();
	
const metrics = new Metrics([consoleReporter], errorHandler);

When a metrics will be reported, a message will appear in the terminal, that includes the key and the value reported.

String

const Metrics = require('@shopyourway/metrics').Metrics;
const fs = require('fs');

const stringReporter = new require('@shopyourway/metrics').StringReporter(metricString => {
	fs.appendFile('metrics.log', metricsString);
});
	
const metrics = new Metrics([stringReporter], errorHandler);

Here, StringReporter is used to build a log file from the metrics reports.

InMemory

InMemoryReporter can be used for testing purposed, in order to make sure your code reports metrics as expected.

const Metrics = require('@shopyourway/metrics').Metrics;

const metricsStorage = [];

const memoryReporter = new require('@shopyourway/metrics').InMemoryReporter(metricsStorage);
	
const metrics = new Metrics([memoryReporter], errorHandler);

When a metric is reported, an object with key and value properties is pushed to the array.
Then, the array can be used in order to validate the report.

Building new reporters

Metrics support creating new reports acccording to an application needs.

A reporter must contain a method called report. The method gets the reported key and value.

For example, lets see how to implement a reporter for redis:

const client = require('redis').createClient();

module.exports = function RedisReporter(channel) {
  this.report = function(key, value) {
    client.publish(channel, JSON.stringify({ key: key, value: value }));
  }
};

The new reporter will pusblish a message to a specified channel in redis when a metric is reported.

Development

How to contribute

We encorage contribution via pull requests on any feature you see fit.

When submitting a pull request make sure to do the following:

  • Check that new and updated code follows OhioBox existing code formatting and naming standard
  • Run all unit and integration tests to ensure no existing functionality has been affected
  • Write unit or integration tests to test your changes. All features and fixed bugs must have tests to verify they work Read GitHub Help for more details about creating pull requests

Running tests

To run tests, in command line simply run npm test

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].