mirror of
https://github.com/samsonjs/kwikemon.git
synced 2026-03-25 09:05:51 +00:00
rename some commands & update readme
This commit is contained in:
parent
f8a09636d1
commit
36930d666d
5 changed files with 76 additions and 54 deletions
74
Readme.md
74
Readme.md
|
|
@ -11,28 +11,27 @@ npm install -g kwikemon
|
|||
## Usage
|
||||
|
||||
$ kwikemond &
|
||||
$ curl -s localhost/nginx_status | grep Active | kwikemon nginx-connections
|
||||
$ curl -s localhost/nginx_status | grep Active | kwikemon write nginx-connections
|
||||
$ curl localhost:1111/nignx-connections
|
||||
Active connections: 316
|
||||
$ kwikemon foo bar
|
||||
$ kwikemon set foo bar
|
||||
$ curl localhost:1111/
|
||||
foo: bar
|
||||
nginx-connections: Active connections: 316
|
||||
|
||||
Here's how it works:
|
||||
|
||||
- call `kwikemon thing status` to set the text for the monitor named "thing"
|
||||
- call `kwikemon set thing status` to set the text for the monitor named "thing"
|
||||
- fire up the server, `kwikemond`, that serves up these monitors in a big list or individually
|
||||
|
||||
Alternatively:
|
||||
|
||||
- continuously pipe data to `kwikemon <name of thing you are watching>` on stdin
|
||||
- continuously pipe data to `kwikemon write <name of thing you are watching>` on stdin
|
||||
- every time a full line of text is received on stdin it becomes the new status for <name of thing you are watching>
|
||||
|
||||
To see everything `kwikemon` can do run it without arguments.
|
||||
To see everything `kwikemon` can do run `kwikemon help`.
|
||||
|
||||
# or with -h or --help
|
||||
$ kwikemon
|
||||
$ kwikemon help
|
||||
|
||||
This is very much a work in progress.
|
||||
|
||||
|
|
@ -44,12 +43,12 @@ You can use kwikemon as a library.
|
|||
var kwikemon = require('kiwkemon');
|
||||
|
||||
kwikemon.set('foo', 'bar', function(err) {
|
||||
kwikemon.fetch('foo', function(err, text) {
|
||||
kwikemon.get('foo', function(err, text) {
|
||||
console.log('foo = ' + text);
|
||||
});
|
||||
});
|
||||
|
||||
kwikemon.fetchAll(function(err, monitors) {
|
||||
kwikemon.getAll(function(err, monitors) {
|
||||
Object.keys(monitors).forEach(function (name) {
|
||||
console.log(name + ' = ' + monitors[name]);
|
||||
});
|
||||
|
|
@ -70,28 +69,14 @@ A monitor named `nginx` stores its data in the hash `kwikemon:monitor:nginx`. Ha
|
|||
are:
|
||||
|
||||
- text
|
||||
- expire
|
||||
- created
|
||||
- modified
|
||||
- updates
|
||||
|
||||
The list of all monitors is a set stored at `kwikemon:monitors`.
|
||||
|
||||
#### List
|
||||
|
||||
This is when you should clean out expired entries.
|
||||
|
||||
names = redis.smembers("kwikemon:monitors")
|
||||
monitors = {}
|
||||
for name in names:
|
||||
if redis.exists("kwikemon:monitor:$name"):
|
||||
monitors[name] = redis.hget("kwikemon:monitor:$name", "text")
|
||||
return monitors
|
||||
|
||||
#### Read
|
||||
|
||||
redis.hgetall("kwikemon:monitor:nginx")
|
||||
|
||||
#### Update
|
||||
#### Set
|
||||
|
||||
exists = redis.exists("kwikemon:monitor:nginx")
|
||||
if exists:
|
||||
|
|
@ -111,11 +96,48 @@ This is when you should clean out expired entries.
|
|||
# optional
|
||||
redis.expire("kwikemon:monitor:nginx", <ttl>)
|
||||
|
||||
#### Delete
|
||||
#### Get
|
||||
|
||||
redis.hgetall("kwikemon:monitor:nginx")
|
||||
|
||||
#### Remove
|
||||
|
||||
redis.del("kwikemon:monitor:nginx")
|
||||
redis.srem("kwikemon:monitors", "nginx")
|
||||
|
||||
#### Sweep
|
||||
|
||||
Clean out expired monitors. Call this before anything that relies on counting or iterating through all monitors.
|
||||
|
||||
for name in redis.smembers("kwikemon:monitors"):
|
||||
if not redis.exists("kwikemon:monitor:$name"):
|
||||
remove(name)
|
||||
|
||||
#### Count
|
||||
|
||||
Sweep before running a count.
|
||||
|
||||
sweep()
|
||||
redis.scard("kwikemon:monitors")
|
||||
|
||||
#### List names
|
||||
|
||||
Sweep before listing.
|
||||
|
||||
sweep()
|
||||
redis.smembers("kwikemon:monitors")
|
||||
|
||||
#### Get all
|
||||
|
||||
Sweep before geting all.
|
||||
|
||||
sweep()
|
||||
monitors = {}
|
||||
for name in list():
|
||||
if redis.exists("kwikemon:monitor:$name"):
|
||||
monitors[name] = get(name)
|
||||
return monitors
|
||||
|
||||
|
||||
## License
|
||||
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ function expire(name, ttl) {
|
|||
|
||||
function get(name) {
|
||||
if (name) {
|
||||
kwikemon.fetch(name, function(err, mon) {
|
||||
kwikemon.get(name, function(err, mon) {
|
||||
if (mon) {
|
||||
console.log(mon.text);
|
||||
process.exit(0);
|
||||
|
|
@ -82,7 +82,7 @@ function get(name) {
|
|||
}
|
||||
|
||||
function list() {
|
||||
kwikemon.fetchAll(function(err, monitors) {
|
||||
kwikemon.getAll(function(err, monitors) {
|
||||
Object.keys(monitors).forEach(function(name) {
|
||||
console.log(name + ':', monitors[name].text);
|
||||
});
|
||||
|
|
|
|||
26
kwikemon.js
26
kwikemon.js
|
|
@ -8,11 +8,11 @@ module.exports = {
|
|||
|
||||
// read
|
||||
, exists: callbackOptional(exists)
|
||||
, fetch: callbackOptional(fetch)
|
||||
, get: callbackOptional(get)
|
||||
, ttl: callbackOptional(ttl)
|
||||
, list: list
|
||||
, fetchAll: fetchAll
|
||||
, count: count
|
||||
, list: list
|
||||
, getAll: getAll
|
||||
|
||||
// remove
|
||||
, remove: callbackOptional(remove)
|
||||
|
|
@ -56,15 +56,15 @@ function redis(newRedis) {
|
|||
// that accepts the callback is returned, with the
|
||||
// rest of the arguments fixed (like bind).
|
||||
//
|
||||
// function fetch(id, cb) { db.fetch(id, cb); }
|
||||
// fetch = callbackOptional(fetch);
|
||||
// function get(id, cb) { db.get(id, cb); }
|
||||
// get = callbackOptional(get);
|
||||
//
|
||||
// function print(err, x) { if (err) throw err; console.log(x); }
|
||||
//
|
||||
// fetch(1, print);
|
||||
// get(1, print);
|
||||
//
|
||||
// var fetch1 = fetch(1);
|
||||
// fetch1(print);
|
||||
// var get1 = get(1);
|
||||
// get1(print);
|
||||
function callbackOptional(fn, ctx) {
|
||||
return function() {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
|
|
@ -135,7 +135,7 @@ function writer(name) {
|
|||
return le;
|
||||
}
|
||||
|
||||
function fetch(name, cb) {
|
||||
function get(name, cb) {
|
||||
redis().hgetall(k(name), cb);
|
||||
}
|
||||
|
||||
|
|
@ -202,20 +202,20 @@ function list(cb) {
|
|||
});
|
||||
}
|
||||
|
||||
function fetchAll(cb) {
|
||||
function getAll(cb) {
|
||||
var monitors = {};
|
||||
list(function(err, names) {
|
||||
if (err) return cb(err);
|
||||
var fetchers = names.sort().map(function(name) {
|
||||
var geters = names.sort().map(function(name) {
|
||||
return function(done) {
|
||||
fetch(name, function(err, text) {
|
||||
get(name, function(err, text) {
|
||||
if (err) return done(err);
|
||||
monitors[name] = text;
|
||||
done();
|
||||
});
|
||||
};
|
||||
});
|
||||
async.parallel(fetchers, function(err, _) {
|
||||
async.parallel(geters, function(err, _) {
|
||||
if (err) return cb(err);
|
||||
cb(null, monitors)
|
||||
});
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ function handleRequest(req, res) {
|
|||
name = name.replace(RegExp('\.' + type + '$'), '');
|
||||
}
|
||||
if (name) {
|
||||
kwikemon.fetch(name, function(err, text) {
|
||||
kwikemon.get(name, function(err, text) {
|
||||
if (err) {
|
||||
res.end('error: ' + (err.message || 'unknown'));
|
||||
return;
|
||||
|
|
@ -50,7 +50,7 @@ function handleRequest(req, res) {
|
|||
}
|
||||
// all
|
||||
else {
|
||||
kwikemon.fetchAll(function(err, monitors) {
|
||||
kwikemon.getAll(function(err, monitors) {
|
||||
if (err) {
|
||||
res.end('error: ' + (err.message || 'unknown'));
|
||||
return;
|
||||
|
|
|
|||
22
test.js
22
test.js
|
|
@ -19,7 +19,7 @@ describe("kwikemon", function() {
|
|||
describe("#set", function() {
|
||||
it("should set text", function(done) {
|
||||
kwikemon.set('foo', 'bar', function(err) {
|
||||
kwikemon.fetch('foo', function(err, mon) {
|
||||
kwikemon.get('foo', function(err, mon) {
|
||||
assert(mon.text == 'bar');
|
||||
done();
|
||||
});
|
||||
|
|
@ -28,7 +28,7 @@ describe("kwikemon", function() {
|
|||
|
||||
it("should overwrite text", function(done) {
|
||||
kwikemon.set('foo', 'baz', function(err) {
|
||||
kwikemon.fetch('foo', function(err, mon) {
|
||||
kwikemon.get('foo', function(err, mon) {
|
||||
assert(mon.text == 'baz');
|
||||
done();
|
||||
});
|
||||
|
|
@ -92,12 +92,12 @@ describe("kwikemon", function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe("#fetch", function() {
|
||||
it("should fetch the last text monitored", function(done) {
|
||||
describe("#get", function() {
|
||||
it("should get the last text monitored", function(done) {
|
||||
async.series([
|
||||
kwikemon.set('foo', 'bar')
|
||||
, kwikemon.set('foo', 'marcellus')
|
||||
, kwikemon.fetch('foo')
|
||||
, kwikemon.get('foo')
|
||||
],
|
||||
function(err, results) {
|
||||
var mon = results[2];
|
||||
|
|
@ -107,8 +107,8 @@ describe("kwikemon", function() {
|
|||
);
|
||||
});
|
||||
|
||||
it("should fetch null for non-existent monitors", function(done) {
|
||||
kwikemon.fetch('non-existent', function(err, mon) {
|
||||
it("should get null for non-existent monitors", function(done) {
|
||||
kwikemon.get('non-existent', function(err, mon) {
|
||||
assert(mon == null);
|
||||
done();
|
||||
});
|
||||
|
|
@ -116,7 +116,7 @@ describe("kwikemon", function() {
|
|||
});
|
||||
|
||||
describe("#ttl", function() {
|
||||
it("should fetch the last TTL set", function(done) {
|
||||
it("should get the last TTL set", function(done) {
|
||||
kwikemon.set('foo', 'bar', { ttl: 300 }, function(err) {
|
||||
kwikemon.ttl('foo', function(err, ttl) {
|
||||
assert(ttl <= 300);
|
||||
|
|
@ -144,13 +144,13 @@ describe("kwikemon", function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe("#fetchAll", function() {
|
||||
it("should fetch all monitors", function(done) {
|
||||
describe("#getAll", function() {
|
||||
it("should get all monitors", function(done) {
|
||||
async.series([
|
||||
kwikemon.set('a', '1')
|
||||
, kwikemon.set('b', '2')
|
||||
, kwikemon.set('c', '3')
|
||||
, kwikemon.fetchAll
|
||||
, kwikemon.getAll
|
||||
],
|
||||
function(err, results) {
|
||||
var monitors = results.pop()
|
||||
|
|
|
|||
Loading…
Reference in a new issue