【问题标题】:Retrieving Azure Performance Counters检索 Azure 性能计数器
【发布时间】:2013-10-22 12:28:52
【问题描述】:

我正在编写云监控应用程序,但无法从 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/>"; 
}

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

【问题讨论】:

    标签: php azure performancecounter


    【解决方案1】:

    更新

    请查看以下博客文章: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,以避免全表扫描。

    【讨论】:

    • 感谢您的回复..从表计数中获取内存信息的方法是什么找到任何信息..以下是我制作的用于获取cpu信息的代码..请看看我该怎么做方法对其进行调整以获取内存或磁盘信息...请查看我在问题中更新的代码...
    • 基本上我一直在寻找订阅内存信息、处理器信息和磁盘信息的代码,这是我发现的……没有经过测试,但应该可以工作……我测试后会确认…… .$counters = array(\Processor(_Total)\% Processor Time', '$counters = array('\Memory\Available MBytes', '\Memory\Committed Bytes', '\LogicalDisk(*)\Disk Bytes', '\TCPv4\Connections Established' );
    • 我想我完全误解了你的问题:P。我以为您想获取您的服务已经收集的诊断数据。如果我没记错的话,您想知道的是如何使用 PHP SDK 启用诊断。我说的对吗?
    • 也许我上面并不清楚.. 无论如何,这就是我需要订阅处理器、内存和磁盘相关的性能计数器。除此之外,我还面临另一个挑战,即在 azure cloud 上获取特定帐户的主机信息或 VM 信息..任何想法..提前致谢..
    • Gauri 先生..这是启用性能计数器的方法..我需要得到的是特定帐户下的主机名或虚拟机名称列表..希望这次足够清楚..
    【解决方案2】:

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

    $MetricsCapacityBlob

    $MetricsTransactionsBlob

    $MetricsTransactionsTable

    $MetricsTransactionsQueue

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

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

    $metrics = $table-&gt;retrieveEntities('$MetricsCapacityBlob');


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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多