Skip to content

Instantly share code, notes, and snippets.

@also
Created October 11, 2013 05:05
Show Gist options
  • Select an option

  • Save also/6929841 to your computer and use it in GitHub Desktop.

Select an option

Save also/6929841 to your computer and use it in GitHub Desktop.
fs = require 'fs'
_ = require 'underscore'
lead = require './dist/nodejs/node.js'
parser = lead.require 'graphite_parser'
dsl = lead.require 'dsl'
filename = process.argv[2]
s = fs.readFileSync filename, 'ascii'
strings = {}
calls = {}
metrics = {}
add = (a, k) ->
a[k] = (a[k] ? 0) + 1
collect = (o) ->
switch o.type
when 's'
add strings, o.values[0]
when 'f'
add calls, o.values[0]
for a in o.values[1...]
collect a
when 'q'
add metrics, o.values[0]
for target in s.trim().split '\n'
try
parsed = parser.parse target
#console.log JSON.stringify parsed
collect parsed
catch e
console.log target
console.log e
result = {strings, calls, metrics}
console.log result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment