~hudson-openstack/nova/trunk

« back to all changes in this revision

Viewing changes to bin/instance-usage-audit

  • Committer: Tarmac
  • Author(s): Vishvananda Ishaya, Anthony Young
  • Date: 2011-09-01 00:16:34 UTC
  • mfrom: (1468.3.13 os-simple-usage)
  • Revision ID: tarmac-20110901001634-bb3whyoipqxc60k5
Simple usage extension for nova.  Uses db to calculate tenant_usage for specified time periods.

Methods:
    * index: return a list of tenant_usages, with option of incuding detailed server_usage
    * show: returns a specific tenant_usage object

tenant_usage object:
    * tenant_usage.total_memory_mb_usage: sum of memory_mb * hours for all instances in tenant for this period
    * tenant_usage.total_local_gb_usage: sum of local_gb * hours for all instances in tenant for this period
    * tenant_usage.total_vcpus_usage: sum of vcpus * hours for all instances in tenant for this period
    * tenant_usage.total_hours: sum of all instance hours for this period
    * tenant_usage.server_usages: A detailed list of server_usages, which describe the usage of a specific server

For larger instances db tables, indexes on instance.launched_at and instance.terminated_at should significantly help performance.

Show diffs side-by-side

added added

removed removed

Lines of Context:
102
102
    logging.setup()
103
103
    begin, end = time_period(FLAGS.instance_usage_audit_period)
104
104
    print "Creating usages for %s until %s" % (str(begin), str(end))
105
 
    instances = db.instance_get_active_by_window(context.get_admin_context(),
106
 
                                                 begin,
107
 
                                                 end)
 
105
    ctxt = context.get_admin_context()
 
106
    instances = db.instance_get_active_by_window_joined(ctxt, begin, end)
108
107
    print "%s instances" % len(instances)
109
108
    for instance_ref in instances:
110
109
        usage_info = utils.usage_from_instance(instance_ref,