Skip to content

Instantly share code, notes, and snippets.

@rmruano
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save rmruano/b3eaacc468223f268913 to your computer and use it in GitHub Desktop.

Select an option

Save rmruano/b3eaacc468223f268913 to your computer and use it in GitHub Desktop.
if (typeof getGraphiteValue=="undefined") {
var getGraphiteValue, reloadGraphiteValues;
getGraphiteValue = function(target, jsonUrl) {
var $target;
if (target instanceof $) {
$target = target;
} else {
$target = $(target);
}
$.ajax({
url: jsonUrl,
success: function(response) {
if (response && response instanceof Array && response.length>0 && response[0].hasOwnProperty('datapoints') && response[0].datapoints instanceof Array && response[0].datapoints.length>0) {
$target.html(response[0].datapoints[0][0]);
} else {
$target.html("Unexpected data");
}
},
error: function(response) {
$target.html("Error");
}
});
}
reloadGraphiteValues = function() {
$("[data-get-graphite-value*=http]").each(function(){
getGraphiteValue($(this), $(this).attr("data-get-graphite-value"));
});
}
setInterval(function(){
reloadGraphiteValues();
}, 30000);
reloadGraphiteValues();
}
// Example usage
/*
<div data-get-graphite-value='http://graphite.lab.vpn.minijuegos.com/render/?width=921&height=459&_salt=1372068496.48&target=alias(hitcount(stats.miniplay.minisite.pageviews.web.category.total%2C%2224h%22)%2C%22category%22)&from=-24h&yMin=0&title=PAGEVIEWS_PER_TYPE&format=json'></div>
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment