Guide: Setup Microsoft Monitoring Agent on Service Fabric and VM Scale Sets for improved Operational Insight

Posted by Nilay Parikh and last modified on Tue Jun 12, 2018.

This guide would demonstrate the steps to connect Service Fabric Nodes or VM Scale Set Instances in the cloud or the hybrid infrastructure to OMS Workspace. Microsoft Monitoring Agent (MMA) enables rich and real-time analytics for operational data (Logs, Performance, Alerts and Inventory) from a tenant.

You can install agents using Installer (manually on the physical machine), Resource Manager Template, Resource Manager CLI/PowerShell and Desired State Configuration (DSC). If you are considering a general best practice for VMSS instances and Service Fabric nodes, then Azure Resource Manger Templates would be an ideal option in my opinion.

Microsoft Monitoring Agent extension can be defined in Azure Resource Manager template (virtualMachineScaleSets\properties\virtualMachineProfile\extensionProfile\extensions).

  • virtualMachineProfile ensures consistency across VM cluster.
  • Provisioning of new VM or Service Fabric Node ensures the deployment and configuration of Microsoft Monitoring Agent.
  • You can roll-out configuration changes easily and consistently across a cluster.

Setup Microsoft Monitoring Agent using Azure RM Templates

You can use following Resource Manager Template snippet to add a Microsoft Monitoring Agent extension. You can use the extension with Microsoft.Compute/virtualMachineScaleSets resource, irrespective of IaaS (VMSS) or PaaS (Service Fabric).

{
  "name": "[concat('OMSVmExt', '_', variables('vmNodeType0Name'))]",
  "properties": {
    "publisher": "Microsoft.EnterpriseCloud.Monitoring",
    "type": "MicrosoftMonitoringAgent",
    "typeHandlerVersion": "1.0",
    "autoUpgradeMinorVersion": true,
    "settings": {
      "workspaceId": "[reference(resourceId('Microsoft.OperationalInsights/workspaces/', parameters('omsWorkspacename')), '2015-11-01-preview').customerId]"
    },
    "protectedSettings": {
      "workspaceKey": "[listKeys(resourceId('Microsoft.OperationalInsights/workspaces/', parameters('omsWorkspacename')),'2015-11-01-preview').primarySharedKey]"
    }
  }
}
Settings

If OMS Workspace is not retrievable through Azure RM template then you can replace resource reference with actual workspaceId and workspaceKey value.

You can find workspaceId and workspaceKey from Microsoft Operations Management Suite user interface. Please follow Overview > Settings.

You can deploy the Azure Service Fabric with Microsoft Monitoring Agent preconfigured from my GitHub template.

Setup Microsoft Monitoring Agent using PowerShell

PowerShell is useful instrumentation in following circumstances,

  • Quick development or testing proof of concept.
  • Relying on Azure Portal and to outmaneuver the limitation of the Azure Portal.

I have created a handy PowerShell script to simplify deployment and configuration of Microsoft Monitoring Agent on Service Fabric Cluster or VM Scale Sets.

Initialise following parameters in order to setup Microsoft Monitoring Agent extensions on Virtual Machine Scale Sets. These parameters are self-explanatory. Please refer, configure an agent manually or add additional workspaces for detail Microsoft Monitoring Agent configuration.

$ResourceGroupLocation = "westeurope";
$ResourceGroupName = "myrg";
$WorkspaceName = "myomsws";
$VMScaleSetName = "myvmss";

Now, try to retrieve workspaceId and workspaceKey using $WorkspaceName. This is a optional step, if you can also assign these values explicitly to next step.

# Get OMS Workspace Id and Key
$workspace = (Get-AzureRmOperationalInsightsWorkspace).Where({$_.Name -eq $WorkspaceName});
$workspaceId = $workspace.CustomerId;
$workspaceKey = (Get-AzureRmOperationalInsightsWorkspaceSharedKeys -ResourceGroupName $workspace.ResourceGroupName -Name $workspace.Name).PrimarySharedKey;

Assign $workspaceId and $workspaceKey to $setting and $protectedSetting, respectively.

# Save access parameter to Setting and ProtectedSetting objects
$setting = [Newtonsoft.Json.Linq.JObject]::Parse("{'workspaceId': '$workspaceId'}");
$protectedSetting = [Newtonsoft.Json.Linq.JObject]::Parse("{'workspaceKey': '$workspaceKey'}");

Retrieve latest VM extension image available at given Azure Region and the version. The format of TypeHandlerVersion is major.minor. The below code snippet retrieve the latest version and transform into supported format.

# Get latest TypeHandlerVersion
$allVersions= (Get-AzureRmVMExtensionImage -Location $ResourceGroupLocation -PublisherName "Microsoft.EnterpriseCloud.Monitoring" -Type "MicrosoftMonitoringAgent").Version
$typeHandlerVer = $allVersions[($allVersions.count) - 1]
$typeHandlerVerMjandMn = $typeHandlerVer.split(".")
$typeHandlerVerMjandMn = $typeHandlerVerMjandMn[0] + "." + $typeHandlerVerMjandMn[1]

Get the current state of Azure VM Scale Set instance.

# Get VM Scale Set instance
$scaleSet = Get-AzureRmVmss -ResourceGroupName $ResourceGroupName -VMScaleSetName $VMScaleSetName;

Add the MicrosoftMonitoringAgent extension and update Azure VM Scale Set.

# Run incremental provision
$scaleSet = Add-AzureRmVmssExtension -VirtualMachineScaleSet $scaleSet -Name $VMExtentionName -Publisher "Microsoft.EnterpriseCloud.Monitoring" -Type "MicrosoftMonitoringAgent" -TypeHandlerVersion $typeHandlerVerMjandMn -AutoUpgradeMinorVersion $autoUpgradeMV -Setting $setting -ProtectedSetting $protectedSetting;
Update-AzureRmVmss -ResourceGroupName $ResourceGroupName -Name $VMScaleSetName -VirtualMachineScaleSet $scaleSet

The complete PowerShell script is available at Github/NilayParikh/AzureScripts . Once Virtual Machine Scale Set is successfully update, you can verify the status from the Azure Portal.

Please refer, Connect Windows computers to the Log Analytics service in Azure for advance configuration options and other supported deployment methods.

Disclaimer

Any views or opinions expressed are solely those of the author and do not represent any other person or organisation. THE ARTICLE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. IN NO EVENT SHALL THE AUTHOR(S) OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY.

References