duanlongnao0028 2016-04-12 01:28
浏览 83
已采纳

远程检查IBM Bluemix PHP实例的CPU,内存和磁盘空间

Remotely check CPU, memory and disk space IBM Bluemix PHP instance.

I have a php instance running in IBM Bluemix.

Now I want to check the CPU, Memory and Disk Space from an external program by calling a php web page.

For CPU I tried the following function:

function get_server_cpu_usage(){
    $load = sys_getloadavg();
    $cores = shell_exec("grep 'model name' /proc/cpuinfo | wc -l");
    $load[2] = ($load[2] / $cores) * 100;
    return $load[2];
}

For Memory I use the following function:

memory_get_usage(true)

For Disk Space I use the following function:

disk_free_space("/") 

But when I compare these results with the results provided by the IBM Bluemix Console, they are different.

Is there a correct way to externally monitor these values?

  • 写回答

3条回答 默认 最新

  • douxian5963 2016-04-12 07:53
    关注

    You can retrieve that information using CF API REST call. You can find the CF APIs documentation here:

    In this specific case you could do a curl call from your php application and parse the JSON response for CPU, Memory and Disk Space information.

    curl "https://api.ng.bluemix.net/v2/apps/YOURAPP_GUID/summary" -X GET -H "Authorization: bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoidWFhLWlkLTQyNCIsImVtYWlsIjoiZW1haWwtMjkzQHNvbWVkb21haW4uY29tIiwic2NvcGUiOlsiY2xvdWRfY29udHJvbGxlci5hZG1pbiJdLCJhdWQiOlsiY2xvdWRfY29udHJvbGxlciJdLCJleHAiOjE0NjA1MDY2NjF9.iUpeFnPKDWf3sxvDB0RF2_nSLAkqLZP7iN6Nx0bWE-Q"

    You can retrieve the Authorization header with:

    cf oauth-token
    

    after login to IBM Bluemix (cf login)

    If you want retrieve the auth-token from your application you should use another REST API before running the first curl get.

    curl -s -X POST -H "Accept-Encoding: application/json" -d "grant_type=password&password=YOURPASSWORD&scope=&username=YOURUSERNAME" -u "cf:" https://login.ng.bluemix.net/UAALoginServerWAR/oauth/token

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 llama.cpp项目中为什么超过上下文窗口就报错
  • ¥15 基于stc89c52单片机的延时小夜灯
  • ¥15 VQAV2现在都是怎么做evaluation的啊
  • ¥20 C#添加、更新MYSQL数据库问题
  • ¥15 ambari部署hadoop集群中的问题
  • ¥15 分析照片像素时,怎样剔除照片背景像素
  • ¥15 Cytoscape导入问题
  • ¥15 关于#lstm#的问题:我想利用一个地方的四组数据来预测第五组数据,如果想预测出另外一个地方(只有前四组数据)的第五组数据(相关搜索:预测模型)
  • ¥15 windows窗口外边框分区是什么?(qt应用)
  • ¥15 使用lightgbm框架,对糖尿病趋势进行预测。