0

我正在编写云监控应用程序,并且无法从 AZURE php SDK 文档中找到有用的逻辑来获取性能计数器(例如 CPU 利用率、磁盘利用率、内存使用率)。

有人可以帮忙吗?

define('PRODUCTION_SITE', false); // Controls connections to cloud or local storage 
define('AZURE_STORAGE_KEY', '<your_storage_key>'); 
define('AZURE_SERVICE', '<your_domain_extension>'); 
define('ROLE_ID', $_SERVER['RoleDeploymentID'] . '/' . $_SERVER['RoleName'] . '/' . $_SERVER['RoleInstanceID']); 
define('PERF_IN_SEC', 30); // How many seconds between times dumping performance metrics to table storage

/** Microsoft_WindowsAzure_Storage_Blob */
require_once 'Microsoft/WindowsAzure/Storage/Blob.php';

/** Microsoft_WindowsAzure_Diagnostics_Manager **/
require_once 'Microsoft/WindowsAzure/Diagnostics/Manager.php'; 
/** Microsoft_WindowsAzure_Storage_Table */
require_once 'Microsoft/WindowsAzure/Storage/Table.php';

if(PRODUCTION_SITE) { 
  $blob = new Microsoft_WindowsAzure_Storage_Blob( 
    'blob.core.windows.net', 
    AZURE_SERVICE, 
    AZURE_STORAGE_KEY 
  ); 
  $table = new Microsoft_WindowsAzure_Storage_Table( 
    'table.core.windows.net', 
    AZURE_SERVICE, 
    AZURE_STORAGE_KEY 
  ); 
} else { 
// Connect to local Storage Emulator 
    $blob = new Microsoft_WindowsAzure_Storage_Blob(); 
    $table = new Microsoft_WindowsAzure_Storage_Table(); 
}

$manager = new Microsoft_WindowsAzure_Diagnostics_Manager($blob);

//////////////////////////////

// Bring in global include file
require_once('setup.php');

// Performance counters to subscribe to
$counters = array(
    '\Processor(_Total)\% Processor Time',
    '\TCPv4\Connections Established',
);

// Retrieve the current configuration information for the running role
$configuration = $manager->getConfigurationForRoleInstance(ROLE_ID);

// Add each subscription counter to the configuration
foreach($counters as $c) {
    $configuration->DataSources->PerformanceCounters->addSubscription($c, PERF_IN_SEC);
}

// These settings are required by the diagnostics manager to know when to transfer the metrics to the storage table
$configuration->DataSources->OverallQuotaInMB = 10;
$configuration->DataSources->PerformanceCounters->BufferQuotaInMB = 10;
$configuration->DataSources->PerformanceCounters->ScheduledTransferPeriodInMinutes = 1;

// Update the configuration for the current running role
$manager->setConfigurationForRoleInstance(ROLE_ID,$configuration);

 ///////////////////////////////////////

 // Bring in global include file 
//require_once('setup.php'); 

// Grab all entities from the metrics table 
$metrics = $table->retrieveEntities('WADPerformanceCountersTable'); 

// Loop through metric entities and display results 
foreach($metrics AS $m) { 
    echo $m->RoleInstance . " - " . $m->CounterName . ": " . $m->CounterValue . "<br/>"; 
}

这是我为提取处理器信息而编写的代码......

4

2 回答 2

0

存储分析指标聚合存储帐户的事务数据和容量数据。记录 Blob、表和队列服务的事务指标。目前,仅记录 Blob 服务的容量指标。交易数据和容量数据存储在下表中:

$MetricsCapacityBlob

$MetricsTransactionsBlob

$MetricsTransactionsTable

$MetricsTransactionsQueue

执行列表操作时,不会显示上述表格,例如 ListTables 方法。必须直接访问每个表。

当您检索指标时,请使用这些表。
前任:

$metrics = $table->retrieveEntities('$MetricsCapacityBlob');


网址:http: //msdn.microsoft.com/en-us/library/windowsazure/hh343264.aspx

于 2013-10-22T04:28:52.517 回答
0

更新

请查看以下博客文章:http ://blog.maartenballiauw.be/post/2010/09/23/Windows-Azure-Diagnostics-in-PHP.aspx 。我意识到这是一篇旧文章,但我认为这应该让您对在运行 PHP 的角色中实现诊断有所了解。该博客文章在 CodePlex 上使用了适用于 Windows Azure 的 PHP SDK,我认为它已经很老了,并且已经退役,取而代之的是 Github 上的新 SDK,但我认为 Github 上的 SDK 代码没有实现诊断(这是一种耻辱)。

原始回复

由于性能计数器数据存储在 Windows Azure 表存储中,您可以简单地使用在您的存储帐户中Windows Azure SDK for PHP查询WADPerformanceCountersTable来获取此数据。

我写了一篇关于有效获取诊断数据的博客文章,您可以在此处阅读:http: //gauravmantri.com/2012/02/17/effective-way-of-fetching-diagnostics-data-from-windows-azure -诊断表提示使用分区键/

更新

查看上面的代码和源代码TableRestProxy.php,您可以在retrieveEntities调用中包含一个查询作为第二个参数。你可以这样:

$query = "(CounterName eq '\Processor(_Total)\% Processor Time` or CounterName eq '\TCPv4\Connections Established')
$metrics = $table->retrieveEntities('WADPerformanceCountersTable', $query);

请注意,我对 PHP 的了解仅限于一无所知,因此上面的代码可能无法正常工作。此外,请确保包含PartitionKey在您的查询中以避免全表扫描。

于 2013-08-13T05:51:01.133 回答