AWS Cloud Operations Blog
Viewing collectd statistics with Amazon Managed Service for Prometheus and Amazon Managed Service for Grafana
Monitoring systems are essential for a resilient solution. A popular tool to monitor Linux-based physical or virtual machines is collectd – a daemon to collect system and application performance metrics periodically. However, collectd doesn’t provide long-term storage for metrics, rich querying, visualization, or an alerting solution. The Amazon Managed Service for Prometheus is a serverless monitoring service for metrics compatible with open-source Prometheus. Amazon Managed Grafana is a fully managed service with rich, interactive data visualizations to help customers analyze, monitor, and alarm on metrics, logs, and traces across multiple data sources.
This post describes how partners and customers can view metrics from a running instance of collectd on a Linux-based Amazon Elastic Compute Cloud (Amazon EC2) instance. The metrics can be stored and queried with Amazon Managed Service for Prometheus. The metrics can be visualized with Amazon Managed Service for Grafana. Further, customers and partners can build alerting mechanisms using either Amazon Managed Service for Prometheus or Amazon Managed Service for Grafana. This can help partners and customers move their existing or create new monitoring workloads in a cloud-native fashion.
Time to read | 6 minutes |
Time to complete | 15 minutes |
Cost to complete (estimated) | 10 USD (at publication time) |
Learning level | Intermediate (200) |
Services used |
Solution overview
The following figure demonstrates how this post utilizes the Prometheus official exporter – collectd_exporter – from Prometheus to collect metrics from the collectd daemon. Then, the Prometheus server scrapes metrics from collectd_exporter and writes to the Amazon Managed Service for Prometheus instance. The Amazon Managed Service for Grafana instance will connect to Amazon Managed Service for Prometheus and host the dashboards for visualization.
Install the collectd daemon, collectd_exporter, and Prometheus server on the same machine for this post. Configure the Prometheus server to write to an Amazon Managed Service for Prometheus workspace remotely. For this to happen, configure the Amazon EC2 instance with an AWS Identity and Access Management (IAM) Role that has the AmazonPrometheusRemoteWriteAccess
policy. A YAML file with Prometheus recording rules is uploaded to the Amazon Managed Service for Prometheus workspace to generate the average values of metrics over a five-minute duration.
Configure the Amazon Managed Service for Grafana workspace to use the Amazon Managed Service for Prometheus workspace as the data source. The Amazon Managed Service for Grafana workspace will have dashboards to display the metrics.
Walkthrough
Implement this solution using the following overview. It uses a Ubuntu Linux-based Amazon EC2 instance for testing purposes, though any Linux-based device is acceptable.
- Install
collectd
. - Configure collectd to write metrics via HTTP to
collectd_exporter
. - Install
collectd_exporter
. - Launch the Amazon Managed Service for Prometheus instance.
- Install Prometheus server.
- Configure the Prometheus server to write to the Amazon Managed Service for Prometheus instance.
- Add Prometheus recording rules in Amazon Managed Service for Prometheus.
- Launch Amazon Managed Service for Grafana instance.
- Import JSON to view metrics.
Prerequisites
Complete the following perquisites before starting this walkthrough:
- Create an AWS account
- Create a Linux-based Amazon EC2 instance using Ubuntu or another on any third-party software or hardware.
Install collectd
The preferred way to install collectd is to use a package manager. Installation through compilation is also an option. However, this is out of the scope of this post.
- Connect to your Linux instance using Session Manager.
- Run the following commands:
Configure collectd
- Back-up the configuration file with the following command:
sudo cp /etc/collectd/collectd.conf /etc/collectd/collectd.conf.old
- Copy the following configuration into /etc/collectd/collectd.conf
The above configuration file does the following:
- Loads the input plugins df, cpu, and memory. These plugins do the following:
a. df – Collects file system usage information.
b. cpu – Collects CPU usage.
c. memory – Collects memory usage. - Loads the logging plugin syslog that writes debug and status information to syslog. This plugin helps monitor collectd.
- Load the output plugins csv and http_write. The csv plugin is optional, as it helps confirm the metrics gathered on the host system. The http_write plugin will write to the collectd_exporter.
- Configure the http_write plugin to write to collectd_exporter at http://localhost:9103/collectd-post
The collectd wiki maintains a list of available collectd plugins.
Restart collectd
- Restart collectd with the following command:
sudo /etc/init.d/collectd restart
- Verify by looking at the logs at
/var/log/syslog
. Here is a sample output:
- Collected metrics can be viewed in the
/var/lib/collectd/csv
folder.
Install collectd_exporter
On the GitHub page for collectd_exporter, the installation instruction refers to running a Docker image. However, this isn’t mandatory. This section describes building and running the collectd_exporter binary for the Linux instance.
- Open a new terminal window.
- Connect to your Linux instance using Session Manager.
- Install Go with the following commands:
- Build collectd_exporter with the following commands:
Launch collectd_exporter
- Launch collectd_exporter with the following command:
collectd_exporter
- These are the logs:
Note the port number that the exporter is listening on – it is 9103
. This is configured when launching collectd
earlier.
Launch Amazon Managed Service for Prometheus workspace
- Create the Amazon Managed Service for Prometheus workspace.
- Copy the workspace ID from Step 1. The section for configuring the Prometheus server will use the workspace ID.
- Create an IAM role with the AmazonPrometheusRemoteWriteAccess policy and attach the role to the Amazon EC2 instance.
- Add the following into YAML file named collectd-prometheus.yaml, and upload it to the workspace created.
Install Prometheus server
- Open a new terminal window.
- Connect to your Linux instance using Session Manager.
- Run the following commands to install the Prometheus server: