Coder Social home page Coder Social logo

unitech / godot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nodejitsu/godot

0.0 3.0 0.0 247 KB

Godot is a streaming real-time event processor based on Riemann written in Node.js

Home Page: http://github.com/nodejitsu/godot

License: MIT License

JavaScript 100.00%

godot's Introduction

godot -- AS : producer patch for dynamic metrics

Example for cpu client/server

client.js

var os = require('os');
var godot = require('godot');

godot.createClient({
    type: 'udp',
    producers: [
        // Producer which send loadavg of cpu 1 each sec
    	godot.producer({
	    host: 'app.server.com',
	    description : 'Main root server',
	    service: 'cpu',
	    metric : function() {
		return os.loadavg()[0] * 100
	    },
	    ttl: 1000
	}),
	// Producer for heartbeat
	godot.producer({
            host: 'app.server.com',
            service: 'app.server/health/heartbeat',
            ttl: 1000
      })
    ]
}).connect(1337);

server.js

var godot = require('godot');

var a = godot.createServer({
    type: 'udp',
    reactors: [
        // Reactor will print to console if cpu1 > 10
	godot.reactor()
	    .where('service', 'cpu')
	    .over(10)
	    .console(),
	// Reactor will print if the client is out
	godot.reactor()
	    .where('service', '*/health/heartbeat')
	    .expire(1000)
	    .console()	
    ]
}).listen(1337);

Notes

  • email module use sendgrid
  • original producer file is static

Official doc

Godot is a streaming real-time event processor based on Riemann written in Node.js

Usage

Here is a simple example of a Reactor server that will send an email to [email protected] if the Producer server for app.server fails to send a heartbeat after 60 seconds.

  var godot = require('../lib/godot');

  //
  // Reactor server which will email `[email protected]`
  // whenever any service matching /.*\/health\/heartbeat/
  // fails to check in after 60 seconds.
  //
  godot.createServer({
    //
    // Defaults to UDP
    //
    type: 'udp',
    reactors: [
      godot.reactor()
        .where('service', '*/health/heartbeat')
        .expire(1000 * 60)
        .email({ to: '[email protected]' })
    ]
  }).listen(1337);

  //
  // Producer client which sends events for the service
  // `app.server/health/heartbeat` every 15 seconds.
  //
  godot.createClient({
    //
    // Defaults to UDP
    //
    type: 'udp',
    producers: [
      godot.producer({
        host: 'app.server.com',
        service: 'app.server/health/heartbeat',
        ttl: 1000 * 15
      })
    ]
  }).connect(1337);

Events

Similar to Riemann, events in godot are simply JSON sent over UDP or TCP. Each event has these optional fields:

  {
    host:         "A hostname, e.g. 'api1', 'foo.com'"
    service:      "e.g. 'API port 8000 reqs/sec'",
    state:        "Any string less than 255 bytes, e.g. 'ok', 'warning', 'critical'",
    time:         "The time of the event, in unix epoch seconds",
    description:  "Freeform text",
    tags:         "Freeform list of strings, e.g. ['rate', 'fooproduct', 'transient']"
    metric:       "A number associated with this event, e.g. the number of reqs/sec."
    ttl:          "A floating-point time, in seconds, that this event is considered valid for."
  }

Reactors

Reactors in Godot are readable and writable Stream instances which consume Events and produce actions or aggregate data flow.

Primatives

There are several core Reactor primatives available in godot which can be composed to create more complex behavior:

  • .aggregate(): Aggregates metric property on events
  • .change(key0, key1, ...): Emits events in which any of key0 ... keyN have changed.
  • .email(options): Sends an email to the specified options.
  • .expire(ttl): Emits an event when no data is received after ttl milliseconds.
  • .forward(options): Forwards all events to a remote server located at options.host and options.port.
  • .sms(options): Sends an sms to the specified options.
  • .where(key, value)|.where(filters): Filters events based on a single key:value pair or a set of key:value filters.

Producers

Producers in Godot are readable Stream instances which produce Events. Events will be emitted by a given Producer every ttl milliseconds.

Tests

All tests are written in vows and can be run with npm:

  npm test

Copyright (C) 2012. Nodejitsu Inc.

godot's People

Contributors

dscape avatar indexzero avatar jcrugzz avatar mmalecki avatar obazoud avatar unitech avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.