Skip to content

Instantly share code, notes, and snippets.

@jhaubrich
Last active December 18, 2015 00:58
Show Gist options
  • Save jhaubrich/5700295 to your computer and use it in GitHub Desktop.
Save jhaubrich/5700295 to your computer and use it in GitHub Desktop.
Graphite Sync knows when to expect the next value in graphite and polls *just-that-value* appending it to the dataset, removing the oldest value, and calls your callback with the updated data and date range.
# initialize graphite syncr
g = graphite_syncr {url: "/graphite/render?target=...",
inteval: 3000, #optional
callback: (data, sdate, edate) ->
update_plot(data) # calls with full dataset
dr(sdate,edate) # optional arguments sdate & edate
window.history.replaceState("",
"#{sdate} to #{edate}",
"/static/sog/iono/index.html?sdate="
+ sdate.toISOString().slice(0,16) #2013-05-01T05:00
+ "&edate="
+ edate.toISOString().slice(0,16))
}
# Methods
g.pause()
g.resume()
g.status() == {state: "paused" ? "polling"
next_poll: 213 #ms
url: "/graphite/render?target=..."
interval: 3000
callbak: <function blah blah>
#last_url, next_url, sdate, edate, last_polled
}
g.t_minus() == 213 # 213ms until next polling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment