Skip to content

Instantly share code, notes, and snippets.

@timgentry
Created March 17, 2017 14:20
Show Gist options
  • Save timgentry/ffc172472c508bd2ee5396c9e837c7e5 to your computer and use it in GitHub Desktop.
Save timgentry/ffc172472c508bd2ee5396c9e837c7e5 to your computer and use it in GitHub Desktop.
getDatapoints = function(json, metric) {
return json.find(function(d) {
return d.target == metric
}).datapoints
}
getProgress = function(graphite_url) {
params = jQuery.param({
from: '-20seconds',
until: '-20seconds',
target: 'stats.gauges.dev.importer.*.batch.*',
format: 'json',
_uniq: Date.now()
})
jQuery.get(graphite_url + "/render?" + params, function(data) {
batchid = getDatapoints(data, 'stats.gauges.dev.importer.1.batch.batchid')[0][0];
progress = getDatapoints(data, 'stats.gauges.dev.importer.1.batch.progress')[0][0];
working = getDatapoints(data, 'stats.gauges.dev.importer.1.batch.working')[0][0];
bar = jQuery('div.progress[data-monitor-importer=' + batchid + '] div.progress-bar');
bar.css('width', progress + '%').text(progress + '%');
bar.toggleClass('progress-bar-striped active', working == '1');
// $( ".result" ).html( data );
// alert( "Load was performed." );
});
setTimeout(function(){ getProgress(url); }, 10000);
}
url = 'http://localhost'
getProgress(url);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment