Revision 03ef4f36

View differences:

src/vmm_mad/remotes/vcenter/vcenter_driver.rb
1987 1987

  
1988 1988
        provider = pm.provider_summary [@vm].first
1989 1989
        refresh_rate = provider.refreshRate
1990
        max_samples = 0
1990 1991

  
1991 1992
        vmid = -1
1992 1993
        extraconfig_vmid = @vm.config.extraConfig.select{|val|
......
2006 2007
            one_vm = OpenNebula::VirtualMachine.new_with_id(vmid, OpenNebula::Client.new)
2007 2008
            one_vm.info
2008 2009
            stats = []
2010
            previous_nettx = 0
2011
            previous_netrx = 0
2012
            if one_vm["MONITORING/NETTX"]
2013
                previous_nettx = one_vm["MONITORING/NETTX"].to_i
2014
            end
2015
            if one_vm["MONITORING/NETRX"]
2016
                previous_netrx = one_vm["MONITORING/NETRX"].to_i
2017
            end
2009 2018

  
2010 2019
            if(one_vm["MONITORING/LAST_MON"] && one_vm["MONITORING/LAST_MON"].to_i != 0 )
2011 2020
                #Real time data stores max 1 hour. 1 minute has 3 samples
2012 2021
                interval = (Time.now.to_i - one_vm["MONITORING/LAST_MON"].to_i)
2013

  
2014 2022
                #If last poll was more than hour ago get 3 minutes,
2015 2023
                #else calculate how many samples since last poll
2016
                samples =  interval > 3600 ? 9 : (interval / refresh_rate) + 1
2017
                max_samples = samples > 0 ? samples : 1
2018

  
2019
                stats = pm.retrieve_stats(
2020
                    [@vm],
2021
                    ['net.transmitted','net.bytesRx','net.bytesTx','net.received',
2022
                    'virtualDisk.numberReadAveraged','virtualDisk.numberWriteAveraged',
2023
                    'virtualDisk.read','virtualDisk.write'],
2024
                    {interval:refresh_rate, max_samples: max_samples}
2025
                )
2024
                max_samples =  interval > 3600 ? 9 : (interval / refresh_rate) + 1
2026 2025
            else
2027 2026
                # First poll, get at least latest 3 minutes = 9 samples
2028
                stats = pm.retrieve_stats(
2029
                    [@vm],
2030
                    ['net.transmitted','net.bytesRx','net.bytesTx','net.received',
2031
                    'virtualDisk.numberReadAveraged','virtualDisk.numberWriteAveraged',
2032
                    'virtualDisk.read','virtualDisk.write'],
2033
                    {interval:refresh_rate, max_samples: 9}
2034
                )
2027
                max_samples = 9
2035 2028
            end
2036 2029

  
2030
            stats = pm.retrieve_stats(
2031
                [@vm],
2032
                ['net.transmitted','net.bytesRx','net.bytesTx','net.received',
2033
                'virtualDisk.numberReadAveraged','virtualDisk.numberWriteAveraged',
2034
                'virtualDisk.read','virtualDisk.write'],
2035
                {interval:refresh_rate, max_samples: max_samples}
2036
            )
2037

  
2038

  
2037 2039
            if stats.empty? || stats.first[1][:metrics].empty?
2038
                @nettx = 0
2039
                @netrx = 0
2040
                @nettx = 0 + previous_nettx
2041
                @netrx = 0 + previous_netrx
2040 2042
                @diskrdbytes = 0
2041 2043
                @diskwrbytes = 0
2042 2044
                @diskrdiops = 0
2043 2045
                @diskwriops = 0
2044 2046
            else
2045 2047
                metrics = stats.first[1][:metrics]
2046

  
2047 2048
                nettx_kbpersec = 0
2048
                if metrics['net.transmitted']
2049
                    metrics['net.transmitted'].each { |sample|
2050
                        nettx_kbpersec += sample
2051
                    }
2052
                end
2053

  
2054 2049
                netrx_kbpersec = 0
2055
                if metrics['net.bytesRx']
2056
                    metrics['net.bytesRx'].each { |sample|
2057
                        netrx_kbpersec += sample
2058
                    }
2059
                end
2050
                (0..max_samples-1).each { |index|
2051
                    tx = [0]
2052
                    rx = [0]
2053
                    tx << metrics['net.transmitted'][index] if metrics['net.transmitted']
2054
                    tx << metrics['net.bytesTx'][index] if metrics['net.bytesTx']
2055
                    rx << metrics['net.received'][index] if metrics['net.received']
2056
                    rx << metrics['net.bytesRx'][index] if metrics['net.bytesRx']
2057
                    nettx_kbpersec += tx.max
2058
                    netrx_kbpersec += rx.max
2059
                }
2060 2060

  
2061 2061
                read_kbpersec = 0
2062 2062
                if metrics['virtualDisk.read']
......
2086 2086
                    }
2087 2087
                end
2088 2088

  
2089
                @nettx = (nettx_kbpersec * 1024 * refresh_rate).to_i
2090
                @netrx = (netrx_kbpersec * 1024 * refresh_rate).to_i
2089
                @nettx = (nettx_kbpersec * 1000 * refresh_rate).to_i + previous_nettx
2090
                @netrx = (netrx_kbpersec * 1000 * refresh_rate).to_i + previous_netrx
2091 2091

  
2092 2092
                @diskrdiops = read_iops
2093 2093
                @diskwriops = write_iops

Also available in: Unified diff