我正在编写云监控应用程序的过程,并且找到了从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/>";
}
这是我精心设计的用于提取处理器信息的代码......
答案 0 :(得分: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-diagnostics-table-hint-use-partitionkey/。
<强>更新强>
查看上面的代码和TableRestProxy.php
的源代码,您可以将查询作为retrieveEntities
调用的第二个参数。你可以这样:
$query = "(CounterName eq '\Processor(_Total)\% Processor Time` or CounterName eq '\TCPv4\Connections Established')
$metrics = $table->retrieveEntities('WADPerformanceCountersTable', $query);
请注意,我对PHP的了解仅限于无,因此上述代码可能无效。另外,请确保在查询中包含PartitionKey
以避免全表扫描。
答案 1 :(得分:0)
Storage Analytics Metrics聚合存储帐户的交易数据和容量数据。记录Blob,表和队列服务的事务度量标准。目前,仅为Blob服务记录容量指标。交易数据和容量数据存储在下表中:
$ MetricsCapacityBlob
$ MetricsTransactionsBlob
$ MetricsTransactionsTable
$ MetricsTransactionsQueue
执行列表操作时不显示上述表,例如ListTables方法。必须直接访问每个表。
检索指标时,请使用这些表。
例如:
$metrics = $table->retrieveEntities('$MetricsCapacityBlob');
URL: http://msdn.microsoft.com/en-us/library/windowsazure/hh343264.aspx