Skip to content

Instantly share code, notes, and snippets.

@edasque
Created August 29, 2014 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save edasque/5cde12f185e0f3118ae4 to your computer and use it in GitHub Desktop.
Save edasque/5cde12f185e0f3118ae4 to your computer and use it in GitHub Desktop.
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 = "full.metric.name"
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 = payload.target
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
return
else
console.dir item
console.log command
)
else
console.dir error
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment