mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 01:58:41 -05:00
Pull 'running' history from graphite on dashboard init
This commit is contained in:
parent
0fccb48455
commit
362d080578
2 changed files with 58 additions and 3 deletions
|
|
@ -9,10 +9,32 @@ var stats_vcloud_running__svg = {};
|
|||
|
||||
var stats_vcloud_running__data__total = 0;
|
||||
|
||||
d3.json( running_url,
|
||||
d3.json( running_url+'?history=1',
|
||||
|
||||
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() {
|
||||
setTimeout( function() {
|
||||
|
||||
|
|
@ -62,8 +84,6 @@ d3.json( running_url,
|
|||
var stack = d3.layout.stack()
|
||||
.values( function( d ) { return d.values; } );
|
||||
|
||||
var stats_vcloud_running__data__stack = {};
|
||||
|
||||
if ( typeof stats_vcloud_running__data[ 'stack' ] === 'undefined' ) {
|
||||
stats_vcloud_running__data[ 'stack' ] = [];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -122,6 +122,41 @@ get '/dashboard/stats/vcloud/running' do
|
|||
result[pool['major']]['running'] = result[pool['major']]['running'].to_i + running.to_i
|
||||
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
|
||||
JSON.pretty_generate(result)
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue