How to Get Token
To access ceilometer, we need to get token first.
curl -si -d @token-request.json -H "Content-type: application/json" http://172.16.235.128:35357/v3/auth/tokens
where token-request.json is file that you can replace admin and password to any target tenant.
{
"auth": {
"identity": {
"methods": [
"password"
],
"password": {
"user": {
"domain": {
"name": "Default"
},
"name": "admin",
"password": "password"
}
}
},
"scope": {
"project": {
"domain": {
"name": "Default"
},
"name": "admin"
}
}
}
}
After we get token, we now can access meter by using the token we got.
Access Meters
junmeindeMacBook$ curl -H 'X-Auth-Token: 8fbfdcf3dc9c4986badaf4a281d444c6' -H 'Content-Type: application/json' http://172.16.235.128:8777/v2/meters/disk.write.bytes/statistics
[{"count": 3, "duration_start": "2016-05-04T04:40:42", "min": 318464.0, "duration_end": "2016-05-04T05:00:42", "max": 331776.0, "sum": 982016.0, "period": 0, "period_end": "2016-05-04T05:00:42", "duration": 1200.0, "period_start": "2016-05-04T04:40:42", "avg": 327338.6666666667, "groupby": null, "unit": "B"}]
take average of meters
junmeindeMacBook$ curl -H 'X-Auth-Token: 8fbfdcf3dc9c4986badaf4a281d444c6' -H 'Content-Type: application/json' http://172.16.235.128:8777/v2/meters/cpu_util/statistics?aggregate.func=avg
[{"duration_start": "2016-05-04T04:50:42", "duration_end": "2016-05-04T05:00:42", "period": 0, "duration": 600.0, "period_end": "2016-05-04T05:00:42", "aggregate": {"avg": 0.20934195882025602}, "period_start": "2016-05-04T04:50:42", "avg": 0.20934195882025602, "groupby": null, "unit": "%"}]
More examples
Here we show more complicate request including timesamap, qeury field, and query operator and their combination.
get project cpu_util information
curl -H 'X-Auth-Token: 90872f53cf534bf98292693ffe31c1ac' -H 'Content-Type: application/json' "http://localhost:8777/v2/meters/cpu_util/statistics?q.field=timestamp&q.op=ge&q.value=2014-08-20T13:34:17&q.field=project_id&q.op=eq&q.value=9aff044df2d44839bd36ee98e08ffa88"
query for a instance
curl -H 'X-Auth-Token: 90872f53cf534bf98292693ffe31c1ac' -H 'Content-Type: application/json' "http://localhost:8777/v2/meters/cpu_util/statistics?q.field=timestamp&q.op=ge&q.value=2014-08-20T13:34:17&q.field=resource_id&q.op=eq&q.value=664615f2-c9b2-4c5b-b3df-68e9f5616a1b"
An example for query filter need “ ”
curl -X GET -H 'X-Auth-Token: 90872f53cf534bf98292693ffe31c1ac' "http://localhost:8777/v2/meters/instance?q.field=metadata.event_type&q.value=compute.instance.exists"
curl -H 'X-Auth-Token: 90872f53cf534bf98292693ffe31c1ac' -H 'Content-Type: application/json' "http://localhost:8777/v2/meters/cpu_util/statistics?q.field=timestamp&q.op=ge&q.value=2014-08-20T13:34:17"
for multiple query:
curl -H 'X-Auth-Token: 90872f53cf534bf98292693ffe31c1ac' -H 'Content-Type: application/json' "http://localhost:8777/v2/meters/cpu_util/statistics?q.field=timestamp&q.op=ge&q.value=2014-08-20T13:34:17&q.field=timestamp&q.op=le&q.value=2014-08-30T13:00:00"
Code analysis (not Complete)
root@ubuntu:~/ceilometer/ceilometer/api/controllers/v2# ls
alarm_rules alarms.py base.py capabilities.py events.py __init__.py meters.py query.py resources.py root.py samples.py utils.py
We can check the API Doc (Kilo)
It's very clear that each api endpoints corresponding to a python file such as meters, query, capabilities. The most important part is ceilometer uses pecan web framework not wsgi. So it's quite difference with OpenStack framework, Paste + PasteDeploy + Routes + WebOb.
We will share the part of code analysis in feature.
No comments:
Post a Comment