Using the Azure ARM SDK for Node to get Site Metrics for your App Service
Documentation for using the Azure ARM SDK for Node to get Site Metrics for your App Service can be found here:
https://azure.github.io/azure-sdk-for-node/azure-arm-website/latest/Sites.html#getSiteMetrics
Here is sample code for how to get this to return the results as JSON in the console. You can use other login methods (not just loginWithServicePrincipalSecret), such as interactiveLogin.
var msRestAzure = require('ms-rest-azure');
var webSiteManagementClient = require('azure-arm-website');
msRestAzure.loginWithServicePrincipalSecret(clientId, secret, domain, function(err, credentials) {
if (err) {
console.log(err);
return;
}
var client = new webSiteManagementClient(credentials, subscription);
var options = {
filter: 'name.value eq \'Requests\' and startTime eq 2016-12-017T19:40:00Z and endTime eq 2016-12-17T19:55:00Z and timeGrain eq duration\'PT1M\'', customHeaders: {accept: 'application/json'}
};
try {
result = client.sites.getSiteMetrics(resourceGroup, name, options, function(err, result) {
if (err) console.log(err);
console.log("RESULT = " + JSON.stringify(result, null, 2));
});
} finally { }
});
Note: Based on this documentation, the retention policy for each granularity is currently as follows:
-Minute granularity metrics (eg PT1M) are retained for 48 hours
-Hour granularity metrics (eg PT1H) are retained for 30 days
-Day granularity metrics (eg PT1D) are retained for 90 days
You can use the Microsoft Azure Cross Platform Command-Line (among other tools) to run the Node application. More information about the Azure Cross Platform Command-Line can be found here: