Ask Your Question
0

Php API call for Ceilometer

asked 2014-02-06 01:11:20 -0500

Lokesh gravatar image

updated 2014-02-06 16:53:27 -0500

smaffulli gravatar image

I am a newbie for this Openstack .Can anyone please suggest me regarding PHP api Calls if any in the openstack .I am really got stuck in passing the parameters for the api calls .

For ex :- for the API call v2/meters/cpu/statistics ... i need to search between 2 dates . So how can pass the parameters here

edit retag flag offensive close merge delete

Comments

I'd suggest you to show some of the code you're thinking of using so others can give you suggestions. Don't expect here people problems instead of you.

smaffulli gravatar imagesmaffulli ( 2014-02-06 16:54:52 -0500 )edit

3 answers

Sort by ยป oldest newest most voted
0

answered 2014-02-07 00:46:42 -0500

Lokesh gravatar image

Hello smaffulli,

      Here am attaching the PHP Code Snippet where i am trying to access the Cpu statistics API call by passing the parameters .It works fine if i use jst the API call without the parameters . i.e (http://192.168.0.198:8777/v2/meters/cpu/statistics).

   $url_send='http://192.168.0.198:8777/v2/meters/cpu/statistics{field:timestamp,
   op: ge,
   value: 2014-01-01T00:00:00,
   field: timestamp,
   op: lt,
   value: 2014-05-01T00:00:00}';

$header1="X-Auth-Token:".$tokenid;
$header2="Content-Type: application/json";

$curl = curl_init();
     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
 curl_setopt($curl, CURLOPT_POST, false);
 curl_setopt($curl, CURLOPT_URL, $url_send);
 curl_setopt($curl, CURLOPT_HTTPHEADER,array($header1,$header2));
 curl_setopt($curl, CURLOPT_HEADER, false);
 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
 $response = curl_exec($curl);

             Can you just clarify me if there ia anything wrong in the above code .

Thanks in Advance

edit flag offensive delete link more
0

answered 2014-03-18 16:17:27 -0500

updated 2014-03-18 16:18:45 -0500

you need to pass the parameter q for querying and pass it through header

like this

'q': [{"field": "timestamp", "op": "ge", "value": "2013-06-01T00:00:00"}, {"field": "timestamp", "op": "lt", "value": "2013-07-01T00:00:00"}, {"field": "resource_id", "op": "eq", "value": "64da755c-9120-4236-bee1-54acafe24980"}]

$url_send='http://192.168.0.198:8777/v2/meters/cpu/statistics $header='q': [{"field": "timestamp", "op": "ge", "value": "2013-06-01T00:00:00"}, {"field": "timestamp", "op": "lt", "value": "2013-07-01T00:00:00"}, {"field": "resource_id", "op": "eq", "value": "64da755c-9120-4236-bee1-54acafe24980"}]; $header1="X-Auth-Token:".$tokenid; $header2="Content-Type: application/json";

$curl = curl_init(); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_POST, false); curl_setopt($curl, CURLOPT_URL, $url_send); curl_setopt($curl, CURLOPT_HTTPHEADER,array($header,$header1,$header2)); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($curl);

make sure that $header is properly closed in double quotations ( i havent done at the top) i haven't tested it but feel free to test and let me know

edit flag offensive delete link more
0

answered 2014-03-25 05:56:34 -0500

ZhiQiang Fan gravatar image

updated 2014-03-25 05:59:54 -0500

firstly, ceilometer api argument can be different between releases, so you should read the http://api.openstack.org/api-ref-telemetry.html (http://api.openstack.org/api-ref-tele...)

if you find that doc is not useful, then you can investigate and test for your own, the trick is use --debug option for command line interface, know as python-ceilometerclient, for example (i use devstack master)

ceilometer --debug statistics -m cpu -q x=y

here i use a wrong field for --query argument, which will cause a 400 error, that is what you need to see, because it will return a valid set of query field for you:

curl -i -X GET -H 'X-Auth-Token: real-token' -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'User-Agent: python-ceilometerclient' http://192.168.0.206:8777/v2/meters/cpu/statistics?q.field=x&q.op=eq&q.type=&q.value=y

ceilometerclient.exc.HTTPBadRequest: HTTPBadRequest (HTTP 400) ERROR Unknown argument: "x": unrecognized field in query: [<query u'x'="" eq="" u'y'="" none="">], valid keys: set(['end', 'start', 'metaquery', 'meter', 'project', 'source', 'user', 'start_timestamp_op', 'resource', 'end_timestamp_op', 'message_id'])

then I can format my rest request with start=2013-03-24T12:00:00 and end=2013-03-25T00:00:00 such as:

http://192.168.0.206:8777/v2/meters/cpu/statistics?q.field=start&q.op=eq&q.type=&q.value=2014-03-24T12%3A00%3A00&q.field=end&q.op=eq&q.value=2014-03-25T00%3A00%3A00

note that the ':' has been encoded to %3A

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower

Stats

Asked: 2014-02-06 01:11:20 -0500

Seen: 644 times

Last updated: Mar 25 '14