Skip to content

Commit

Permalink
Merge pull request #50 from davidmu1/mvc-tutorials
Browse files Browse the repository at this point in the history
technical tweaks
  • Loading branch information
neilpeterson authored May 3, 2017
2 parents 7d609cf + 88c72ff commit 64be80e
Showing 1 changed file with 15 additions and 29 deletions.
44 changes: 15 additions & 29 deletions articles/virtual-machines/linux/tutorial-monitoring.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ms.devlang: na
ms.topic: article
ms.tgt_pltfrm: vm-linux
ms.workload: infrastructure
ms.date: 04/27/2017
ms.date: 05/03/2017
ms.author: davidmu
---

Expand All @@ -26,7 +26,7 @@ The steps in this tutorial can be completed using the latest [Azure CLI 2.0](/cl

## Create VM

Before you can create any other Azure resources, you need to create a resource group with az group create. The following example creates a resource group named `myRGNetwork` in the `westus` location:
Before you can create any other Azure resources, you need to create a resource group with az group create. The following example creates a resource group named `myRGMonitor` in the `westus` location:

```azurecli
az group create --name myRGMonitor --location westus
Expand All @@ -50,7 +50,7 @@ Before you can enable boot diagnostics, you will need a storage account in myRGM

```azurecli
az storage account create \
--resource-group myRGMonitor \
--resource-group myRGMonitor \
--name mydiagnosticsstorage \
--sku Standard_LRS \
--location westus
Expand All @@ -75,7 +75,7 @@ You can get the boot diagnostic data from myMonitorVM with [az vm boot-diagnosti

```azurecli
az vm boot-diagnostics get-boot-log \
-–resource-group myRGMonitor \
-–resource-group myRGMonitor \
-–name myMonitorVM
```

Expand All @@ -92,34 +92,20 @@ A Linux VM has a dedicated Host VM in Azure that it interacts with. Metrics are

[Azure Diagnostics](https://docs.microsoft.com/azure/monitoring-and-diagnostics/monitoring-overview-of-diagnostic-logs) enables the collection of diagnostic data on a VM. You can use the same storage account that you created for boot diagnostics to collect diagnostics data.

You can get the default diagnostics configuration with [az vm diagnostics get-default-config](https://docs.microsoft.com/cli/azure/vm/diagnostics#get-default-config):

```azurecli
default_config=$(az vm diagnostics get-default-config \
--query "merge(@, {storageAccount: 'mydiagnosticsstorage'})")
```

You need the primary access key for your storage account. You can get it with [az storage account keys list](https://docs.microsoft.com/cli/azure/storage/account/keys#list):

```azurecli
storage_key=$(az storage account keys list \
-g myRGMonitor \
-n mydiagnosticsstorage \
--query "[?keyName=='key1'] | [0].value" -o tsv)
```

With the storage key, you can configure the extension settings:
You can get the default diagnostics configuration with [az vm diagnostics get-default-config](https://docs.microsoft.com/cli/azure/vm/diagnostics#get-default-config). You can get the primary access key for your storage account with [az storage account keys list](https://docs.microsoft.com/cli/azure/storage/account/keys#list):

```azurecli
default_config=$(az vm diagnostics get-default-config --query "merge(@, {storageAccount: 'mydiagnosticsstorage'})")
storage_key=$(az storage account keys list -g myRGMonitor -n mydiagnosticsstorage --query "[?keyName=='key1'] | [0].value" -o tsv)
settings="{'storageAccountName': 'mydiagnosticsstorage', 'storageAccountKey': '${storage_key}'}"
```

Now you can install the extension using the diagnostics configuration and settings with [az vm diagnostics set](https://docs.microsoft.com/cli/azure/vm/diagnostics#set):

```azurecli
az vm diagnostics set \
--settings '${default_config}' \
--protected-settings '${settings}' \
--settings "${default_config}" \
--protected-settings "${settings}" \
--vm-name myMonitorVM \
--resource-group myRGMonitor
```
Expand All @@ -144,18 +130,18 @@ az monitor activity-log list \

## Create alerts

Alerts are a method of monitoring Azure resource metrics, events, or logs and being notified when a condition you specify is met.
Alerts are a method of monitoring Azure resource metrics, events, or logs and being notified when a condition you specify is met. In this section, you create an alert that sends email when the percentage of CPU usage goes over the threshold of 1

The following alert that you can create with [az monitor alert-rules create](https://docs.microsoft.com/cli/azure/monitor/alert-rules#create) sends an email when the percentage of CPU usage goes over the threshold of 1:
Before creating an alert with [az monitor alert-rules create](https://docs.microsoft.com/cli/azure/monitor/alert-rules#create), replace {sub-id} with the identifier of your Azure subscription:

```azurecli
az monitor alert-rules create \
--alert-rule-resource-name cpu-alert \
-g myRGMonitor \
-l westus \
--resource-group myRGMonitor \
--location westus \
--is-enabled true \
--condition '{"odatatype": "Microsoft.Azure.Management.Insights.Models.ThresholdRuleCondition", "data_source": { "odatatype": "Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource", "resource_uri": "/subscriptions/{sub-id}/resourceGroups/myRGMonitor/providers/Microsoft.Compute/virtualMachines/monitor-rule", "metric_name": "Percentage CPU" }, "operator": "GreaterThan", "threshold": 1, "window_size": "PT5M"}
--actions '[{"odatatype": "Microsoft.Azure.Management.Insights.Models.RuleEmailAction", "send_to_service_owners": true}]
--condition '{"odatatype": "Microsoft.Azure.Management.Insights.Models.ThresholdRuleCondition", "data_source": { "odatatype": "Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource", "resource_uri": "/subscriptions/{sub-id}/resourceGroups/myRGMonitor/providers/Microsoft.Compute/virtualMachines/myMonitorVM", "metric_name": "Percentage CPU", }, "operator": "GreaterThan", "threshold": 1, "window_size": "PT5M"}'
--actions '[{"odatatype": "Microsoft.Azure.Management.Insights.Models.RuleEmailAction", "send_to_service_owners": true}]'
```

## Advanced monitoring
Expand Down

0 comments on commit 64be80e

Please sign in to comment.