1.1. How to use API client¶
Overview¶
Smart Data Platform Monitoring APIs are partially-compatible with "OpenStack Telemetry API v2".
Hence you can use CLI tools designed for the Openstack Ceilometer project.
This page shows how to send API requests by using the following API client.
警告
Smart Data Platform Monitoring APIs don't cover the entire of the OpenStack Telemetry API. Some python-ceilometerclient commands will not work normally.
How to use python-ceilometerclient¶
Install¶
Install python-ceilometerclient to your computer.
See OpenStack User Guide to get detailed information.
For example:
$ pip install python-ceilometerclient
Set your account information¶
Some account information (API key, API secret key, Tenant name, Keystone endpoint) are required to use the API client.
For example, in Bash you would use:
@@ -16,8 +16,8 @@
export OS_USERNAME={your_api_key}
export OS_PASSWORD={your_api_secret_key}
export OS_USER_DOMAIN_ID=default
export OS_PROJECT_ID={your_tenant_id}
export OS_AUTH_URL={keystone_api_endpoint (ex. https://keystone-jp1-ecl.api.ntt.com/v3)}
export CEILOMETER_URL={api_endpoint (ex. https://monitoring-jp1-ecl.api.ntt.com)}
Execute client commands and send requests¶
The following command is equal to List Alarms .
$ ceilometer alarm-list
Narrow down the result by specifying an alarm ID in a query.
$ ceilometer alarm-list --query 'alarm_id={alarm_id}'
Add "--debug" option to display the detailed response data.
$ ceilometer --debug alarm-list --query 'alarm_id={alarm_id}'
The following command is equal to List Meters .
$ ceilometer meter-list
The following command is equal to Show Alarm History .
$ ceilometer alarm-history {alarm_id}
Execution examples¶
$ ceilometer meter-list
+-------------------------------+-------+---------+---------------------------------------------+---------+----------------------------------+
| Name | Type | Unit | Resource ID | User ID | Project ID |
+-------------------------------+-------+---------+---------------------------------------------+---------+----------------------------------+
| cinder.disk.read.bytes | delta | byte | cinder_f4f9ce85-a442-465f-8a47-95e860ba055e | | 2cf8ebbbcb8f4b3ebba7a599bdacd5fa |
| cinder.disk.read.requests | delta | request | cinder_f4f9ce85-a442-465f-8a47-95e860ba055e | | 2cf8ebbbcb8f4b3ebba7a599bdacd5fa |
| cinder.disk.write.bytes | delta | byte | cinder_f4f9ce85-a442-465f-8a47-95e860ba055e | | 2cf8ebbbcb8f4b3ebba7a599bdacd5fa |
| cinder.disk.write.requests | delta | request | cinder_f4f9ce85-a442-465f-8a47-95e860ba055e | | 2cf8ebbbcb8f4b3ebba7a599bdacd5fa |
| nova.cpu.utilization.percents | gauge | percent | nova_f4f9ce85-a442-465f-8a47-95e860ba055e | | 2cf8ebbbcb8f4b3ebba7a599bdacd5fa |
| nova.disk.read.bytes | delta | byte | nova_f4f9ce85-a442-465f-8a47-95e860ba055e | | 2cf8ebbbcb8f4b3ebba7a599bdacd5fa |
| nova.disk.read.requests | delta | request | nova_f4f9ce85-a442-465f-8a47-95e860ba055e | | 2cf8ebbbcb8f4b3ebba7a599bdacd5fa |
| nova.disk.write.bytes | delta | byte | nova_f4f9ce85-a442-465f-8a47-95e860ba055e | | 2cf8ebbbcb8f4b3ebba7a599bdacd5fa |
| nova.disk.write.requests | delta | request | nova_f4f9ce85-a442-465f-8a47-95e860ba055e | | 2cf8ebbbcb8f4b3ebba7a599bdacd5fa |
| nova.hv.status.bool | gauge | boolean | nova_f4f9ce85-a442-465f-8a47-95e860ba055e | | 2cf8ebbbcb8f4b3ebba7a599bdacd5fa |
| nova.network.incoming.bytes | delta | byte | nova_f4f9ce85-a442-465f-8a47-95e860ba055e | | 2cf8ebbbcb8f4b3ebba7a599bdacd5fa |
| nova.network.outgoing.bytes | delta | byte | nova_f4f9ce85-a442-465f-8a47-95e860ba055e | | 2cf8ebbbcb8f4b3ebba7a599bdacd5fa |
| nova.vm.status.bool | gauge | boolean | nova_f4f9ce85-a442-465f-8a47-95e860ba055e | | 2cf8ebbbcb8f4b3ebba7a599bdacd5fa |
+-------------------------------+-------+---------+---------------------------------------------+---------+----------------------------------+
$ ceilometer alarm-list
+--------------------------------------+-----------------------+-------+----------+---------+------------+------------------------------------------------------------+------------------+
| Alarm ID | Name | State | Severity | Enabled | Continuous | Alarm condition | Time constraints |
+--------------------------------------+-----------------------+-------+----------+---------+------------+------------------------------------------------------------+------------------+
| 4b3da454-e531-4d11-8883-3f6848f8880d | alarm-test-00 | ok | moderate | True | False | max(nova.cpu.utilization.percents) >= 80.0 during 1 x 10s | None |
| 9509d62a-61fe-488c-831c-eb411b854c7d | alarm-test-01 | alarm | low | True | False | max(nova.cpu.utilization.percents) > 50.0 during 1 x 10s | None |
| ba80cfa4-d3e6-48a2-a618-30fd03a13422 | user01-alarm-test-01 | alarm | moderate | False | False | max(nova.hv.status.bool) == 1.0 during 1 x 10s | None |
| fe6ece61-7568-4e1b-bcc9-1f6fee8f407d | user02-alarm-test-02 | alarm | critical | False | True | max(nova.cpu.utilization.percents) < 0.0 during 1 x 10s | None |
+--------------------------------------+-----------------------+-------+----------+---------+------------+------------------------------------------------------------+------------------+
$ ceilometer --debug alarm-list --query 'alarm_id=fe6ece61-7568-4e1b-bcc9-1f6fee8f407d'
( ... snipped ... )
DEBUG (base) Making authentication request to https://keystone-jp1-ecl.api.ntt.com/v3/auth/tokens
DEBUG (connectionpool) "POST /v3/auth/tokens HTTP/1.1" 201 9344
DEBUG (client) REQ: curl -g -i -X 'GET' 'https://monitoring-jp1-ecl.api.ntt.com/v2/alarms?q.field=alarm_id&q.op=eq&q.type=&q.value=fe6ece61-7568-4e1b-bcc9-1f6fee8f407d' -H 'User-Agent: ceilometerclient.openstack.common.apiclient' -H 'X-Auth-Token: {SHA1}65c82ad74f6073fbc1c26ddfd1412e3f46af4375'
INFO (connectionpool) Starting new HTTPS connection (1): monitoring-jp1-ecl.api.ntt.com
DEBUG (connectionpool) "GET /v2/alarms?q.field=alarm_id&q.op=eq&q.type=&q.value=fe6ece61-7568-4e1b-bcc9-1f6fee8f407d HTTP/1.1" 200 None
DEBUG (client) RESP: [200] {'Status': '200 OK', 'X-XSS-Protection': '1; mode=block', 'X-Content-Type-Options': 'nosniff', 'Transfer-Encoding': 'chunked', 'Set-Cookie': 'TS0183560f=01cce65ce1d0b92f0aeaaed79defe1910f7827ad1088c96fe36b16dc799837b3a3c93eb206; Path=/', 'Connection': 'keep-alive', 'Cache-Control': 'max-age=0, private, must-revalidate', 'Date': 'Mon, 21 Dec 2015 07:14:27 GMT', 'X-Frame-Options': 'SAMEORIGIN', 'Total': '1', 'Content-Type': 'application/json; charset=utf-8', 'Per-Page': '100'}
DEBUG (client) RESP BODY: [{"alarm_id":"fe6ece61-7568-4e1b-bcc9-1f6fee8f407d","project_id":"2cf8ebbbcb8f4b3ebba7a599bdacd5fa","user_id":"35bb4a1fc4d0479cb032a9a7dfa1dc82","name":"user02-alarm-test-02","description":"VM Status Alarm","enabled":false,"state":"alarm","repeat_actions":true,"severity":"critical","time_constraints":[],"alarm_actions":[],"ok_actions":[],"insufficient_data_actions":[],"type":"threshold","threshold_rule":{"meter_name":"nova.cpu.utilization.percents","period":10,"query":[{"field":"resource_id","op":"eq","type":"string","value":"nova_2b500672-3ddc-4452-990b-92ff30135810"}],"exclude_outliers":false,"evaluation_periods":1,"evaluation_type":"0","comparison_operator":"lt","statistic":"max","threshold":0.0},"timestamp":"2015-12-17T03:14:29+00:00","state_timestamp":"2015-12-16T12:50:01+00:00","resource_name":"nova-test-vm","deleted":true}]
+--------------------------------------+-----------------------+-------+----------+---------+------------+------------------------------------------------------------+------------------+
| Alarm ID | Name | State | Severity | Enabled | Continuous | Alarm condition | Time constraints |
+--------------------------------------+-----------------------+-------+----------+---------+------------+------------------------------------------------------------+------------------+
| fe6ece61-7568-4e1b-bcc9-1f6fee8f407d | user02-alarm-test-02 | alarm | critical | False | True | max(nova.cpu.utilization.percents) < 0.0 during 1 x 10s | None |
+--------------------------------------+-----------------------+-------+----------+---------+------------+------------------------------------------------------------+------------------+