Skip to content

Instantly share code, notes, and snippets.

@megastef
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save megastef/95d29b7de7d5d71ef07c to your computer and use it in GitHub Desktop.
Save megastef/95d29b7de7d5d71ef07c to your computer and use it in GitHub Desktop.
spm-metrics-js examples
// app.js generates login/logout events
var app = require('./app.js')
var os = require('os')
// create SPM client
var SPM = require('spm-metrics-js')
var spmClient = new SPM(process.env.SPM_TOKEN, 20000)
// Create a metrics object to count users
var userCounterMetric = spmClient.getCustomMetric({
// name of the metric
name: 'concurrentUser',
// aggregation type
aggregation: 'avg',
// filter value in SPM User Interface, e.g. hostname
filter1: os.hostname(),
// auto-save metrics in the given interval
interval: 30000})
// use metric as 'counter' object
var counter = userCounterMetric.counter()
// Hook the counter to your business logic
app.on('login', function (user, password) {counter.inc()})
app.on('logout', function (user) {counter.dec()})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment