Using Gnocchi command-line tool

After enabling metering, you can get access to your compute resource metrics either via REST API or by using the Gnocchi command-line tool. To be able to use the tool, connect to the OpenStack command-line interface to authorize further gnocchi commands (refer to Connecting to OpenStack command-line interface):

# kolla-ansible post-deploy
# source /etc/kolla/admin-openrc.sh

Now you can use the gnocchi command with the --insecure option. You can see the full list of gnocchi commands in the OpenStack documentation.

Viewing resources

To view the existing resources, use the gnocchi resource list command. For example:

# gnocchi --insecure resource list -c id -c type -c project_id
+---------------+----------------------------+------------+
| id            | type                       | project_id |
+---------------+----------------------------+------------+
| 238597c7<...> | volume                     | c1bf1<...> |
| 3c78558f<...> | instance                   | c1bf1<...> |
| 44f1896f<...> | instance_network_interface | c1bf1<...> |
| 880e9efc<...> | instance_disk              | c1bf1<...> |
+---------------+----------------------------+------------+

The output shows that the compute cluster hosts one virtual machine with one NIC and one disk that is also present as a volume.

Viewing metrics for resources

To check all the available metrics for the resources, use the gnocchi metric list command. For example:

# gnocchi --insecure metric list
+-------------+-------+-------------------------------+---------+-------------+
| id          | <...> | name                          | unit    | resource_id |
+-------------+-------+-------------------------------+---------+-------------+
| 243c7a<...> | <...> | disk.root.size                | GB      | 3c7855<...> |
| 365e45<...> | <...> | network.outgoing.packets      | packet  | 44f189<...> |
| 4fbd3e<...> | <...> | disk.device.read.requests     | request | 880e9e<...> |
| 54519f<...> | <...> | compute.instance.booting.time | sec     | 3c7855<...> |
| 5e1406<...> | <...> | disk.device.write.bytes       | B       | 880e9e<...> |
| 66a96c<...> | <...> | vcpus                         | vcpu    | 3c7855<...> |
| 722ea9<...> | <...> | memory                        | MB      | 3c7855<...> |
| 7c961a<...> | <...> | disk.device.write.requests    | request | 880e9e<...> |
| 87e9fb<...> | <...> | network.incoming.packets      | packet  | 44f189<...> |
| 9d5632<...> | <...> | disk.device.read.bytes        | B       | 880e9e<...> |
| b8be8f<...> | <...> | cpu                           | ns      | 3c7855<...> |
| c1961b<...> | <...> | disk.ephemeral.size           | GB      | 3c7855<...> |
| c9b61e<...> | <...> | volume.size                   | GB      | 238597<...> |
| d06a58<...> | <...> | network.outgoing.bytes        | B       | 44f189<...> |
| e2d998<...> | <...> | network.incoming.bytes        | B       | 44f189<...> |
| eaac2b<...> | <...> | memory.usage                  | MB      | 3c7855<...> |
+-------------+-------+-------------------------------+---------+-------------+

Viewing measures for metrics

To view measures for a particular metric, use the gnocchi measures show command. For example:

# gnocchi --insecure measures show cpu \
--resource-id 3c78558f-08bf-47e2-ba3e-bdb13e7b25bb +---------------------------+-------------+-------------+ | timestamp | granularity | value | +---------------------------+-------------+-------------+ | 2019-12-11T17:05:00+03:00 | 300.0 | 2.2756e+11 | | 2019-12-11T17:10:00+03:00 | 300.0 | 2.8897e+11 | | 2019-12-11T17:15:00+03:00 | 300.0 | 3.7367e+11 | | 2019-12-11T17:20:00+03:00 | 300.0 | 4.64e+11 | | 2019-12-11T17:25:00+03:00 | 300.0 | 7.6104e+11 | +---------------------------+-------------+-------------+

By default, the mean aggregation method is used. To obtain how much CPU time is consumed per interval, use the --aggregation rate:mean option:

# gnocchi --insecure measures show cpu --aggregation rate:mean \
--resource-id 3c78558f-08bf-47e2-ba3e-bdb13e7b25bb
+---------------------------+-------------+---------------+
| timestamp                 | granularity |         value |
+---------------------------+-------------+---------------+
| 2019-12-11T17:10:00+03:00 |       300.0 | 61410000000.0 |
| 2019-12-11T17:15:00+03:00 |       300.0 | 84700000000.0 |
| 2019-12-11T17:20:00+03:00 |       300.0 | 90330000000.0 |
| 2019-12-11T17:25:00+03:00 |       300.0 |    2.9704e+11 |
| 2019-12-11T17:30:00+03:00 |       300.0 |      3.64e+11 |
+---------------------------+-------------+---------------+

Viewing outgoing traffic usage

The bandwidth metric that can show outgoing traffic usage is not available by default. To be able to use it, you need to configure it first. Do the following:

  1. Create a meter by using the openstack network meter create command. For example, to create the meter outgoing_traffic in the project project1 within the domain domain1, run:

    # openstack --insecure network meter create outgoing_traffic --share \
    --project project1 --project-domain domain1
  2. Create a rule that includes all outgoing network traffic by specifying the CIDR 0.0.0.0/0 and the egress traffic direction. For example:

    # openstack --insecure network meter rule create outgoing_traffic --egress \
    --include --remote-ip-prefix 0.0.0.0/0
  3. Create a rule that excludes the outgoing network traffic of your physical compute network by specifying its CIDR. For example, for the physical compute network with the CIDR 10.10.10.0/24, run:

    # openstack --insecure network meter rule create outgoing_traffic --egress \
    --exclude --remote-ip-prefix 10.10.10.0/24

Now, you can proceed to creating virtual routers and assigning floating IP addresses to virtual machines in the self-service panel. The bandwidth metric will only account outgoing VM traffic via virtual routers. You can view measures for this metric as follows:

  1. Find out the resource_id for the bandwidth metric. For example:

    # gnocchi --insecure metric list | grep bandwidth
    | dce6d500-37c9<…> | low | bandwidth | B | cfc0cbb3-ff05-4b25-be7c-ab7f872e4180 |
  2. View measures for the resource. For example:

    # gnocchi --insecure measures show --resource-id cfc0cbb3-ff05-4b25-be7c-ab7f872e4180 bandwidth
    +---------------------------+-------------+---------+
    | timestamp                 | granularity |   value |
    +---------------------------+-------------+---------+
    | 2021-10-03T02:40:00+03:00 |       300.0 |  1045.0 |
    | 2021-10-03T02:50:00+03:00 |       300.0 |  1907.0 |
    | 2021-10-03T02:55:00+03:00 |       300.0 | 15932.0 |
    +---------------------------+-------------+---------+

Changing retention period for metrics

Extending retention period increases the Gnocchi database size insignificantly compared to its default value.

You can change the retention period for metrics through an archive policy. By default, the ceilometer-low-rate and low policies are used to store metrics. Note that you cannot change the metering granularity for these policies.

To show the details of a particular archive policy, use the gnocchi archive-policy show command. For example:

# gnocchi --insecure archive-policy show ceilometer-low-rate
+---------------------+---------------------------------------+
| Field               | Value                                 |
+---------------------+---------------------------------------+
| aggregation_methods | rate:mean, mean                       |
| back_window         | 0                                     |
| definition          | - points: 8640, granularity: 0:05:00, |
|                     |   timespan: 30 days, 0:00:00          |
| name                | ceilometer-low-rate                   |
+---------------------+---------------------------------------+

In the output:

  • 8640 points shows how many aggregates will be retained
  • the granularity of 5 minutes defines the time between two aggregates
  • the timespan of 30 days specifies the retention period for aggregates

To sum it up, metrics with the ceilometer-low-rate policy will keep 8640 computed aggregates for one month with 5-minute granularity.

To change the policy definition, use the gnocchi archive-policy update command. To calculate the correct number of points required for the desired timespan, refer to this formula: points = timespan \ granularity. For example, to keep aggregates for 2 months with the 5-minute granularity, specify 17280 points:

# gnocchi --insecure archive-policy update ceilometer-low-rate \
-d points:17280,granularity:0:05:00,timespan:60d
+---------------------+----------------------------------------+
| Field               | Value                                  |
+---------------------+----------------------------------------+
| aggregation_methods | rate:mean, mean                        |
| back_window         | 0                                      |
| definition          | - points: 17280, granularity: 0:05:00, |
|                     |   timespan: 60 days, 0:00:00           |
| name                | ceilometer-low-rate                    |
+---------------------+----------------------------------------+