0.4.1 • Published 12 years ago

informant v0.4.1

Weekly downloads
20
License
-
Repository
github
Last release
12 years ago

Informant

Informant is a lightweight way to monitor server resources in real-time. It can be used as an Express.JS middleware or standalone. When running as middleware each request is logged to the provided store.

Viewing the realtime interface:

Navigate to

http://<server where you are running informant>:2222/
![Screenshot](https://github.com/base698/Informant/raw/master/static/screenshot.png)

How to Install

npm install informant

How to use

First, require informant:

var informant = require('informant');

If you are using it as middleware with Express:

var express = require('express');
var app = express.createServer();
app.use(informant.middleware());
informant.init();
app.listen(8080);

If you are using it as a standalone app:

cd <node_modules where informant installed>
 node run

Environment Variables

Setting these three environment variables effects the operation of informant:

INFORMANT_PORT         = 2222 # Port the server interface response (default is 2222)
INFORMANT_INTERVAL     = 5000 # Sample rate in milliseconds for data (default is 5000)
INFORMANT_MEM_STORAGE  = 2000 # Number of items the Memory Store will retain is 2000

Store API

The Store API is a simple API designed to persist data. If no store is supplied then the in memory store will be used.

Stores conform to this interface:

	cb = function(err,records) {}
	var store = {
		insert: function(record) {}
		find: function(query,cb) {}
		add_machine: function(record) {}
		get_machines: function(cb) {}
	}

The supplied stores are:

var informant = require('informant');
var mem_store = new informant.MemStore();
var mongo_store = new informant.MongoStore();

To use a store, pass it into the init method:

app.use(informant.middleware());
informant.init(mongo_store);

MemoryStore example:

var MemStore = function() {
   var env_var_mem = parseInt(process.env.INFORMANT_MEM_STORAGE); 
   var mem_storage = env_var_mem || 2000; 

   this.machines = [];
 
   console.log('Using MemStore for Storage with a history of '+mem_storage+' items.');
   this.mem = [];
   this.insert = function(rec) {
      this.mem.push(rec);
      if(this.mem.length>=mem_storage) {
         this.mem.shift();
      }
   };

   this.find = function(query,cb) {
      cb(null,this.mem);
   };

   this.add_machine = function(rec) {
      this.machines.push(rec);
   };

   this.get_machines = function(cb) {
      cb(null,this.machines);
   }


};