コード例 #1
0
ファイル: libvirt.py プロジェクト: tangyi1989/nova-monitor
 def stat_vm_info_from_libvirt(self):
     """
     Get instance statistic info from libvirtd then calculate 
     performance info by passed time.
     """
     current_time = timeutils.utcnow()
     vm_stats = self.libvirt_manager.get_all_doms_stats()
     inst_stats = vm_stats.copy()
     
     #NOTE 
     for inst_name in vm_stats.keys():
         
         inst_stat = vm_stats[inst_name]
         inst_last_stat = self.last_inst_stat[inst_name]
         collect_inst = inst_stats[inst_name]
         
         #NIC IO rate
         for nic in inst_stat['nic_stats'].keys():
             nic_stat = inst_stat['nic_stats'][nic]
             last_nic_stat = inst_last_stat['nic_stats'][nic]
             
             collect_inst['nic_stats'][nic]['rx_bytes_rate'] = \
                 utils.io_bytes_rate(last_nic_stat['rx_bytes'], 
                                      nic_stat['rx_bytes'],
                                      self.last_stat_time, current_time)
                 
             collect_inst['nic_stats'][nic]['tx_bytes_rate'] = \
                 utils.io_bytes_rate(last_nic_stat['tx_bytes'], 
                                      nic_stat['tx_bytes'],
                                      self.last_stat_time, current_time)
                 
         #DISK IO rate        
         for disk in inst_stat['disk_stats'].keys():
             disk_stat = inst_stat['disk_stats'][disk]
             last_disk_stat = inst_last_stat['disk_stats'][disk]
             
             collect_inst['disk_stats'][disk]['wr_bytes_rate'] = \
                 utils.io_bytes_rate(last_disk_stat['wr_bytes'], 
                                      disk_stat['wr_bytes'],
                                      self.last_stat_time, current_time)
                 
             collect_inst['disk_stats'][disk]['rd_bytes_rate'] = \
                 utils.io_bytes_rate(last_disk_stat['rd_bytes'], 
                                      disk_stat['rd_bytes'],
                                      self.last_stat_time, current_time)
                 
         #CPU percent
         last_cputime = inst_last_stat['overview']['cputime']
         cputime = inst_stat['overview']['cputime']
         ncpus = inst_stat['overview']['ncpus']
         collect_inst['overview']['cpu_percent'] = \
             utils.cpu_percent(last_cputime, cputime, self.last_stat_time, 
                               current_time, ncpus)
                 
     self.last_inst_stat = vm_stats
     self.last_stat_time = current_time
     
     return inst_stats
コード例 #2
0
        def _inner():
            if initial_delay:
                greenthread.sleep(initial_delay)

            try:
                while self._running:
                    start = timeutils.utcnow()
                    self.f(*self.args, **self.kw)
                    end = timeutils.utcnow()
                    if not self._running:
                        break
                    delay = interval - timeutils.delta_seconds(start, end)
                    if delay <= 0:
                        LOG.warn(_('task run outlasted interval by %s sec') %
                                 -delay)
                    greenthread.sleep(delay if delay > 0 else 0)
            except LoopingCallDone, e:
                self.stop()
                done.send(e.retvalue)