Skip to content

Commit

Permalink
Added cli tool
Browse files Browse the repository at this point in the history
  • Loading branch information
lbovet committed Jan 15, 2016
1 parent 3ee18f2 commit 93aa951
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 36 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
index.coffee
59 changes: 31 additions & 28 deletions index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -157,35 +157,38 @@ turtle = (config) ->
screen.key 'home', -> tryScroll length-1
screen.key 'end', -> tryScroll pos
api = {}
started = false
api.start = ->
t0 = Date.now()
setInterval ->
now = Date.now()
pos++
for title,acc of accumulators
for subTitle,sub of acc
series[title] = series[title] || {}
serie = series[title][subTitle] = series[title][subTitle] || []
contexts[title] = contexts[title] || {}
context = contexts[title][subTitle] = contexts[title][subTitle] || {}
last = series[title][subTitle][-1..]?[0] || 0
if sub.length
agg = config?.metrics?[subTitle]?.aggregator
agg = aggregators[agg] if not agg?.apply
agg = agg || aggregators.avg
value = agg sub, context
else
value = if config?.keep then last else 0
if not serie.length and pos > 1
for i in [0..pos-1]
serie.push 0
serie.push value
sub.splice 0
layout() if not graphers[title]?[subTitle]
graphers[title][subTitle] serie, styles[title]?[subTitle]
screen.render()
, config?.interval || 1000
return api
if not started
t0 = Date.now()
setInterval ->
now = Date.now()
pos++
for title,acc of accumulators
for subTitle,sub of acc
series[title] = series[title] || {}
serie = series[title][subTitle] = series[title][subTitle] || []
contexts[title] = contexts[title] || {}
context = contexts[title][subTitle] = contexts[title][subTitle] || {}
last = series[title][subTitle][-1..]?[0] || 0
if sub.length
agg = config?.metrics?[subTitle]?.aggregator
agg = aggregators[agg] if not agg?.apply
agg = agg || aggregators.avg
value = agg sub, context
else
value = if config?.keep then last else 0
if not serie.length and pos > 1
for i in [0..pos-1]
serie.push 0
serie.push value
sub.splice 0
layout() if not graphers[title]?[subTitle]
graphers[title][subTitle] serie, styles[title]?[subTitle]
screen.render()
, config?.interval || 1000
started = true
return api
api.metric = (one, two) ->
group = if two then one else ''
name = if two then two else one
Expand Down
36 changes: 28 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
{
"name": "turtle-race",
"version": "0.15.0",
"description": "",
"version": "1.0.0",
"description": "Real-time metric graphs in the terminal",
"author": "Laurent Bovet <[email protected]>",
"keywords": [
"terminal",
"console",
"graph",
"chart",
"metric",
"statistics",
"real-time",
"timeline",
"time series",
""
],
"repository": {
"type": "git",
"url": "https://github.com/lbovet/turtle-race"
},
"main": "index.js",
"dependencies": {
"blessed": "~0.1.81",
"chalk": "~1.1.1",
"zibar": "^1.0.9"
"bin": {
"turtle-race": "turtle-race.js"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"prepublish": "coffee -c index.coffee"
},
"author": "",
"dependencies": {
"blessed": "~0.1.81",
"chalk": "~1.1.1",
"minimist": "^1.2.0",
"split": "^1.0.0",
"zibar": "^1.0.9",
},
"license": "BSD-2-Clause"
}
22 changes: 22 additions & 0 deletions turtle-race.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env node
argv = require('minimist')(process.argv.slice(2));
config = {}
if(argv.c) {
config = JSON.parse(require('fs').readFileSync(argv.c, 'utf8'));
}
pattern = new RegExp(config.pattern or "([^\\.]*\\.)?"
turtle = require('./index')(config);
if(argv._[0] == '-') {
process.stdin.pipe(require('split')())
.on('data', function(line) {
turtle.start()
tokens = line.split(' ')
value = if tokens[1] isnt undefined then tokens[1] else tokens[0]
label = if tokens[1] isnt undefined then tokens[0] else ""
labelTokens = tokens[1].split(".")
turtle.metric line.split
})
} else {
process.stdout.write("Usage: zibar [-c config-file] [ - ] [ value1 [value2..]]\n");
process.exit(1);
}

0 comments on commit 93aa951

Please sign in to comment.