Pull 'running' history from graphite on dashboard init

This commit is contained in:
Scott Schneider 2014-02-11 15:11:43 -08:00
parent 0fccb48455
commit 362d080578
2 changed files with 58 additions and 3 deletions

View file

@ -9,10 +9,32 @@ var stats_vcloud_running__svg = {};
var stats_vcloud_running__data__total = 0; var stats_vcloud_running__data__total = 0;
d3.json( running_url, d3.json( running_url+'?history=1',
function( stats_vcloud_running__data ) { function( stats_vcloud_running__data ) {
if ( typeof stats_vcloud_running__data[ 'stack' ] === 'undefined' ) {
stats_vcloud_running__data[ 'stack' ] = [];
}
var mytmphash = [];
for ( var c = 0; c < 500; c++ ) {
for ( var key in stats_vcloud_running__data ) {
if ( ! stats_vcloud_running__data[ key ][ 'history' ] ) {
continue;
}
if ( ! stats_vcloud_running__data[ key ][ 'history' ][ c ] ) {
mytmphash[ key ] = 0;
}
else {
mytmphash[ key ] = stats_vcloud_running__data[ key ][ 'history' ][ c ];
}
}
stats_vcloud_running__data[ 'stack' ].push( mytmphash );
}
( function tick() { ( function tick() {
setTimeout( function() { setTimeout( function() {
@ -62,8 +84,6 @@ d3.json( running_url,
var stack = d3.layout.stack() var stack = d3.layout.stack()
.values( function( d ) { return d.values; } ); .values( function( d ) { return d.values; } );
var stats_vcloud_running__data__stack = {};
if ( typeof stats_vcloud_running__data[ 'stack' ] === 'undefined' ) { if ( typeof stats_vcloud_running__data[ 'stack' ] === 'undefined' ) {
stats_vcloud_running__data[ 'stack' ] = []; stats_vcloud_running__data[ 'stack' ] = [];
} }

View file

@ -122,6 +122,41 @@ get '/dashboard/stats/vcloud/running' do
result[pool['major']]['running'] = result[pool['major']]['running'].to_i + running.to_i result[pool['major']]['running'] = result[pool['major']]['running'].to_i + running.to_i
end end
if ( params[:history] )
if ( config[:config]['graphite'] )
history ||= Hash.new
begin
buffer = open( 'http://'+config[:config]['graphite']+'/render?target=vcloud.running.*&from=-1hour&format=json' ).read
history = JSON.parse( buffer )
history.each do |pool|
if pool['target'] =~ /.*\.(.*)$/
pool['name'] = $1
pool['major'] = $1 if pool['name'] =~ /^(\w+)\-/
if ( result[pool['major']] )
pool['last'] = result[pool['major']]['running']
result[pool['major']]['history'] ||= Array.new
pool['datapoints'].each do |metric|
3.times do |n|
if ( metric[0] )
pool['last'] = metric[0].to_i
result[pool['major']]['history'].push( metric[0].to_i )
else
result[pool['major']]['history'].push( pool['last'] )
end
end
end
end
end
end
rescue
end
end
end
content_type :json content_type :json
JSON.pretty_generate(result) JSON.pretty_generate(result)
end end