From 362d08057845b6e45e8cacb3fd1a7ec9869f9c38 Mon Sep 17 00:00:00 2001 From: Scott Schneider Date: Tue, 11 Feb 2014 15:11:43 -0800 Subject: [PATCH] Pull 'running' history from graphite on dashboard init --- public/lib/stats-vcloud-running.js | 26 +++++++++++++++++++--- vmware-host-pooler-api | 35 ++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/public/lib/stats-vcloud-running.js b/public/lib/stats-vcloud-running.js index cabb4d4..82368f7 100644 --- a/public/lib/stats-vcloud-running.js +++ b/public/lib/stats-vcloud-running.js @@ -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' ] = []; } diff --git a/vmware-host-pooler-api b/vmware-host-pooler-api index 84b78b7..283203a 100755 --- a/vmware-host-pooler-api +++ b/vmware-host-pooler-api @@ -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