Skip to content

Commit

Permalink
do not require coffeescript to be installed globally
Browse files Browse the repository at this point in the history
  • Loading branch information
mjpizz committed Apr 3, 2012
1 parent 3946b1b commit 5cb03f5
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 42 deletions.
6 changes: 1 addition & 5 deletions README.md
Expand Up @@ -53,15 +53,11 @@ Easiest is installing hashmonitor globally:

$ sudo npm install -g hashmonitor

...you may also need to install coffee-script if you don't have it:

$ sudo npm install -g coffee-script

Then just run the HashMonitor using the default stdin/stdout:

$ hashmonitor

Once you are here, just type some fake log messages in:
Once you are here, just type some fake log messages into stdin:

hello #world
goodnight #moon
Expand Down
40 changes: 3 additions & 37 deletions bin/hashmonitor
@@ -1,38 +1,4 @@
#!/usr/bin/env coffee
#!/usr/bin/env node

HashMonitor = require('../lib/hashmonitor').HashMonitor
HttpAccessLogParser = require('../lib/inputs/httpaccess').HttpAccessLogParser

DEFAULT_MILLISECONDS_FOR_SINGLE_STATS_WINDOW = 30 * 1000

# Initialize the HashMonitor collector that will contain all the
# parsed log lines and calculated statistics.
monitor = new HashMonitor()

# Keep a list of pre-parsers
preParsers = []

# Parse most HTTP log formats into plaintext strings. This should
# be safe for non-HTTP log lines, but probably should make this configurable
# instead configurat
if '--parse-http-access' in process.argv
preParsers.push(new HttpAccessLogParser())

# Listen for data on standard input (default input for log lines).
# TODO: add other input options
process.stdin.resume()
process.stdin.setEncoding('utf8')
process.stdin.on 'data', (line) ->
for parser in preParsers
line = parser.parse(line)
monitor.parse(line)

# Periodically output the statistics for this monitor as JSON dictionaries
# so that other scripts can send these stats into other systems.
setInterval(
->
# TODO: add other output options
console.log(monitor.calculate())
monitor.reset()
, DEFAULT_MILLISECONDS_FOR_SINGLE_STATS_WINDOW
)
require('coffee-script')
require('../lib/commandline').run()
40 changes: 40 additions & 0 deletions lib/commandline.coffee
@@ -0,0 +1,40 @@
HashMonitor = require('./hashmonitor').HashMonitor
HttpAccessLogParser = require('./inputs/httpaccess').HttpAccessLogParser

DEFAULT_MILLISECONDS_FOR_SINGLE_STATS_WINDOW = 30 * 1000

run = ->

# Initialize the HashMonitor collector that will contain all the
# parsed log lines and calculated statistics.
monitor = new HashMonitor()

# Keep a list of pre-parsers
preParsers = []

# Parse most HTTP log formats into plaintext strings. This should
# be safe for non-HTTP log lines, but probably should make this configurable
# instead configurat
if '--parse-http-access' in process.argv
preParsers.push(new HttpAccessLogParser())

# Listen for data on standard input (default input for log lines).
# TODO: add other input options
process.stdin.resume()
process.stdin.setEncoding('utf8')
process.stdin.on 'data', (line) ->
for parser in preParsers
line = parser.parse(line)
monitor.parse(line)

# Periodically output the statistics for this monitor as JSON dictionaries
# so that other scripts can send these stats into other systems.
setInterval(
->
# TODO: add other output options
console.log(monitor.calculate())
monitor.reset()
, DEFAULT_MILLISECONDS_FOR_SINGLE_STATS_WINDOW
)

exports.run = run
19 changes: 19 additions & 0 deletions package.json
@@ -0,0 +1,19 @@
{
"name": "hashmonitor",
"version": "0.0.1",
"author": "Matt Pizzimenti",
"description": "Turn logs into metrics like a boss",
"repository": {
"url": "https://github.com/olark/hashmonitor"
},
"main": "lib/hashmonitor",
"dependencies": {
"coffee-script": "*"
},
"devDependencies": {
"nodeunit": "*"
},
"scripts": {
"prepublish": "coffee -c lib"
}
}

0 comments on commit 5cb03f5

Please sign in to comment.