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条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部