benbuckman/nodejs-munin — pull request #8 by AlexeyKupershtokh (2014-05-29 03:19:21+00:00)
Title: Add pullable stats

Currently we need to push data into nodejs-munin stats by calling setStat(key, val).
But taking into account that I don't know when exactly the stats are polled I need to set them regularly to mirror updates to original like this:
```js
setInterval(function() {
stats.setStat('uptime', process.uptime());
}, 1000);
```
or like this:
```js
function onUserConnected(user) {
this.online_users[user.uid] = user;
var n_online_users = Object.keys(this.online_users).length;
stats.setStat('online_users', n_online_users);
}
```

But since munin only polls these values once per 5 minutes this seems too much overhead.
What would be more appropriate is to be able to add stat sources as callbacks. So the example above would be written as:
```js
stats.initStat('uptime', config, options, function() {
return process.uptime();
});
```
and
```js
stats.initStat('online_users', config, options, function() {
return Object.keys(this.online_users).length;
}.bind(some_server));
```
Then, when munin-node polls the plugin, it will call the stat callbacks and return actual values.

Currently only synchronous callbacks are allowed.