Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Producer event emiting #56

Open
jokesterfr opened this issue Jun 19, 2013 · 3 comments
Open

Producer event emiting #56

jokesterfr opened this issue Jun 19, 2013 · 3 comments

Comments

@jokesterfr
Copy link

Hi there,
I've been trying some tests with Godot, while it's really handy to get it working with the standard examples (heartbeat case), I could not find any mention of customized events sent by a Godot producer.

Moar docs branch is helpful but lacks references in this domain, whereas the godot introducing entry on Nodejistu mention the ('service', 'cpu').

Could you please paste here some quick draft example ?
I could then try to fill the documentation, if you guys do not have time for now.

Many thanks

@jcrugzz
Copy link
Member

jcrugzz commented Jun 19, 2013

Hey @jokesterfr, I am glad you are interested in godot! The docs I've written so far are a decent reference for reactors, but on the producer end of things, I'd check out godot-producer by @jesusabdullah. I totally agree the doc coverage isn't there yet, I'm looking to fix that soon. Any help would greatly appreciated :).

Let me know if you have any other questions!

@jokesterfr
Copy link
Author

I ended up overriding the produce method, which is for me, less ugly than expected:

/*
 * A godot probe to retrieve the memory state
 * of a Linux system.
 */

var fs = require('fs')
  , godot = require('godot');

//
// Get a proper producer instance
//
var linuxSysCPU = godot.producer({
    host: 'monitor.foo.bar',
    service: 'server/health/cpu',
    description: 'CPU usage',
    tags: ['CPU','server'],
    ttl: 1000 * 30,
});

//
// Override data emission
//
linuxSysCPU.produce = function () {
    /**
     * Read a file and extract the last minute load average.
     *
     * /proc/loadavg may contain some datas like `0.43 0.62 0.52 1/519 7418`
     * first value is the load average of last minute, second val stand for 5mn, 
     * and third val for 15mn.
     */
    fs.readFile('/proc/loadavg', 'ascii', function(err, data) {
        if (err) throw err;
        var m = data.match(/^([\w\.]*)\s/);

        // Measure in %
        var measure = {
            cpuload: parseFloat(m[1], 10)
        };

        // Get current state
        var state = 'ok';
        if (measure.mem > 70 || measure.swap > 70) state = 'warning'
        else if (measure.mem > 90 || measure.swap > 90) state = 'critical'

        // Emit the event to reactor server
        this.emit('data', {
            host:        this.values.host,
            service:     this.values.service,
            state:       state,
            time:        Date.now(),
            description: this.values.description,
            tags:        this.values.tags,
            meta:        measure,
            metric:      this.values.metric,
            ttl:         this.values.ttl
        });
    }); 
};

But surely, I will have a look on @jesusabdullah work. Moreover, I feel the need to make my own sms service, to get something free internationally (Twilio cannot send sms from any European phone number, + it's expensive). I was thinking about porting gcsms from Python to NodeJS.

@obazoud
Copy link
Contributor

obazoud commented Jun 19, 2013

@jokesterfr If you are looking for procuders, have a look at https://github.com/godot-plugins.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants