statware
Node.js status monitoring wares.
var statware = require("statware")
var stats = statware()
stats.installProcessInfo()
stats.installSystemInfo()
stats.registerHelper(function (status, next) {
status.foo = (new Date()).toString()
next()
})
stats.set("cat", "meow")
stats.increment("lines")
stats.increment("lines")
stats.increment("lines")
var windowed = stats.windowedStat("games", 10)
windowed.push(50)
windowed.push(100)
windowed.push(75)
var s = stats.addStat("ht")
s.update(40)
s.update(1000)
s.update(352)
s.update(550)
var ns = stats.namespace("ns")
ns.increment("foo")
stats.getStats(function (metrics) {
console.log(metrics)
})
API
Statware([initial])
Create a statware stats instance, with optional initial value object of initial
.
statwareInstance.getStats(callback)
Fetch the stats object. The callback
should be of form callback(statsObject)
where statsObject
is a pure Js object with the statware internal stats.
statwareInstance.registerHelper(helper)
Register an asynchronous helper function to be called whenever stats.getStats(cb)
is called. The helper must be in the form of helper(statsObject, next)
and must call next()
one time. The statsObject
is the internal stats object from statware
and can be mutated to add, remove, or modify values. Returns itself for chaining.
statwareInstance.set(key, value)
Set a key to a value explicitly
statwareInstance.increment(key)
Update an incrementing key
var fixedArray = statwareInstance.windowedStat(key, windowSize)
Create a FixedArray at key
that will have n, min, max, mean reported for it at each getStats()
call.
var statsIncremental = statwareInstance.addStat(key)
Create a stats-incremental instance that will report getAll()
every time getStats()
is run.
var namespace = statwareInstance.namespace(name)
Create a toplevel namespace inside the statInstance that behaves almost identically to statwareInstance
except it cannot registerHelpers
or define deeper namespaces.
stawareInstance.installProcessInfo()
Register a pre-defined helper that collects a set of process-related information.
statwareInstance.installSystemInfo()
Register a pre-defined helper that collects a set of system-related information.
LICENSE
MIT