Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
This will overwrite metrics data in Graphite. Proceed with caution. Look at and understand the different constants. Here there be dragons. You've been warned
_ = require('lodash')
request = require('request')
exec = require('child_process').exec
host = "your graphite host"
port = 2003
metric = ""
anomalous_data_url = "http://#{host}/render/?_salt=1409317188.361&target=#{metric}&from=00%3A45_20140828&format=json&until=04%3A11_20140829"
threshold = 50000
corrected_value = 14000
act = false
request(anomalous_data_url, (error, response, body) ->
if (!error)
payload = JSON.parse(body)[0]
metric =
datapoints = payload.datapoints
console.log "Metric: #{metric}"
outside_the_threshold = _.filter(datapoints, (item) -> item[0]>threshold)
console.log("#{outside_the_threshold.length} items outside the threshold")
_.each(outside_the_threshold, (item) ->
command = "/bin/echo '#{metric} #{corrected_value} #{item[1]}' | /usr/bin/nc #{host} #{port}"
if (act)
console.dir item
console.log command
exec command, (error, stdout, stderr) ->
console.log "stdout: " + stdout if stdout isnt ""
console.log "stderr: " + stderr if stderr isnt ""
console.log "exec error: " + error if error isnt null
console.dir item
console.log command
console.dir error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment