Simple and pluggable business metrics. It makes internal reporting much easier.
Segment uses metrics as an internal API to power our dashboards, auto-updating spreadsheets, and other admin services.
var Metrics = require('metrics');
Metrics()
.every('5m', charges('stripe-key'))
.every('10m', subscriptions('stripe-key'))
.every('1h', helpscout('helpscout-key'))
.use(function (metrics) {
metrics.on('stripe charges last month', function (val) {
geckoboard('widget-id').number(val));
});
});
Plugins add their own metrics using keys like stripe charges last month
. Each company can customize their reporting by writing their own plugins.
The code above calculates revenue and support metrics that can then be visualized with a dashboard, like Geckoboard:
It's easy to get started: there's already plugins for Stripe, Helpscout, AWS, and others.
It separates data and views: split the raw data from how its presented.
It's dashboard agnostic: so you can use Geckoboard, Ducksboard, Leftronic, or your own internal dashboard.
It pushes you in the right direction: use Segment's metrics expertise to avoid the wrong metrics.
Its an internal metrics API: Segment uses the metrics-express plugin to serve our metrics to other internal services (like admin tools and auto-updating spreadsheets).
$ npm install segmentio/metrics
Metrics is super simple. Plugins write data into a key value store, and other plugins then send that data to dashboards or other reporting tools.
A plugin can learn about how much you're making on Stripe, and make that data available:
var stripe = require('stripe')(key);
module.exports = function (metrics) {
stripe.charges.list(function (err, charges) {
metrics.set('total charges', charges.length);
});
};
and another plugin can push the data to a geckoboard:
var geckoboard = require('geckobard')('api-key');
module.exports = function (metrics) {
metrics.on('total charges', geckoboard('widget-id').number);
}
and now you have your first dashboard.
Metrics()
.every('5m', charges)
.use(dashboard);
Existing plugins for metrics can tell you:
- metrics-aws-billing - how much your AWS hosting costs
- metrics-helpscout - how many active Helpscout support tickets you have, and who they're assigned to
- metrics-stripe-charges - how much money you're making every month (and today!)
- metrics-stripe-subscriptions - how much subscriptions you have, and how much recurring revenue you're generating
- metrics-express - serves your metrics as an HTTP API using an express subapp
It's normal for every company to care about different metrics. If your plugin can help others do easier reporting, pull request this Readme.md to add your own plugin to this list.
At its core, metrics is a simple key value store. Plugins put data into a hashtable, and other plugins then use that data to update dashboards, send emails, or really anything you want.
Create a new Metrics
instance.
Set a key
/ val
pair.
Get a value at key
.
Get a list of keys.
Add a metrics plugin to run on an interval
.
var metrics = new Metrics()
.every('5m', function (metrics) {
metrics.set('hours', new Date().getHours());
metrics.set('minutes', new Date().getMinutes());
});
Listen for when one or more keys become available.
var metrics = new Metrics()
.every('5m', function (metrics) {
metrics.set('hours', new Date().getHours());
metrics.set('minutes', new Date().getMinutes());
});
metrics.on('hours', 'minutes', function (h, m) {
console.log('time update: ' + h + ':' + m);
});
Add a plugin that consumes metrics data.
new Metrics()
.every('5m', function (metrics) {
metrics.set('hours', new Date().getHours());
metrics.set('minutes', new Date().getMinutes());
})
.use(function (metrics) {
metrics.on('hours', 'minutes', function (h, m) {
console.log('time update: ' + h + ':' + m);
});
});
WWWWWW||WWWWWW
W W W||W W W
||
( OO )__________
/ | \
/o o| MIT \
\___/||_||__||_|| *
|| || || ||
_||_|| _||_||
(__|__|(__|__|