SoftLayer API CPU使用率不匹配 [英] SoftLayer API CPU usage mismatch

查看:84
本文介绍了SoftLayer API CPU使用率不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用PHP客户端在其中一台虚拟服务器上查询API的CPU使用率:

I tried querying the API for CPU usage on one of our virtual servers, using the PHP client:

$user = 'my_user';
$key = 'my_key';
$server = 24819101;

$client = \SoftLayer\SoapClient::getClient('SoftLayer_Virtual_Guest', $server, $user, $key);

$usage = $client->getCpuMetricDataByDate(date('Y-m-d H:i:s', strtotime('-2 HOUR')));

对API的调用是可以的,结果之一是这样的:

The call to the API is ok, and one of the results is like this:

array(
  'counter' => 2.096,
  'dateTime' => '2017-01-24T14:00:00+01:00',
  'type' => 'cpu0',
)

我将其读为今天下午2点的第一个CPU负载约为2%".

I read this as "the first CPU, at 2 PM today, was at about 2% load".

但是,如果我从控制面板上查看CPU图表,我发现今天下午2点的CPU率为76.5%

However, if I go see the CPU chart from the control panel, I see that at 2 PM today the CPU was at 76.5%

两个值相等不应该相等吗?

Shouldn't the two values be equal be equal?

推荐答案

Softlayer门户用于显示CPU使用率的所有API方法的正确性不是SoftLayer_Virtual_Guest:getCpuMetricDataByDate此方法显示平均CPU使用率,另一方面Softlayer的门户显示最大CPU使用率,它使用以下方法:

Firt of all the API method that the Softlayer's portal uses to display the CPU usage is not SoftLayer_Virtual_Guest:getCpuMetricDataByDate this method displays the average CPU usage, in another hand the Softlayer's portal displays the max CPU usages and it uses this method:

http://sldn.softlayer.com/reference/services/SoftLayer_Metric_Tracking_Object/getSummaryData

这是使用RESTful的示例:

This is an example using RESTful:

POST https://$USER:$APIKEY@api.softlayer.com/rest/v3.1/SoftLayer_Metric_Tracking_Object/$METIRCID/getSummaryData

PAYLOAD:

{
  "parameters": [
    "2017-01-24T00:00:00-00:00",
    "2017-01-25T00:00:00-00:00",
    [
      {
        "keyName": "CPU0",
        "summaryType": "max"
      }
    ],
    600
  ]
}

使用PHP会是这样的:

using PHP it would be something like this:

$metricID = 11111;
$client = \SoftLayer\SoapClient::getClient('SoftLayer_Metric_Tracking_Object', $metricID, $user, $key);

$types = array();
$type = new stdClass();
$type -> keyName = "CPU0";
$type -> summaryType= "max";
$types[] =  $type

$usage = $client->getCpuMetricDataByDate("2017-01-24T00:00:00-00:00", "2017-01-25T00:00:00-00:00",$types,600);

因此,您需要获取可以使用此方法的metricID:

So you need to get the metricID for that you can use this method:

http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/getMetricTrackingObjectId

这里是使用RESTFUl的示例:

here an example using RESTFUl:

GET https://api.softlayer.com/rest/v3.1/SoftLayer_Virtual_Guest/$VirtualGuestId/getMetricTrackingObjectId

要指出的另一件事是时间,您需要确保门户和您的代码使用相同的时区,否则您将在门户和API中同时看到不同的数据.该API将使用执行请求的用户所在的时区显示时间,您可以通过以下方式查看用户所在的时区:

Another thing to point out is the time, you need to make sure that the portal and your code are using the same timezone otherwise you will see different data for the same time in portal and API. The API will show the time using the timezone of the user that uses to perform the request, you can see the user timezone by:

  1. 转到Softlayer的门户网站
  2. 点击帐户"菜单项->用户"
  3. 点击您的用户
  4. 查看时区

我建议您首先显示所有数据,然后验证确定的时区的数据是否相同,如果不是,则需要查看时区并进行更改,直到它们显示相同的数据为止

i suggest you first display all the data then verify if the data are the same for a determinate timezone, if they are not you need to review the timezone and make the changes until they display the same data

致谢

这篇关于SoftLayer API CPU使用率不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆