0
votes

I am in the process of coding a cloud monitoring application and coudnt find useful logic of getting performance counters from AZURE php SDK documentation(such as CPU utilization, disk utilization, ram usage).

can anybody help ??

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/>"; 
}

this is the code I crafted to extract processor info ...

2

2 Answers

0
votes

UPDATE

Do take a look at the following blog post: http://blog.maartenballiauw.be/post/2010/09/23/Windows-Azure-Diagnostics-in-PHP.aspx. I realize that it's an old post but I think this should give you some idea about implementing diagnostics in your role running PHP. The blog post makes use of PHP SDK for Windows Azure on CodePlex which I think is quite old and has been retired in favor of the new SDK on Github but I think the SDK code on Github doesn't have diagnostics implemented (and that's a shame).

ORIGINAL RESPONSE

Since performance counters data is stored in Windows Azure Table Storage, you could simply use Windows Azure SDK for PHP to query WADPerformanceCountersTable in your storage account to fetch this data.

I have written a blog post about efficiently fetching diagnostics data sometime back which you can read here: http://gauravmantri.com/2012/02/17/effective-way-of-fetching-diagnostics-data-from-windows-azure-diagnostics-table-hint-use-partitionkey/.

Update

Looking at your code above and source code for TableRestProxy.php, you could include a query as the 2nd parameter to your retrieveEntities call. You could something like:

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

Please note that my knowledge about PHP is limited to none so the code above may not work. Also, please ensure to include PartitionKey in your query to avoid full table scan.

0
votes

Storage Analytics Metrics aggregates transaction data and capacity data for a storage account. Transactions metrics are recorded for the Blob, Table, and Queue services. Currently, capacity metrics are only recorded for the Blob service. Transaction data and capacity data is stored in the following tables:

$MetricsCapacityBlob

$MetricsTransactionsBlob

$MetricsTransactionsTable

$MetricsTransactionsQueue

The above tables are not displayed when a listing operation is performed, such as the ListTables method. Each table must be accessed directly.

When you retrieve metrics,use these tables.
Ex:

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


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