simple tenant usage - dianaclarke/openstack-notes GitHub Wiki

  • Using the simple tenant usage API for the first time (first get a token, test that it works, request the usage)
$ curl -s -X POST http://192.168.122.32:5000/v2.0/tokens \
>     -H "Content-Type: application/json" \
>     -d '{"auth": {"tenantName": "'"$OS_TENANT_NAME"'", "passwordCredentials":
>     {"username": "'"$OS_USERNAME"'", "password": "'"$OS_PASSWORD"'"}}}' \
>     | python -m json.tool
{
    "access": {
        "metadata": {
            "is_admin": 0,
            "roles": [
                "dd1533c2eca645269aac92d0e3f4ca50"
            ]
        },
        "serviceCatalog": [
            {
                "endpoints": [
                    {
                        "adminURL": "http://192.168.122.32:8774/v2.1/050ad8214ccb4c5e88185c9cdb415bbe",
                        "id": "06c57ebc2234461f981dae1bcea8e3bb",
                        "internalURL": "http://192.168.122.32:8774/v2.1/050ad8214ccb4c5e88185c9cdb415bbe",
                        "publicURL": "http://192.168.122.32:8774/v2.1/050ad8214ccb4c5e88185c9cdb415bbe",
                        "region": "RegionOne"
                    }
                ],
                "endpoints_links": [],
                "name": "nova",
                "type": "compute"
            },
            {
                "endpoints": [
                    {
                        "adminURL": "http://192.168.122.32:8776/v2/050ad8214ccb4c5e88185c9cdb415bbe",
                        "id": "7aa29b381a0d4d4d9ccf3ad255dcfd88",
                        "internalURL": "http://192.168.122.32:8776/v2/050ad8214ccb4c5e88185c9cdb415bbe",
                        "publicURL": "http://192.168.122.32:8776/v2/050ad8214ccb4c5e88185c9cdb415bbe",
                        "region": "RegionOne"
                    }
                ],
                "endpoints_links": [],
                "name": "cinderv2",
                "type": "volumev2"
            },
            {
                "endpoints": [
                    {
                        "adminURL": "http://192.168.122.32:9292",
                        "id": "098ce8aff9204832ac425c7fd1ade411",
                        "internalURL": "http://192.168.122.32:9292",
                        "publicURL": "http://192.168.122.32:9292",
                        "region": "RegionOne"
                    }
                ],
                "endpoints_links": [],
                "name": "glance",
                "type": "image"
            },
            {
                "endpoints": [
                    {
                        "adminURL": "http://192.168.122.32:8774/v2/050ad8214ccb4c5e88185c9cdb415bbe",
                        "id": "49d454b97b55464b802ed9fe9a74ca87",
                        "internalURL": "http://192.168.122.32:8774/v2/050ad8214ccb4c5e88185c9cdb415bbe",
                        "publicURL": "http://192.168.122.32:8774/v2/050ad8214ccb4c5e88185c9cdb415bbe",
                        "region": "RegionOne"
                    }
                ],
                "endpoints_links": [],
                "name": "nova_legacy",
                "type": "compute_legacy"
            },
            {
                "endpoints": [
                    {
                        "adminURL": "http://192.168.122.32:8776/v1/050ad8214ccb4c5e88185c9cdb415bbe",
                        "id": "0657717548794cd5a21afbaa08ac58da",
                        "internalURL": "http://192.168.122.32:8776/v1/050ad8214ccb4c5e88185c9cdb415bbe",
                        "publicURL": "http://192.168.122.32:8776/v1/050ad8214ccb4c5e88185c9cdb415bbe",
                        "region": "RegionOne"
                    }
                ],
                "endpoints_links": [],
                "name": "cinder",
                "type": "volume"
            },
            {
                "endpoints": [
                    {
                        "adminURL": "http://192.168.122.32:35357/v2.0",
                        "id": "091aeb9f13f741728ae79f471c9c116d",
                        "internalURL": "http://192.168.122.32:5000/v2.0",
                        "publicURL": "http://192.168.122.32:5000/v2.0",
                        "region": "RegionOne"
                    }
                ],
                "endpoints_links": [],
                "name": "keystone",
                "type": "identity"
            }
        ],
        "token": {
            "audit_ids": [
                "xpcJkfwaSbGoCu3amaJOzA"
            ],
            "expires": "2016-09-28T22:02:38Z",
            "id": "e9483ae42262438bba4c4fc34e443210",
            "issued_at": "2016-09-28T21:02:38.941894Z",
            "tenant": {
                "description": "",
                "enabled": true,
                "id": "050ad8214ccb4c5e88185c9cdb415bbe",
                "name": "alt_demo"
            }
        },
        "user": {
            "id": "278b6d11179449fab0586aec94556f8a",
            "name": "admin",
            "roles": [
                {
                    "name": "admin"
                }
            ],
            "roles_links": [],
            "username": "admin"
        }
    }
}
$ curl -s -H "X-Auth-Token:e9483ae42262438bba4c4fc34e443210" http://192.168.122.32:8774/v2.1/050ad8214ccb4c5e88185c9cdb415bbe/servers/detail | python -m json.tool
{
    "servers": [
        {
            "OS-DCF:diskConfig": "AUTO",
            "OS-EXT-AZ:availability_zone": "nova",
            "OS-EXT-SRV-ATTR:host": "localhost.localdomain",
            "OS-EXT-SRV-ATTR:hypervisor_hostname": "localhost.localdomain",
            "OS-EXT-SRV-ATTR:instance_name": "instance-00000001",
            "OS-EXT-STS:power_state": 1,
            "OS-EXT-STS:task_state": null,
            "OS-EXT-STS:vm_state": "active",
            "OS-SRV-USG:launched_at": "2016-09-28T20:58:38.000000",
            "OS-SRV-USG:terminated_at": null,
            "accessIPv4": "",
            "accessIPv6": "",
            "addresses": {
                "private": [
                    {
                        "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:06:3c:fc",
                        "OS-EXT-IPS:type": "fixed",
                        "addr": "10.0.0.2",
                        "version": 4
                    }
                ]
            },
            "config_drive": "True",
            "created": "2016-09-28T20:58:03Z",
            "flavor": {
                "id": "42",
                "links": [
                    {
                        "href": "http://192.168.122.32:8774/050ad8214ccb4c5e88185c9cdb415bbe/flavors/42",
                        "rel": "bookmark"
                    }
                ]
            },
            "hostId": "8abaeeccf64377fd45d1e777fac69b60fd5c967ee98a1186d6e6803d",
            "id": "d8fb59f9-e212-4a23-a92d-2d6fd824f4ad",
            "image": {
                "id": "0edff2d0-3a47-4c0b-b0c2-2423c622f086",
                "links": [
                    {
                        "href": "http://192.168.122.32:8774/050ad8214ccb4c5e88185c9cdb415bbe/images/0edff2d0-3a47-4c0b-b0c2-2423c622f086",
                        "rel": "bookmark"
                    }
                ]
            },
            "key_name": null,
            "links": [
                {
                    "href": "http://192.168.122.32:8774/v2.1/050ad8214ccb4c5e88185c9cdb415bbe/servers/d8fb59f9-e212-4a23-a92d-2d6fd824f4ad",
                    "rel": "self"
                },
                {
                    "href": "http://192.168.122.32:8774/050ad8214ccb4c5e88185c9cdb415bbe/servers/d8fb59f9-e212-4a23-a92d-2d6fd824f4ad",
                    "rel": "bookmark"
                }
            ],
            "metadata": {},
            "name": "instance-1",
            "os-extended-volumes:volumes_attached": [],
            "progress": 0,
            "security_groups": [
                {
                    "name": "default"
                }
            ],
            "status": "ACTIVE",
            "tenant_id": "050ad8214ccb4c5e88185c9cdb415bbe",
            "updated": "2016-09-28T20:58:38Z",
            "user_id": "278b6d11179449fab0586aec94556f8a"
        }
    ]
}
$ curl -s -H "X-Auth-Token:e9483ae42262438bba4c4fc34e443210" http://192.168.122.32:8774/v2.1/050ad8214ccb4c5e88185c9cdb415bbe/os-simple-tenant-usage | python -m json.tool
{
    "tenant_usages": [
        {
            "start": "2016-09-28T21:14:06.750467",
            "stop": "2016-09-28T21:14:06.750489",
            "tenant_id": "050ad8214ccb4c5e88185c9cdb415bbe",
            "total_hours": 6.111111111111111e-09,
            "total_local_gb_usage": 0.0,
            "total_memory_mb_usage": 3.911111111111111e-07,
            "total_vcpus_usage": 6.111111111111111e-09
        }
    ]
}

Examples to work off of:

  • The current query:
SET timestamp=1475096571;

SELECT instances.created_at AS instances_created_at, instances.updated_at AS instances_updated_at, instances.deleted_at AS instances_deleted_at, instances.deleted AS instances_deleted, instances.id AS instances_id, instances.user_id AS instances_user_id, instances.project_id AS instances_project_id, instances.image_ref AS instances_image_ref, instances.kernel_id AS instances_kernel_id, instances.ramdisk_id AS instances_ramdisk_id, instances.hostname AS instances_hostname, instances.launch_index AS instances_launch_index, instances.key_name AS instances_key_name, instances.key_data AS instances_key_data, instances.power_state AS instances_power_state, instances.vm_state AS instances_vm_state, instances.task_state AS instances_task_state, instances.memory_mb AS instances_memory_mb, instances.vcpus AS instances_vcpus, instances.root_gb AS instances_root_gb, instances.ephemeral_gb AS instances_ephemeral_gb, instances.ephemeral_key_uuid AS instances_ephemeral_key_uuid, instances.host AS instances_host, instances.node AS instances_node, instances.instance_type_id AS instances_instance_type_id, instances.user_data AS instances_user_data, instances.reservation_id AS instances_reservation_id, instances.launched_at AS instances_launched_at, instances.terminated_at AS instances_terminated_at, instances.availability_zone AS instances_availability_zone, instances.display_name AS instances_display_name, instances.display_description AS instances_display_description, instances.launched_on AS instances_launched_on, instances.locked AS instances_locked, instances.locked_by AS instances_locked_by, instances.os_type AS instances_os_type, instances.architecture AS instances_architecture, instances.vm_mode AS instances_vm_mode, instances.uuid AS instances_uuid, instances.root_device_name AS instances_root_device_name, instances.default_ephemeral_device AS instances_default_ephemeral_device, instances.default_swap_device AS instances_default_swap_device, instances.config_drive AS instances_config_drive, instances.access_ip_v4 AS instances_access_ip_v4, instances.access_ip_v6 AS instances_access_ip_v6, instances.auto_disk_config AS instances_auto_disk_config, instances.progress AS instances_progress, instances.shutdown_terminate AS instances_shutdown_terminate, instances.disable_terminate AS instances_disable_terminate, instances.cell_name AS instances_cell_name, instances.internal_id AS instances_internal_id, instances.cleaned AS instances_cleaned, instance_extra_1.flavor AS instance_extra_1_flavor, instance_extra_1.created_at AS instance_extra_1_created_at, instance_extra_1.updated_at AS instance_extra_1_updated_at, instance_extra_1.deleted_at AS instance_extra_1_deleted_at, instance_extra_1.deleted AS instance_extra_1_deleted, instance_extra_1.id AS instance_extra_1_id, instance_extra_1.instance_uuid AS instance_extra_1_instance_uuid 

FROM instances

LEFT OUTER JOIN instance_extra AS instance_extra_1 ON instance_extra_1.instance_uuid = instances.uuid 

WHERE (instances.terminated_at IS NULL OR instances.terminated_at > '2016-09-28 21:02:51') AND instances.launched_at < '2016-09-28 21:02:51';

  • With more than 1 tenant:
[diana@localhost devstack]$ curl -s -H "X-Auth-Token:0654c6b8c8c346eea4afa0afa961bd69" http://192.168.122.32:8774/v2.1/050ad8214ccb4c5e88185c9cdb415bbe/os-simple-tenant-usage | python -m json.tool
{
    "tenant_usages": [
        {
            "start": "2016-09-28T22:07:20.506006",
            "stop": "2016-09-28T22:07:20.506031",
            "tenant_id": "050ad8214ccb4c5e88185c9cdb415bbe",
            "total_hours": 2.0833333333333335e-08,
            "total_local_gb_usage": 0.0,
            "total_memory_mb_usage": 1.3333333333333334e-06,
            "total_vcpus_usage": 2.0833333333333335e-08
        },
        {
            "start": "2016-09-28T22:07:20.506006",
            "stop": "2016-09-28T22:07:20.506031",
            "tenant_id": "68dae576d7d54baeb27f13b4eb3f0ae8",
            "total_hours": 6.944444444444445e-09,
            "total_local_gb_usage": 0.0,
            "total_memory_mb_usage": 4.444444444444445e-07,
            "total_vcpus_usage": 6.944444444444445e-09
        }
    ]
}

[diana@localhost devstack]$ openstack project list
+----------------------------------+--------------------+
| ID                               | Name               |
+----------------------------------+--------------------+
| 050ad8214ccb4c5e88185c9cdb415bbe | alt_demo           |
| 68dae576d7d54baeb27f13b4eb3f0ae8 | invisible_to_admin |
| 99d66d3f8ffe44cf9a6ad9c6c6851d27 | demo               |
| fcc4d1f31d7f40b48c8b16969b6e4d72 | admin              |
| fcc80c4596b54f67a7f23dd04d6cf457 | service            |
+----------------------------------+--------------------+

[diana@localhost devstack]$ nova list
+--------------------------------------+------------+--------+------------+-------------+------------------+
| ID                                   | Name       | Status | Task State | Power State | Networks         |
+--------------------------------------+------------+--------+------------+-------------+------------------+
| 13cf9333-0345-479d-a700-e9f7a467e3b0 | instance-1 | ACTIVE | -          | Running     | private=10.0.0.2 |
| 024bca58-b7c2-4da1-91a3-41916546e63a | instance-2 | ACTIVE | -          | Running     | private=10.0.0.3 |
| 38a569dc-50c3-4b9a-b696-431c58df6faa | instance-3 | ACTIVE | -          | Running     | private=10.0.0.4 |
+--------------------------------------+------------+--------+------------+-------------+------------------+

$ openstack project show alt_demo
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description |                                  |
| enabled     | True                             |
| id          | 050ad8214ccb4c5e88185c9cdb415bbe |
| name        | alt_demo                         |
| properties  |                                  |
+-------------+----------------------------------+

  • With the detailed flag:
$ curl -s -H "X-Auth-Token:641f32d5c7594e0da16e7190c760d990" http://192.168.122.32:8774/v2.1/050ad8214ccb4c5e88185c9cdb415bbe/os-simple-tenant-usage?detailed=1 | python -m json.tool
{
    "tenant_usages": [
        {
            "server_usages": [
                {
                    "ended_at": null,
                    "flavor": "m1.nano",
                    "hours": 6.944444444444445e-09,
                    "instance_id": "13cf9333-0345-479d-a700-e9f7a467e3b0",
                    "local_gb": 0,
                    "memory_mb": 64,
                    "name": "instance-1",
                    "started_at": "2016-09-28T20:54:43.000000",
                    "state": "active",
                    "tenant_id": "050ad8214ccb4c5e88185c9cdb415bbe",
                    "uptime": 9154,
                    "vcpus": 1
                },
                {
                    "ended_at": null,
                    "flavor": "m1.nano",
                    "hours": 6.944444444444445e-09,
                    "instance_id": "024bca58-b7c2-4da1-91a3-41916546e63a",
                    "local_gb": 0,
                    "memory_mb": 64,
                    "name": "instance-2",
                    "started_at": "2016-09-28T21:51:17.000000",
                    "state": "active",
                    "tenant_id": "050ad8214ccb4c5e88185c9cdb415bbe",
                    "uptime": 5760,
                    "vcpus": 1
                },
                {
                    "ended_at": null,
                    "flavor": "m1.nano",
                    "hours": 6.944444444444445e-09,
                    "instance_id": "38a569dc-50c3-4b9a-b696-431c58df6faa",
                    "local_gb": 0,
                    "memory_mb": 64,
                    "name": "instance-3",
                    "started_at": "2016-09-28T21:52:15.000000",
                    "state": "active",
                    "tenant_id": "050ad8214ccb4c5e88185c9cdb415bbe",
                    "uptime": 5702,
                    "vcpus": 1
                }
            ],
            "start": "2016-09-28T23:27:17.120058",
            "stop": "2016-09-28T23:27:17.120083",
            "tenant_id": "050ad8214ccb4c5e88185c9cdb415bbe",
            "total_hours": 2.0833333333333335e-08,
            "total_local_gb_usage": 0.0,
            "total_memory_mb_usage": 1.3333333333333334e-06,
            "total_vcpus_usage": 2.0833333333333335e-08
        },
        {
            "server_usages": [
                {
                    "ended_at": null,
                    "flavor": "m1.nano",
                    "hours": 6.944444444444445e-09,
                    "instance_id": "b710b787-e71b-4b77-b253-ab78a9185464",
                    "local_gb": 0,
                    "memory_mb": 64,
                    "name": "instance-4",
                    "started_at": "2016-09-28T22:05:08.000000",
                    "state": "active",
                    "tenant_id": "68dae576d7d54baeb27f13b4eb3f0ae8",
                    "uptime": 4929,
                    "vcpus": 1
                }
            ],
            "start": "2016-09-28T23:27:17.120058",
            "stop": "2016-09-28T23:27:17.120083",
            "tenant_id": "68dae576d7d54baeb27f13b4eb3f0ae8",
            "total_hours": 6.944444444444445e-09,
            "total_local_gb_usage": 0.0,
            "total_memory_mb_usage": 4.444444444444445e-07,
            "total_vcpus_usage": 6.944444444444445e-09
        }
    ]
}

[diana@localhost devstack]$ time curl -s -H "X-Auth-Token:15b41f14c1ee4487a91cbd55d582166b" http://192.168.122.32:8774/v2.1/050ad8214ccb4c5e88185c9cdb415bbe/os-simple-tenant-usage?detailed=1 | python -m json.tool
{
    "tenant_usages": [
        {
            "server_usages": [
                {
                    "ended_at": null,
                    "flavor": "m1.nano",
                    "hours": 6.388888888888889e-09,
                    "instance_id": "13cf9333-0345-479d-a700-e9f7a467e3b0",
                    "local_gb": 0,
                    "memory_mb": 64,
                    "name": "instance-1",
                    "started_at": "2016-09-28T20:54:43.000000",
                    "state": "active",
                    "tenant_id": "050ad8214ccb4c5e88185c9cdb415bbe",
                    "uptime": 93852,
                    "vcpus": 1
                },
                {
                    "ended_at": null,
                    "flavor": "m1.nano",
                    "hours": 6.388888888888889e-09,
                    "instance_id": "024bca58-b7c2-4da1-91a3-41916546e63a",
                    "local_gb": 0,
                    "memory_mb": 64,
                    "name": "instance-2",
                    "started_at": "2016-09-28T21:51:17.000000",
                    "state": "active",
                    "tenant_id": "050ad8214ccb4c5e88185c9cdb415bbe",
                    "uptime": 90458,
                    "vcpus": 1
                },
                {
                    "ended_at": null,
                    "flavor": "m1.nano",
                    "hours": 6.388888888888889e-09,
                    "instance_id": "38a569dc-50c3-4b9a-b696-431c58df6faa",
                    "local_gb": 0,
                    "memory_mb": 64,
                    "name": "instance-3",
                    "started_at": "2016-09-28T21:52:15.000000",
                    "state": "active",
                    "tenant_id": "050ad8214ccb4c5e88185c9cdb415bbe",
                    "uptime": 90400,
                    "vcpus": 1
                },
                {
                    "ended_at": null,
                    "flavor": "m1.nano",
                    "hours": 6.388888888888889e-09,
                    "instance_id": "07bbb4e1-a91c-470e-a6ca-a9baf401b110",
                    "local_gb": 0,
                    "memory_mb": 64,
                    "name": "test",
                    "started_at": "2016-09-29T22:43:12.000000",
                    "state": "active",
                    "tenant_id": "050ad8214ccb4c5e88185c9cdb415bbe",
                    "uptime": 943,
                    "vcpus": 1
                },
                {
                    "ended_at": null,
                    "flavor": "m1.nano",
                    "hours": 6.388888888888889e-09,
                    "instance_id": "48b6ce19-f636-48c2-8e5d-82f8a80493a1",
                    "local_gb": 0,
                    "memory_mb": 64,
                    "name": "test-1",
                    "started_at": "2016-09-29T22:44:09.000000",
                    "state": "active",
                    "tenant_id": "050ad8214ccb4c5e88185c9cdb415bbe",
                    "uptime": 886,
                    "vcpus": 1
                },
                {
                    "ended_at": null,
                    "flavor": "m1.nano",
                    "hours": 6.388888888888889e-09,
                    "instance_id": "cd187e98-cab5-4895-aeed-e39cda5a7794",
                    "local_gb": 0,
                    "memory_mb": 64,
                    "name": "test-2",
                    "started_at": "2016-09-29T22:44:14.000000",
                    "state": "active",
                    "tenant_id": "050ad8214ccb4c5e88185c9cdb415bbe",
                    "uptime": 881,
                    "vcpus": 1
                },
                {
                    "ended_at": null,
                    "flavor": "m1.nano",
                    "hours": 6.388888888888889e-09,
                    "instance_id": "65e7e622-f61e-494d-b5e2-69d08c851290",
                    "local_gb": 0,
                    "memory_mb": 64,
                    "name": "test-3",
                    "started_at": "2016-09-29T22:44:17.000000",
                    "state": "active",
                    "tenant_id": "050ad8214ccb4c5e88185c9cdb415bbe",
                    "uptime": 878,
                    "vcpus": 1
                },
                {
                    "ended_at": null,
                    "flavor": "m1.nano",
                    "hours": 6.388888888888889e-09,
                    "instance_id": "fa463037-8f8e-456b-908b-badab846d0cb",
                    "local_gb": 0,
                    "memory_mb": 64,
                    "name": "test-4",
                    "started_at": "2016-09-29T22:44:19.000000",
                    "state": "active",
                    "tenant_id": "050ad8214ccb4c5e88185c9cdb415bbe",
                    "uptime": 876,
                    "vcpus": 1
                },
                {
                    "ended_at": null,
                    "flavor": "m1.nano",
                    "hours": 6.388888888888889e-09,
                    "instance_id": "b7d43a0a-10d2-4eaf-b066-ccff8ccb0b75",
                    "local_gb": 0,
                    "memory_mb": 64,
                    "name": "test-5",
                    "started_at": "2016-09-29T22:44:23.000000",
                    "state": "active",
                    "tenant_id": "050ad8214ccb4c5e88185c9cdb415bbe",
                    "uptime": 872,
                    "vcpus": 1
                },
                {
                    "ended_at": null,
                    "flavor": "m1.nano",
                    "hours": 6.388888888888889e-09,
                    "instance_id": "c81bd9ae-6683-4493-b93d-4f7e98bb109b",
                    "local_gb": 0,
                    "memory_mb": 64,
                    "name": "test-6",
                    "started_at": "2016-09-29T22:44:19.000000",
                    "state": "active",
                    "tenant_id": "050ad8214ccb4c5e88185c9cdb415bbe",
                    "uptime": 876,
                    "vcpus": 1
                },
                {
                    "ended_at": null,
                    "flavor": "m1.nano",
                    "hours": 6.388888888888889e-09,
                    "instance_id": "5c46cf72-8798-4949-a52c-9a861e26b7ce",
                    "local_gb": 0,
                    "memory_mb": 64,
                    "name": "test-1",
                    "started_at": "2016-09-29T22:49:34.000000",
                    "state": "active",
                    "tenant_id": "050ad8214ccb4c5e88185c9cdb415bbe",
                    "uptime": 561,
                    "vcpus": 1
                },
                {
                    "ended_at": null,
                    "flavor": "m1.nano",
                    "hours": 6.388888888888889e-09,
                    "instance_id": "01d404ec-648c-4c62-9f70-e4380c90cd5d",
                    "local_gb": 0,
                    "memory_mb": 64,
                    "name": "test-2",
                    "started_at": "2016-09-29T22:49:41.000000",
                    "state": "active",
                    "tenant_id": "050ad8214ccb4c5e88185c9cdb415bbe",
                    "uptime": 554,
                    "vcpus": 1
                },
                {
                    "ended_at": null,
                    "flavor": "m1.nano",
                    "hours": 6.388888888888889e-09,
                    "instance_id": "52db7a4d-c579-4171-a50f-9ad20a72d668",
                    "local_gb": 0,
                    "memory_mb": 64,
                    "name": "test-3",
                    "started_at": "2016-09-29T22:49:44.000000",
                    "state": "active",
                    "tenant_id": "050ad8214ccb4c5e88185c9cdb415bbe",
                    "uptime": 551,
                    "vcpus": 1
                },
                {
                    "ended_at": null,
                    "flavor": "m1.nano",
                    "hours": 6.388888888888889e-09,
                    "instance_id": "9e7a7b86-8bd7-43c1-a02c-24926305ffdb",
                    "local_gb": 0,
                    "memory_mb": 64,
                    "name": "test-4",
                    "started_at": "2016-09-29T22:49:49.000000",
                    "state": "active",
                    "tenant_id": "050ad8214ccb4c5e88185c9cdb415bbe",
                    "uptime": 546,
                    "vcpus": 1
                },
                {
                    "ended_at": null,
                    "flavor": "m1.nano",
                    "hours": 6.388888888888889e-09,
                    "instance_id": "a9cb4d99-3ad8-42e4-92b7-2e5fdc3eaf64",
                    "local_gb": 0,
                    "memory_mb": 64,
                    "name": "test-5",
                    "started_at": "2016-09-29T22:49:52.000000",
                    "state": "active",
                    "tenant_id": "050ad8214ccb4c5e88185c9cdb415bbe",
                    "uptime": 543,
                    "vcpus": 1
                },
                {
                    "ended_at": null,
                    "flavor": "m1.nano",
                    "hours": 6.388888888888889e-09,
                    "instance_id": "bfbfe518-3c1e-4665-8c03-8e1b80426029",
                    "local_gb": 0,
                    "memory_mb": 64,
                    "name": "test-6",
                    "started_at": "2016-09-29T22:49:57.000000",
                    "state": "active",
                    "tenant_id": "050ad8214ccb4c5e88185c9cdb415bbe",
                    "uptime": 538,
                    "vcpus": 1
                },
                {
                    "ended_at": null,
                    "flavor": "m1.nano",
                    "hours": 6.388888888888889e-09,
                    "instance_id": "ab9b497f-5987-4761-bfd4-36172fe25d4c",
                    "local_gb": 0,
                    "memory_mb": 64,
                    "name": "test-7",
                    "started_at": "2016-09-29T22:49:53.000000",
                    "state": "active",
                    "tenant_id": "050ad8214ccb4c5e88185c9cdb415bbe",
                    "uptime": 542,
                    "vcpus": 1
                },
                {
                    "ended_at": null,
                    "flavor": "m1.nano",
                    "hours": 6.388888888888889e-09,
                    "instance_id": "346201f8-d7b9-4aaf-8886-39c418be7100",
                    "local_gb": 0,
                    "memory_mb": 64,
                    "name": "test-8",
                    "started_at": "2016-09-29T22:49:57.000000",
                    "state": "active",
                    "tenant_id": "050ad8214ccb4c5e88185c9cdb415bbe",
                    "uptime": 538,
                    "vcpus": 1
                },
                {
                    "ended_at": null,
                    "flavor": "m1.nano",
                    "hours": 6.388888888888889e-09,
                    "instance_id": "d9ad8b20-6e60-42fd-a28c-6e713882486e",
                    "local_gb": 0,
                    "memory_mb": 64,
                    "name": "test-9",
                    "started_at": "2016-09-29T22:50:06.000000",
                    "state": "active",
                    "tenant_id": "050ad8214ccb4c5e88185c9cdb415bbe",
                    "uptime": 529,
                    "vcpus": 1
                },
                {
                    "ended_at": null,
                    "flavor": "m1.nano",
                    "hours": 6.388888888888889e-09,
                    "instance_id": "17974a35-dbfd-45fe-bf9c-48f3609d0f2a",
                    "local_gb": 0,
                    "memory_mb": 64,
                    "name": "test-10",
                    "started_at": "2016-09-29T22:50:04.000000",
                    "state": "active",
                    "tenant_id": "050ad8214ccb4c5e88185c9cdb415bbe",
                    "uptime": 531,
                    "vcpus": 1
                }
            ],
            "start": "2016-09-29T22:58:55.877547",
            "stop": "2016-09-29T22:58:55.877570",
            "tenant_id": "050ad8214ccb4c5e88185c9cdb415bbe",
            "total_hours": 1.277777777777778e-07,
            "total_local_gb_usage": 0.0,
            "total_memory_mb_usage": 8.177777777777779e-06,
            "total_vcpus_usage": 1.277777777777778e-07
        },
        {
            "server_usages": [
                {
                    "ended_at": null,
                    "flavor": "m1.nano",
                    "hours": 6.388888888888889e-09,
                    "instance_id": "b710b787-e71b-4b77-b253-ab78a9185464",
                    "local_gb": 0,
                    "memory_mb": 64,
                    "name": "instance-4",
                    "started_at": "2016-09-28T22:05:08.000000",
                    "state": "active",
                    "tenant_id": "68dae576d7d54baeb27f13b4eb3f0ae8",
                    "uptime": 89627,
                    "vcpus": 1
                }
            ],
            "start": "2016-09-29T22:58:55.877547",
            "stop": "2016-09-29T22:58:55.877570",
            "tenant_id": "68dae576d7d54baeb27f13b4eb3f0ae8",
            "total_hours": 6.388888888888889e-09,
            "total_local_gb_usage": 0.0,
            "total_memory_mb_usage": 4.088888888888889e-07,
            "total_vcpus_usage": 6.388888888888889e-09
        }
    ]
}

real	0m0.129s
user	0m0.048s
sys	0m0.016s
MariaDB [nova]> show create table instances\G
*************************** 1. row ***************************
       Table: instances
Create Table: CREATE TABLE `instances` (
  `created_at` datetime DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL,
  `deleted_at` datetime DEFAULT NULL,
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `internal_id` int(11) DEFAULT NULL,
  `user_id` varchar(255) DEFAULT NULL,
  `project_id` varchar(255) DEFAULT NULL,
  `image_ref` varchar(255) DEFAULT NULL,
  `kernel_id` varchar(255) DEFAULT NULL,
  `ramdisk_id` varchar(255) DEFAULT NULL,
  `launch_index` int(11) DEFAULT NULL,
  `key_name` varchar(255) DEFAULT NULL,
  `key_data` mediumtext,
  `power_state` int(11) DEFAULT NULL,
  `vm_state` varchar(255) DEFAULT NULL,
  `memory_mb` int(11) DEFAULT NULL,
  `vcpus` int(11) DEFAULT NULL,
  `hostname` varchar(255) DEFAULT NULL,
  `host` varchar(255) DEFAULT NULL,
  `user_data` mediumtext,
  `reservation_id` varchar(255) DEFAULT NULL,
  `scheduled_at` datetime DEFAULT NULL,
  `launched_at` datetime DEFAULT NULL,
  `terminated_at` datetime DEFAULT NULL,
  `display_name` varchar(255) DEFAULT NULL,
  `display_description` varchar(255) DEFAULT NULL,
  `availability_zone` varchar(255) DEFAULT NULL,
  `locked` tinyint(1) DEFAULT NULL,
  `os_type` varchar(255) DEFAULT NULL,
  `launched_on` mediumtext,
  `instance_type_id` int(11) DEFAULT NULL,
  `vm_mode` varchar(255) DEFAULT NULL,
  `uuid` varchar(36) NOT NULL,
  `architecture` varchar(255) DEFAULT NULL,
  `root_device_name` varchar(255) DEFAULT NULL,
  `access_ip_v4` varchar(39) DEFAULT NULL,
  `access_ip_v6` varchar(39) DEFAULT NULL,
  `config_drive` varchar(255) DEFAULT NULL,
  `task_state` varchar(255) DEFAULT NULL,
  `default_ephemeral_device` varchar(255) DEFAULT NULL,
  `default_swap_device` varchar(255) DEFAULT NULL,
  `progress` int(11) DEFAULT NULL,
  `auto_disk_config` tinyint(1) DEFAULT NULL,
  `shutdown_terminate` tinyint(1) DEFAULT NULL,
  `disable_terminate` tinyint(1) DEFAULT NULL,
  `root_gb` int(11) DEFAULT NULL,
  `ephemeral_gb` int(11) DEFAULT NULL,
  `cell_name` varchar(255) DEFAULT NULL,
  `node` varchar(255) DEFAULT NULL,
  `deleted` int(11) DEFAULT NULL,
  `locked_by` enum('owner','admin') DEFAULT NULL,
  `cleaned` int(11) DEFAULT NULL,
  `ephemeral_key_uuid` varchar(36) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uuid` (`uuid`),
  UNIQUE KEY `uniq_instances0uuid` (`uuid`),
  KEY `instances_reservation_id_idx` (`reservation_id`),
  KEY `instances_terminated_at_launched_at_idx` (`terminated_at`,`launched_at`),
  KEY `instances_task_state_updated_at_idx` (`task_state`,`updated_at`),
  KEY `instances_uuid_deleted_idx` (`uuid`,`deleted`),
  KEY `instances_host_node_deleted_idx` (`host`,`node`,`deleted`),
  KEY `instances_host_deleted_cleaned_idx` (`host`,`deleted`,`cleaned`),
  KEY `instances_project_id_deleted_idx` (`project_id`,`deleted`),
  KEY `instances_deleted_created_at_idx` (`deleted`,`created_at`)
) ENGINE=InnoDB AUTO_INCREMENT=522 DEFAULT CHARSET=utf8

MariaDB [nova]> show create table instance_extra\G
*************************** 1. row ***************************
       Table: instance_extra
Create Table: CREATE TABLE `instance_extra` (
  `created_at` datetime DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL,
  `deleted_at` datetime DEFAULT NULL,
  `deleted` int(11) DEFAULT NULL,
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `instance_uuid` varchar(36) NOT NULL,
  `numa_topology` text,
  `pci_requests` text,
  `flavor` text,
  `vcpu_model` text,
  `migration_context` text,
  PRIMARY KEY (`id`),
  KEY `instance_extra_idx` (`instance_uuid`),
  CONSTRAINT `instance_extra_instance_uuid_fkey` FOREIGN KEY (`instance_uuid`) REFERENCES `instances` (`uuid`)
) ENGINE=InnoDB AUTO_INCREMENT=522 DEFAULT CHARSET=utf8

SELECT
instances.created_at AS instances_created_at, 
instances.id AS instances_id,
instances.display_name AS instances_display_name,
instances.uuid AS instances_uuid,
instance_extra_1.flavor AS instance_extra_1_flavor
FROM instances LEFT OUTER JOIN instance_extra AS instance_extra_1 ON instance_extra_1.instance_uuid = instances.uuid WHERE (instances.terminated_at IS NULL OR instances.terminated_at > '2016-09-28 21:02:51') AND instances.launched_at < '2016-09-28 21:02:51'\G

MariaDB [nova]> SELECT
    -> instances.created_at AS instances_created_at, 
    -> instances.id AS instances_id,
    -> instances.display_name AS instances_display_name,
    -> instances.uuid AS instances_uuid,
    -> instance_extra_1.flavor AS instance_extra_1_flavor
    -> FROM instances LEFT OUTER JOIN instance_extra AS instance_extra_1 ON instance_extra_1.instance_uuid = instances.uuid WHERE (instances.terminated_at IS NULL OR instances.terminated_at > '2016-09-28 21:02:51') AND instances.launched_at < '2016-09-28 21:02:51'\G
*************************** 1. row ***************************
   instances_created_at: 2016-09-28 20:54:10
           instances_id: 1
 instances_display_name: instance-1
         instances_uuid: 13cf9333-0345-479d-a700-e9f7a467e3b0
instance_extra_1_flavor: {"new": null, "old": null, "cur": {"nova_object.version": "1.1", "nova_object.name": "Flavor", "nova_object.data": {"disabled": false, "root_gb": 0, "name": "m1.nano", "flavorid": "42", "deleted": false, "created_at": "2016-09-28T20:39:36Z", "ephemeral_gb": 0, "updated_at": null, "memory_mb": 64, "vcpus": 1, "extra_specs": {}, "swap": 0, "rxtx_factor": 1.0, "is_public": true, "deleted_at": null, "vcpu_weight": 0, "id": 6}, "nova_object.namespace": "nova"}}
1 row in set (0.00 sec)

MariaDB [nova]> EXPLAIN SELECT instances.created_at AS instances_created_at,  instances.id AS instances_id, instances.display_name AS instances_display_name, instances.uuid AS instances_uuid, instance_extra_1.flavor AS instance_extra_1_flavor FROM instances LEFT OUTER JOIN instance_extra AS instance_extra_1 ON instance_extra_1.instance_uuid = instances.uuid WHERE (instances.terminated_at IS NULL OR instances.terminated_at > '2016-09-28 21:02:51') AND instances.launched_at < '2016-09-30 21:02:51'\G
*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: instances
         type: ALL
possible_keys: instances_terminated_at_launched_at_idx
          key: NULL
      key_len: NULL
          ref: NULL
         rows: 521
        Extra: Using where
*************************** 2. row ***************************
           id: 1
  select_type: SIMPLE
        table: instance_extra_1
         type: ref
possible_keys: instance_extra_idx
          key: instance_extra_idx
      key_len: 110
          ref: nova.instances.uuid
         rows: 1
        Extra: 
2 rows in set (0.00 sec)


  • Now create 500 more instances
$ nova boot --image=0edff2d0-3a47-4c0b-b0c2-2423c622f086 --flavor=m1.nano --min-count 500 foo 
  • Without detail, 500+ instance and only 2 tenants takes:
$ time curl -s -H "X-Auth-Token:da85897100984b4e8693c8f7f22d3633" http://192.168.122.32:8774/v2.1/050ad8214ccb4c5e88185c9cdb415bbe/os-simple-tenant-usage?detailed=0 | python -m json.tool
{
    "tenant_usages": [
        {
            "start": "2016-09-30T01:26:24.602050",
            "stop": "2016-09-30T01:26:24.602075",
            "tenant_id": "050ad8214ccb4c5e88185c9cdb415bbe",
            "total_hours": 3.6111111111110822e-06,
            "total_local_gb_usage": 0.0,
            "total_memory_mb_usage": 0.00023111111111110926,
            "total_vcpus_usage": 3.6111111111110822e-06
        },
        {
            "start": "2016-09-30T01:26:24.602050",
            "stop": "2016-09-30T01:26:24.602075",
            "tenant_id": "68dae576d7d54baeb27f13b4eb3f0ae8",
            "total_hours": 6.944444444444445e-09,
            "total_local_gb_usage": 0.0,
            "total_memory_mb_usage": 4.444444444444445e-07,
            "total_vcpus_usage": 6.944444444444445e-09
        }
    ]
}

real	0m1.218s
user	0m0.050s
sys	0m0.009s
  • With detail, 500+ instance and only 2 tenants takes:
[diana@localhost devstack]$ time curl -s -H "X-Auth-Token:da85897100984b4e8693c8f7f22d3633" http://192.168.122.32:8774/v2.1/050ad8214ccb4c5e88185c9cdb415bbe/os-simple-tenant-usage?detailed=1 | python -m json.tool

real	0m1.588s
user	0m0.084s
sys	0m0.052s
  • From the slow log:
# Query_time: 0.011292  Lock_time: 0.000275  Rows_sent: 521  Rows_examined: 1042
  • And a no-op (stubbed query out):
$ time curl -s -H "X-Auth-Token:da85897100984b4e8693c8f7f22d3633" http://192.168.122.32:8774/v2.1/050ad8214ccb4c5e88185c9cdb415bbe/os-simple-tenant-usage?detailed=0 | python -m json.tool
{
    "tenant_usages": []
}

real	0m0.060s
user	0m0.048s
sys	0m0.012s
  • Execute query, and iterate over the results, but don't otherwise do anything:
[diana@localhost devstack]$ time curl -s -H "X-Auth-Token:da85897100984b4e8693c8f7f22d3633" http://192.168.122.32:8774/v2.1/050ad8214ccb4c5e88185c9cdb415bbe/os-simple-tenant-usage?detailed=0 | python -m json.tool
{
    "tenant_usages": []
}

real	0m1.180s
user	0m0.048s
sys	0m0.009s
  • Without the extra info join, iterate over the results, but don't otherwise do anything:
$ time curl -s -H "X-Auth-Token:3e35b0a64d204c7d9c24d39cb742e722" http://192.168.122.32:8774/v2.1/050ad8214ccb4c5e88185c9cdb415bbe/os-simple-tenant-usage?detailed=0 | python -m json.tool
{
    "tenant_usages": []
}

real	0m0.711s
user	0m0.046s
sys	0m0.015s
  • And if you omit the the expected_attrs kward entirely, it's almost a full minute.
[diana@localhost devstack]$ time curl -s -H "X-Auth-Token:3e35b0a64d204c7d9c24d39cb742e722" http://192.168.122.32:8774/v2.1/050ad8214ccb4c5e88185c9cdb415bbe/os-simple-tenant-usage?detailed=0 | python -m json.tool


real	0m53.298s
user	0m0.050s
sys	0m0.008s
  • Perhaps that's what it used to do... checking stable/liberty
$ nova boot --image=ae263f70-d1a8-445d-b026-ba36a695dfaa --flavor=m1.nano --min-count=100 test

$ nova boot --image=ae263f70-d1a8-445d-b026-ba36a695dfaa --flavor=m1.nano --min-count=100 foo

$ nova boot --image=ae263f70-d1a8-445d-b026-ba36a695dfaa --flavor=m1.nano --min-count=100 bar

$ nova boot --image=ae263f70-d1a8-445d-b026-ba36a695dfaa --flavor=m1.nano --min-count=100 baz

$ nova boot --image=ae263f70-d1a8-445d-b026-ba36a695dfaa --flavor=m1.nano --min-count=100 red
  • Fake the launched_at date (since they all didn't actually launch).
update instances set launched_at = '2016-09-27 23:24:03' where launched_at is null;
  • Hmmm.... that's still not all that slow:
[diana@reserved devstack]$ time curl -s -H "X-Auth-Token:cd6f683f398e4a8d88d304520f43f02a" http://192.168.122.209:8774/v2/8125115d5da34b698e6645e434050749/os-simple-tenant-usage?detailed=1 | python -m json.tool | grep name | wc -l
501

real	0m1.459s
user	0m0.106s
sys	0m0.052s
    ---------------------> NO LIMIT
    SELECT instances.created_at AS instances_created_at, instances.updated_at AS instances_updated_at, instances.deleted_at AS instances_deleted_at, instances.deleted AS instances_deleted, instances.id AS instances_id, instances.user_id AS instances_user_id, instances.project_id AS instances_project_id, instances.image_ref AS instances_image_ref, instances.kernel_id AS instances_kernel_id, instances.ramdisk_id AS instances_ramdisk_id, instances.hostname AS instances_hostname, instances.launch_index AS instances_launch_index, instances.key_name AS instances_key_name, instances.key_data AS instances_key_data, instances.power_state AS instances_power_state, instances.vm_state AS instances_vm_state, instances.task_state AS instances_task_state, instances.memory_mb AS instances_memory_mb, instances.vcpus AS instances_vcpus, instances.root_gb AS instances_root_gb, instances.ephemeral_gb AS instances_ephemeral_gb, instances.ephemeral_key_uuid AS instances_ephemeral_key_uuid, instances.host AS instances_host, instances.node AS instances_node, instances.instance_type_id AS instances_instance_type_id, instances.user_data AS instances_user_data, instances.reservation_id AS instances_reservation_id, instances.launched_at AS instances_launched_at, instances.terminated_at AS instances_terminated_at, instances.availability_zone AS instances_availability_zone, instances.display_name AS instances_display_name, instances.display_description AS instances_display_description, instances.launched_on AS instances_launched_on, instances.locked AS instances_locked, instances.locked_by AS instances_locked_by, instances.os_type AS instances_os_type, instances.architecture AS instances_architecture, instances.vm_mode AS instances_vm_mode, instances.uuid AS instances_uuid, instances.root_device_name AS instances_root_device_name, instances.default_ephemeral_device AS instances_default_ephemeral_device, instances.default_swap_device AS instances_default_swap_device, instances.config_drive AS instances_config_drive, instances.access_ip_v4 AS instances_access_ip_v4, instances.access_ip_v6 AS instances_access_ip_v6, instances.auto_disk_config AS instances_auto_disk_config, instances.progress AS instances_progress, instances.shutdown_terminate AS instances_shutdown_terminate, instances.disable_terminate AS instances_disable_terminate, instances.cell_name AS instances_cell_name, instances.cleaned AS instances_cleaned 
    FROM instances 
    WHERE instances.terminated_at IS NULL OR instances.terminated_at > :terminated_at_1
    ---------------------x


    ---------------------> LIMIT
    SELECT instances.created_at AS instances_created_at, instances.updated_at AS instances_updated_at, instances.deleted_at AS instances_deleted_at, instances.deleted AS instances_deleted, instances.id AS instances_id, instances.user_id AS instances_user_id, instances.project_id AS instances_project_id, instances.image_ref AS instances_image_ref, instances.kernel_id AS instances_kernel_id, instances.ramdisk_id AS instances_ramdisk_id, instances.hostname AS instances_hostname, instances.launch_index AS instances_launch_index, instances.key_name AS instances_key_name, instances.key_data AS instances_key_data, instances.power_state AS instances_power_state, instances.vm_state AS instances_vm_state, instances.task_state AS instances_task_state, instances.memory_mb AS instances_memory_mb, instances.vcpus AS instances_vcpus, instances.root_gb AS instances_root_gb, instances.ephemeral_gb AS instances_ephemeral_gb, instances.ephemeral_key_uuid AS instances_ephemeral_key_uuid, instances.host AS instances_host, instances.node AS instances_node, instances.instance_type_id AS instances_instance_type_id, instances.user_data AS instances_user_data, instances.reservation_id AS instances_reservation_id, instances.launched_at AS instances_launched_at, instances.terminated_at AS instances_terminated_at, instances.availability_zone AS instances_availability_zone, instances.display_name AS instances_display_name, instances.display_description AS instances_display_description, instances.launched_on AS instances_launched_on, instances.locked AS instances_locked, instances.locked_by AS instances_locked_by, instances.os_type AS instances_os_type, instances.architecture AS instances_architecture, instances.vm_mode AS instances_vm_mode, instances.uuid AS instances_uuid, instances.root_device_name AS instances_root_device_name, instances.default_ephemeral_device AS instances_default_ephemeral_device, instances.default_swap_device AS instances_default_swap_device, instances.config_drive AS instances_config_drive, instances.access_ip_v4 AS instances_access_ip_v4, instances.access_ip_v6 AS instances_access_ip_v6, instances.auto_disk_config AS instances_auto_disk_config, instances.progress AS instances_progress, instances.shutdown_terminate AS instances_shutdown_terminate, instances.disable_terminate AS instances_disable_terminate, instances.cell_name AS instances_cell_name, instances.cleaned AS instances_cleaned 
    FROM instances 
    WHERE instances.terminated_at IS NULL OR instances.terminated_at > :terminated_at_1 ORDER BY instances.id ASC
     LIMIT :param_1
    ---------------------x
  • How's Horizon currently using this data?
$ grep -r server_usages *
openstack_dashboard/api/nova.py:    _attrs = ['start', 'server_usages', 'stop', 'tenant_id',
openstack_dashboard/api/nova.py:        return sum(1 for s in self.server_usages if s['ended_at'] is None)
openstack_dashboard/api/nova.py:        return sum(s['vcpus'] for s in self.server_usages
openstack_dashboard/api/nova.py:        return sum(s['local_gb'] for s in self.server_usages
openstack_dashboard/api/nova.py:        return sum(s['memory_mb'] for s in self.server_usages
openstack_dashboard/test/test_data/nova_data.py:    "server_usages": [
openstack_dashboard/usage/base.py:        [instance_list.extend(u.server_usages) for u in self.usage_list]
openstack_dashboard/usage/base.py:        if hasattr(usage, 'server_usages'):
openstack_dashboard/usage/base.py:            for server_usage in usage.server_usages:
openstack_dashboard/usage/base.py:        usage.server_usages = instances

How does the data displayed via Horizon differ from the API response?

$ time curl -s -H "X-Auth-Token:46597075808c4995902589e99112fc4a" http://192.168.122.32:8774/v2.1/050ad8214ccb4c5e88185c9cdb415bbe/os-simple-tenant-usage?detailed=0 | python -m json.tool
{
    "tenant_usages": [
        {
            "start": "2016-09-30T07:50:37.398376",
            "stop": "2016-09-30T07:50:37.398397",
            "tenant_id": "050ad8214ccb4c5e88185c9cdb415bbe",
            "total_hours": 3.033333333333361e-06,
            "total_local_gb_usage": 0.0,
            "total_memory_mb_usage": 0.00019413333333333512,
            "total_vcpus_usage": 3.033333333333361e-06
        },
        {
            "start": "2016-09-30T07:50:37.398376",
            "stop": "2016-09-30T07:50:37.398397",
            "tenant_id": "68dae576d7d54baeb27f13b4eb3f0ae8",
            "total_hours": 5.833333333333333e-09,
            "total_local_gb_usage": 0.0,
            "total_memory_mb_usage": 3.733333333333333e-07,
            "total_vcpus_usage": 5.833333333333333e-09
        }
    ]
}

$ cat ~/Downloads/usage.csv 
Usage Report For Period:,2016-09-30,2016-09-30
Active Instances:,521
Total VCPU Usage (Hours):,4076.31
Total Active RAM (MB):,33344
Total Memory Usage (Hours):,260883.72
Total Disk Size (GB):,0
Total Disk Usage (Hours):,0.00
Project Name,VCPUs,RAM (MB),Disk (GB),Usage (Hours)
alt_demo,520,33280,0,4068.48
invisible_to_admin,1,64,0,7.82
Active Instances: 521
Active RAM: 32.6GB
This Period's VCPU-Hours: 4069.41
This Period's GB-Hours: 0.00
This Period's RAM-Hours: 260442.45

Project Name: alt_demo
VCPUs: 520
Disk: 0Bytes
RAM: 32.5GB
VCPU Hours: 4061.60
Disk GB Hours: 0.00
Memory MB Hours: 259942.56

Project Name: invisible_to_admin 
VCPUs: 1
Disk: 0Bytes
RAM: 64MB
VCPU Hours: 7.81
Disk GB Hours: 0.00
Memory MB Hours: 499.89
  • Manually testing the changes against devstack:
$ nova help usage
usage: nova usage [--start <start>] [--end <end>] [--tenant <tenant-id>]
                  [--marker <marker>] [--limit <limit>]

Show usage data for a single tenant. (Supported by API versions '2.0' -
'2.latest') [hint: use '--os-compute-api-version' flag to show help message
for proper version]

Optional arguments:
  --start <start>       Usage range start date ex 2012-01-20. (default: 4
                        weeks ago)
  --end <end>           Usage range end date, ex 2012-01-20. (default:
                        tomorrow)
  --tenant <tenant-id>  UUID of tenant to get usage for.
  --marker <marker>     The last instance UUID of the previous page; displays
                        usage for instances after "marker".
  --limit <limit>       Maximum number of instances to display usage
                        information for. If limit is bigger than
                        'osapi_max_limit' option of Nova API, limit
                        'osapi_max_limit' will be used instead.

$ nova usage
Usage from 2016-10-21 to 2016-11-19:
+---------+--------------+-----------+---------------+
| Servers | RAM MB-Hours | CPU Hours | Disk GB-Hours |
+---------+--------------+-----------+---------------+
| 2       | 7.79         | 0.12      | 0.00          |
+---------+--------------+-----------+---------------+
$ nova usage --limit=1
Usage from 2016-10-21 to 2016-11-19:
+---------+--------------+-----------+---------------+
| Servers | RAM MB-Hours | CPU Hours | Disk GB-Hours |
+---------+--------------+-----------+---------------+
| 1       | 5.43         | 0.08      | 0.00          |
+---------+--------------+-----------+---------------+
  • Test the REST API with the new microversion
$ nova usage --limit=1
Usage from 2016-11-01 to 2016-11-30:
+---------+--------------+-----------+---------------+
| Servers | RAM MB-Hours | CPU Hours | Disk GB-Hours |
+---------+--------------+-----------+---------------+
| 1       | 16752.50     | 261.76    | 0.00          |
+---------+--------------+-----------+---------------+

$ curl -s -H "X-Auth-Token:d7daf450cffb4bddaca4139cc574b657" -H "X-OpenStack-Nova-API-Version: 2.39" "http://192.168.122.172:8774/v2.1/os-simple-tenant-usage?detailed=1&limit=1" | python -m json.tool
{
    "tenant_usages": [
        {
            "server_usages": [
                {
                    "ended_at": null,
                    "flavor": "m1.nano",
                    "hours": 6.388888888888889e-09,
                    "instance_id": "77112df2-b913-4e55-b4af-c155dbebd347",
                    "local_gb": 0,
                    "memory_mb": 64,
                    "name": "instance-1",
                    "started_at": "2016-11-18T20:51:06.000000",
                    "state": "active",
                    "tenant_id": "2cc8a61bd7ae442d9f8ec97ec767d960",
                    "uptime": 942403,
                    "vcpus": 1
                }
            ],
            "start": "2016-11-29T18:37:49.117289",
            "stop": "2016-11-29T18:37:49.117312",
            "tenant_id": "2cc8a61bd7ae442d9f8ec97ec767d960",
            "total_hours": 6.388888888888889e-09,
            "total_local_gb_usage": 0.0,
            "total_memory_mb_usage": 4.088888888888889e-07,
            "total_vcpus_usage": 6.388888888888889e-09
        }
    ],
    "tenant_usages_links": [
        {
            "href": "http://192.168.122.172:8774/v2.1/os-simple-tenant-usage?detailed=1&limit=1&marker=77112df2-b913-4e55-b4af-c155dbebd347",
            "rel": "next"
        }
    ]
}
  • Test the next link
$ curl -s -H "X-Auth-Token:d7daf450cffb4bddaca4139cc574b657" -H "X-OpenStack-Nova-API-Version: 2.39" "href": "http://192.168.122.172:8774/v2.1/os-simple-tenant-usage?detailed=1&limit=1&marker=77112df2-b913-4e55-b4af-c155dbebd347" | python -m json.tool
{
    "tenant_usages": [
        {
            "server_usages": [
                {
                    "ended_at": null,
                    "flavor": "m1.nano",
                    "hours": 5.2777777777777784e-09,
                    "instance_id": "f079e394-de53-457b-b350-bb5ecc685cdd",
                    "local_gb": 0,
                    "memory_mb": 64,
                    "name": "instance-2",
                    "started_at": "2016-11-18T20:51:38.000000",
                    "state": "active",
                    "tenant_id": "2cc8a61bd7ae442d9f8ec97ec767d960",
                    "uptime": 942491,
                    "vcpus": 1
                }
            ],
            "start": "2016-11-29T18:39:49.234765",
            "stop": "2016-11-29T18:39:49.234784",
            "tenant_id": "2cc8a61bd7ae442d9f8ec97ec767d960",
            "total_hours": 5.2777777777777784e-09,
            "total_local_gb_usage": 0.0,
            "total_memory_mb_usage": 3.377777777777778e-07,
            "total_vcpus_usage": 5.2777777777777784e-09
        }
    ],
    "tenant_usages_links": [
        {
            "href": "http://192.168.122.172:8774/v2.1/os-simple-tenant-usage?detailed=1&limit=1&marker=f079e394-de53-457b-b350-bb5ecc685cdd",
            "rel": "next"
        }
    ]
}
  • Test what happens when you hit the end of the road
$ curl -s -H "X-Auth-Token:d7daf450cffb4bddaca4139cc574b657" -H "X-OpenStack-Nova-API-Version: 2.39" "href": "http://192.168.122.172:8774/v2.1/os-simple-tenant-usage?detailed=1&limit=1&marker=f079e394-de53-457b-b350-bb5ecc685cdd" | python -m json.tool
{
    "tenant_usages": []
}
  • Here are the Usage items, post response parse:
    ('total_hours', 49.71047423333333)
    ('total_memory_mb_usage', 25451.762807466665)
    ('_info', {u'total_hours': 49.71047423333333, u'total_memory_mb_usage': 25451.762807466665, u'total_vcpus_usage': 49.71047423333333, u'total_local_gb_usage': 0.0, u'start': u'2011-12-25 19:48:41.750687', u'server_usages': [{u'vcpus': 1, u'uptime': 27035, u'name': u'f15image1', u'started_at': u'2012-01-20 18:06:06.479998', u'state': u'active', u'flavor': u'm1.tiny', u'ended_at': None, u'hours': 49.71047423333333, u'local_gb': 0, u'tenant_id': u'7b0a1d73f8fb41718f3343c207597869', u'memory_mb': 512}], u'tenant_id': u'7b0a1d73f8fb41718f3343c207597869', u'stop': u'2012-01-22 19:48:41.750722'})
    ('total_vcpus_usage', 49.71047423333333)
    ('manager', <novaclient.v2.usage.UsageManager object at 0x1067161d0>)
    ('total_local_gb_usage', 0.0)
    ('x_openstack_request_ids', [])
    ('stop', u'2012-01-22 19:48:41.750722')
    ('server_usages', [{u'vcpus': 1, u'uptime': 27035, u'name': u'f15image1', u'started_at': u'2012-01-20 18:06:06.479998', u'state': u'active', u'flavor': u'm1.tiny', u'ended_at': None, u'hours': 49.71047423333333, u'local_gb': 0, u'tenant_id': u'7b0a1d73f8fb41718f3343c207597869', u'memory_mb': 512}])
    ('_loaded', True)
    ('start', u'2011-12-25 19:48:41.750687')
    ('tenant_id', u'7b0a1d73f8fb41718f3343c207597869')
⚠️ **GitHub.com Fallback** ⚠️