~ubuntu-branches/ubuntu/quantal/nova/quantal-proposed

« back to all changes in this revision

Viewing changes to nova/compute/monitor.py

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2011-01-21 11:48:06 UTC
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: james.westby@ubuntu.com-20110121114806-v8fvnnl6az4m4ohv
Tags: upstream-2011.1~bzr597
ImportĀ upstreamĀ versionĀ 2011.1~bzr597

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
"""
26
26
 
27
27
import datetime
28
 
import logging
29
28
import os
30
 
import sys
31
29
import time
32
30
 
33
31
import boto
34
32
import boto.s3
35
33
import rrdtool
36
 
from twisted.internet import defer
37
34
from twisted.internet import task
38
35
from twisted.application import service
39
36
 
40
37
from nova import flags
 
38
from nova import log as logging
41
39
from nova.virt import connection as virt_connection
42
40
 
43
41
 
91
89
utcnow = datetime.datetime.utcnow
92
90
 
93
91
 
 
92
LOG = logging.getLogger('nova.compute.monitor')
 
93
 
 
94
 
94
95
def update_rrd(instance, name, data):
95
96
    """
96
97
    Updates the specified RRD file.
255
256
        Updates the instances statistics and stores the resulting graphs
256
257
        in the internal object store on the cloud controller.
257
258
        """
258
 
        logging.debug('updating %s...', self.instance_id)
 
259
        LOG.debug(_('updating %s...'), self.instance_id)
259
260
 
260
261
        try:
261
262
            data = self.fetch_cpu_stats()
262
263
            if data != None:
263
 
                logging.debug('CPU: %s', data)
 
264
                LOG.debug('CPU: %s', data)
264
265
                update_rrd(self, 'cpu', data)
265
266
 
266
267
            data = self.fetch_net_stats()
267
 
            logging.debug('NET: %s', data)
 
268
            LOG.debug('NET: %s', data)
268
269
            update_rrd(self, 'net', data)
269
270
 
270
271
            data = self.fetch_disk_stats()
271
 
            logging.debug('DISK: %s', data)
 
272
            LOG.debug('DISK: %s', data)
272
273
            update_rrd(self, 'disk', data)
273
274
 
274
275
            # TODO(devcamcar): Turn these into pool.ProcessPool.execute() calls
285
286
            graph_disk(self, '1w')
286
287
            graph_disk(self, '1m')
287
288
        except Exception:
288
 
            logging.exception('unexpected error during update')
 
289
            LOG.exception(_('unexpected error during update'))
289
290
 
290
291
        self.last_updated = utcnow()
291
292
 
309
310
        self.cputime = float(info['cpu_time'])
310
311
        self.cputime_last_updated = utcnow()
311
312
 
312
 
        logging.debug('CPU: %d', self.cputime)
 
313
        LOG.debug('CPU: %d', self.cputime)
313
314
 
314
315
        # Skip calculation on first pass. Need delta to get a meaningful value.
315
316
        if cputime_last_updated == None:
319
320
        d = self.cputime_last_updated - cputime_last_updated
320
321
        t = d.days * 86400 + d.seconds
321
322
 
322
 
        logging.debug('t = %d', t)
 
323
        LOG.debug('t = %d', t)
323
324
 
324
325
        # Calculate change over time in number of nanoseconds of CPU time used.
325
326
        cputime_delta = self.cputime - cputime_last
326
327
 
327
 
        logging.debug('cputime_delta = %s', cputime_delta)
 
328
        LOG.debug('cputime_delta = %s', cputime_delta)
328
329
 
329
330
        # Get the number of virtual cpus in this domain.
330
331
        vcpus = int(info['num_cpu'])
331
332
 
332
 
        logging.debug('vcpus = %d', vcpus)
 
333
        LOG.debug('vcpus = %d', vcpus)
333
334
 
334
335
        # Calculate CPU % used and cap at 100.
335
336
        return min(cputime_delta / (t * vcpus * 1.0e9) * 100, 100)
351
352
                rd += rd_bytes
352
353
                wr += wr_bytes
353
354
            except TypeError:
354
 
                logging.error('Cannot get blockstats for "%s" on "%s"',
355
 
                              disk, self.instance_id)
 
355
                LOG.error(_('Cannot get blockstats for "%s" on "%s"'),
 
356
                          disk, self.instance_id)
356
357
                raise
357
358
 
358
359
        return '%d:%d' % (rd, wr)
373
374
                rx += stats[0]
374
375
                tx += stats[4]
375
376
            except TypeError:
376
 
                logging.error('Cannot get ifstats for "%s" on "%s"',
377
 
                              interface, self.instance_id)
 
377
                LOG.error(_('Cannot get ifstats for "%s" on "%s"'),
 
378
                          interface, self.instance_id)
378
379
                raise
379
380
 
380
381
        return '%d:%d' % (rx, tx)
408
409
        try:
409
410
            conn = virt_connection.get_connection(read_only=True)
410
411
        except Exception, exn:
411
 
            logging.exception('unexpected exception getting connection')
 
412
            LOG.exception(_('unexpected exception getting connection'))
412
413
            time.sleep(FLAGS.monitoring_instances_delay)
413
414
            return
414
415
 
416
417
        try:
417
418
            self.updateInstances_(conn, domain_ids)
418
419
        except Exception, exn:
419
 
            logging.exception('updateInstances_')
 
420
            LOG.exception('updateInstances_')
420
421
 
421
422
    def updateInstances_(self, conn, domain_ids):
422
423
        for domain_id in domain_ids:
423
424
            if not domain_id in self._instances:
424
425
                instance = Instance(conn, domain_id)
425
426
                self._instances[domain_id] = instance
426
 
                logging.debug('Found instance: %s', domain_id)
 
427
                LOG.debug(_('Found instance: %s'), domain_id)
427
428
 
428
429
        for key in self._instances.keys():
429
430
            instance = self._instances[key]