Last active
March 3, 2018 23:41
-
-
Save sbimikesmullin/92b3c14904632c4abbff to your computer and use it in GitHub Desktop.
interpret stdin and output reports periodically throughout the stream
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
counters = {} | |
process.stdin.resume() | |
process.stdin.setEncoding('utf8') | |
process.stdin.on 'data', (chunk) -> | |
if (matches = `/ \[3\] \[ (.+?) \]: (\w+) cmd=(\w+)/`.exec(''+chunk)) isnt null | |
[ nil, cla, type, cmd ] = matches | |
counters["#{cla}:#{type}:#{cmd}"] ||= 0 | |
counters["#{cla}:#{type}:#{cmd}"] += 1 | |
#process.stdout.write chunk | |
#console.log [cla, type, cmd, counters] | |
setInterval((-> | |
s = [] | |
for k, v of counters | |
s.push [ k, v ] | |
s.sort((a,b) -> a[1] - b[1]) | |
s.reverse() | |
process.stdout.write "STATS: " | |
for v in s | |
process.stdout.write "#{v[1]} #{v[0]} " | |
process.stdout.write "\n\n" | |
), 3000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment