thread info from clapi: message queue depth and proto error message

Homepage Clovertech Forums Cloverleaf thread info from clapi: message queue depth and proto error message

Tagged: 

  • Creator
    Topic
  • #112533
    Arie Klop
    Participant

    I am trying to get thread info from clapi for our custom monitoring tool (php).

    Super easy with PHP and CURL, just by calling
    <pre>https://hostname:15037/clapi/api/site/sitename/command/thread/state</pre&gt;
    but i am missing two critical pieces of info per thread:

    the number of pending messages and proto err msg. (as seen in normal thread status window).

    Is there a different way to get this, could they be added in a future release of clapi? Without them i am missing the two most important runtime metrics, aside from threads and processes being up or down.

     

Viewing 1 reply thread
  • Author
    Replies
    • #113248
      Rob Lindsey
      Participant

      I have not played around with the CLAPI as of yet.

      Would you be interested in sharing a small sample of your PHP / CURL and clapi calls?

      Thanks

      Rob

    • #113265
      Arie Klop
      Participant

      Sure, no problem. I have created a small function execCLAPICmd which executes an http request. As you can see, it always uses http POST. It’s exceedingly simple.

      <?php

      $authhash = base64_encode(“user:password”);

      $headers = array(“Authorization: Basic $authhash”);
      $site = “sitename”;
      $process = “processname”;
      $thread = “threadname”;
      $server = “ourserver.ourdomain.com”;

      $cmd = “clapi/api/site/$site/command/process/$process/thread/$thread/start”;

      $result = execCLAPICmd($server, 15037, $headers, $cmd);
      $result = json_decode($result);
      $result = $result->$thread;

      echo “status thread: $thread: {$result->state}<br/>”;

      var_dump($result); //dump rest of the result object

      function execCLAPICmd($hostname, $port, $headers, $cmd) {

      //first get xcsrf token

      $xcsrf_token_url = “https://$hostname:$port/clapi/api/security/csrf&#8221;;
      $ch = curl_init($xcsrf_token_url);

      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
      curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
      $cookiefile = ‘/tmp/curl-session’; //must be valid directory!
      curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
      curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);

      $xcsrf_response = curl_exec($ch);

      $xcsrf_response_err = curl_error($ch);

      if(! empty($xcsrf_response_err)) {
      $xcsrf_response = $xcsrf_response_err;
      }

      $xcsrf_token_obj = json_decode($xcsrf_response);

      $xcsrf_token = $xcsrf_token_obj->csrf;

      $headers[] = “X-CSRF-TOKEN: $xcsrf_token”;

      $url = “https://$hostname:$port/$cmd&#8221;;

      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
      curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
      curl_setopt($ch, CURLOPT_POST, 1);
      curl_setopt($ch, CURLOPT_HEADER, 0); //set to 1 to also output headers
      curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);

      $return = curl_exec($ch);
      $cerr = curl_error($ch);

      if(! empty($cerr)) {
      $return = $cerr;
      }

      curl_close($ch);

      return $return;
      }

      ?>

      • This reply was modified 4 years, 11 months ago by Arie Klop.
Viewing 1 reply thread
  • You must be logged in to reply to this topic.

Forum Statistics

Registered Users
5,117
Forums
28
Topics
9,293
Replies
34,435
Topic Tags
286
Empty Topic Tags
10