duanlongnao0028 2016-04-12 09: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 15: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 r语言神经网络自变量重要性分析
  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢