mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
Clean up 'running' history-pulling code
This commit is contained in:
parent
18f139905a
commit
a8d3369684
2 changed files with 22 additions and 30 deletions
|
|
@ -17,22 +17,16 @@ d3.json( running_url+'?history=1',
|
||||||
stats_vcloud_running__data[ 'stack' ] = [];
|
stats_vcloud_running__data[ 'stack' ] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
var mytmphash = [];
|
for ( var key in stats_vcloud_running__data ) {
|
||||||
|
if ( stats_vcloud_running__data[ key ][ 'history' ] ) {
|
||||||
|
for ( var c = 0; c < stats_vcloud_running__data[ key ][ 'history' ].length; c++ ) {
|
||||||
|
if ( typeof stats_vcloud_running__data[ 'stack' ][ c ] === 'undefined' ) {
|
||||||
|
stats_vcloud_running__data[ 'stack' ][ c ] = {};
|
||||||
|
}
|
||||||
|
|
||||||
for ( var c = 0; c < 500; c++ ) {
|
stats_vcloud_running__data[ 'stack' ][ c ][ key ] = stats_vcloud_running__data[ key ][ 'history' ][ 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() {
|
||||||
|
|
|
||||||
|
|
@ -124,32 +124,30 @@ get '/dashboard/stats/vcloud/running' do
|
||||||
|
|
||||||
if ( params[:history] )
|
if ( params[:history] )
|
||||||
if ( config[:config]['graphite'] )
|
if ( config[:config]['graphite'] )
|
||||||
history ||= Hash.new
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
buffer = open( 'http://'+config[:config]['graphite']+'/render?target=vcloud.running.*&from=-1hour&format=json' ).read
|
buffer = open( 'http://'+config[:config]['graphite']+'/render?target=vcloud.running.*&from=-1hour&format=json' ).read
|
||||||
history = JSON.parse( buffer )
|
JSON.parse( buffer ).each do |pool|
|
||||||
|
|
||||||
history.each do |pool|
|
|
||||||
if pool['target'] =~ /.*\.(.*)$/
|
if pool['target'] =~ /.*\.(.*)$/
|
||||||
pool['name'] = $1
|
pool['name'] = $1
|
||||||
|
|
||||||
pool['major'] = $1 if pool['name'] =~ /^(\w+)\-/
|
pool['major'] = $1 if pool['name'] =~ /^(\w+)\-/
|
||||||
|
|
||||||
if ( result[pool['major']] )
|
result[pool['major']]['history'] ||= Array.new
|
||||||
pool['last'] = result[pool['major']]['running']
|
|
||||||
result[pool['major']]['history'] ||= Array.new
|
|
||||||
|
|
||||||
pool['datapoints'].each do |metric|
|
for i in 0..pool['datapoints'].length
|
||||||
3.times do |n|
|
if (
|
||||||
if ( metric[0] )
|
pool['datapoints'][i] and
|
||||||
pool['last'] = metric[0].to_i
|
pool['datapoints'][i][0]
|
||||||
result[pool['major']]['history'].push( metric[0].to_i )
|
)
|
||||||
else
|
pool['last'] = pool['datapoints'][i][0]
|
||||||
result[pool['major']]['history'].push( pool['last'] )
|
|
||||||
end
|
result[pool['major']]['history'][i] ||= 0
|
||||||
end
|
result[pool['major']]['history'][i] = result[pool['major']]['history'][i].to_i + pool['datapoints'][i][0].to_i
|
||||||
|
else
|
||||||
|
result[pool['major']]['history'][i] = result[pool['major']]['history'][i].to_i + pool['last'].to_i
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue
|
rescue
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue