title | description | author | services | ms.topic | ms.date | ms.author |
---|---|---|---|---|---|---|
Collect custom metrics for Linux VM with the InfluxData Telegraf agent |
Instructions on how to deploy the InfluxData Telegraf agent on a Linux VM in Azure and configure the agent to publish metrics to Azure Monitor. |
anirudhcavale |
azure-monitor |
conceptual |
09/24/2018 |
ancav |
By using Azure Monitor, you can collect custom metrics via your application telemetry, an agent running on your Azure resources, or even outside-in monitoring systems. Then you can submit them directly to Azure Monitor. This article provides instructions on how to deploy the InfluxData Telegraf agent on a Linux VM in Azure and configure the agent to publish metrics to Azure Monitor.
Telegraf is a plug-in-driven agent that enables the collection of metrics from over 150 different sources. Depending on what workloads run on your VM, you can configure the agent to leverage specialized input plug-ins to collect metrics. Examples are MySQL, NGINX, and Apache. By using output plug-ins, the agent can then write to destinations that you choose. The Telegraf agent has integrated directly with the Azure Monitor custom metrics REST API. It supports an Azure Monitor output plug-in. By using this plug-in, the agent can collect workload-specific metrics on your Linux VM and submit them as custom metrics to Azure Monitor.
Note
Custom Metrics are not supported in all regions. Supported regions are listed here
For this tutorial, we deploy a Linux VM that runs the Ubuntu 18.04 LTS operating system. The Telegraf agent is supported for most Linux operating systems. Both Debian and RPM packages are available along with unpackaged Linux binaries on the InfluxData download portal. See this Telegraf installation guide for additional installation instructions and options.
Sign in to the Azure portal.
Note
If you want to migrate classic alert rules and use an existing Linux virtual machine, make sure the virutal machine has a system-assigned identity set to On.
Create a new Linux VM:
-
Select the Create a resource option from the left-hand navigation pane.
-
Search for Virtual Machine.
-
Select Ubuntu 18.04 LTS and select Create.
-
Provide a VM name like MyTelegrafVM.
-
Leave the disk type as SSD. Then provide a username, such as azureuser.
-
For Authentication type, select Password. Then enter a password you'll use later to SSH into this VM.
-
Choose to Create new resource group. Then provide a name, such as myResourceGroup. Choose your Location. Then select OK.
-
Select a size for the VM. You can filter by Compute type or Disk type, for example.
-
On the Settings page in Network > Network Security Group > Select public inbound ports, select HTTP and SSH (22). Leave the rest of the defaults and select OK.
-
On the summary page, select Create to start the VM deployment.
-
The VM is pinned to the Azure portal dashboard. After the deployment finishes, the VM summary automatically opens.
-
In the VM pane, navigate to the Identity tab. Ensure that your VM has a system-assigned identity set to On.
Create an SSH connection with the VM. Select the Connect button on the overview page for your VM.
In the Connect to virtual machine page, keep the default options to connect by DNS name over port 22. In Login using VM local account, a connection command is shown. Select the button to copy the command. The following example shows what the SSH connection command looks like:
ssh azureuser@XXXX.XX.XXX
Paste the SSH connection command into a shell, such as Azure Cloud Shell or Bash on Ubuntu on Windows, or use an SSH client of your choice to create the connection.
To install the Telegraf Debian package onto the VM, run the following commands from your SSH session:
# download the package to the VM
curl -s https://repos.influxdata.com/influxdb.key | sudo apt-key add -
source /etc/lsb-release
echo "deb https://repos.influxdata.com/${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
Telegraf's configuration file defines Telegraf's operations. By default, an example configuration file is installed at the path /etc/telegraf/telegraf.conf. The example configuration file lists all possible input and output plug-ins. However, we'll create a custom configuration file and have the agent use it by running the following commands:
# generate the new Telegraf config file in the current directory
telegraf --input-filter cpu:mem --output-filter azure_monitor config > azm-telegraf.conf
# replace the example config with the new generated config
sudo cp azm-telegraf.conf /etc/telegraf/telegraf.conf
Note
The preceding code enables only two input plug-ins: cpu and mem. You can add more input plug-ins, depending on the workload that runs on your machine. Examples are Docker, MySQL, and NGINX. For a full list of input plug-ins, see the Additional configuration section.
Finally, to have the agent start using the new configuration, we force the agent to stop and start by running the following commands:
# stop the telegraf agent on the VM
sudo systemctl stop telegraf
# start the telegraf agent on the VM to ensure it picks up the latest configuration
sudo systemctl start telegraf
Now the agent will collect metrics from each of the input plug-ins specified and emit them to Azure Monitor.
-
Open the Azure portal.
-
Navigate to the new Monitor tab. Then select Metrics.
-
Select your VM in the resource selector.
-
Select the Telegraf/CPU namespace, and select the usage_system metric. You can choose to filter by the dimensions on this metric or split on them.
The preceding walkthrough provides information on how to configure the Telegraf agent to collect metrics from a few basic input plug-ins. The Telegraf agent has support for over 150 input plug-ins, with some supporting additional configuration options. InfluxData has published a list of supported plugins and instructions on how to configure them.
Additionally, in this walkthrough, you used the Telegraf agent to emit metrics about the VM the agent is deployed on. The Telegraf agent can also be used as a collector and forwarder of metrics for other resources. To learn how to configure the agent to emit metrics for other Azure resources, see Azure Monitor Custom Metric Output for Telegraf.
When they're no longer needed, you can delete the resource group, virtual machine, and all related resources. To do so, select the resource group for the virtual machine and select Delete. Then confirm the name of the resource group to delete.
- Learn more about custom metrics.