Before we dive into the setup, make sure you have the following prerequisites in place:
AWS Account: You need access to Amazon Web Services (AWS) to create and manage EC2 instances.
EC2 Instances: Launch an Ubuntu Linux and a Windows EC2 instance. Ensure they are running and accessible over the internet.
Grafana Instance: You'll need a Grafana server up and running. You can set up Grafana on a separate EC2 instance or use a cloud-based solution.
Step 1: Install Grafana
If you haven't already set up Grafana, here's how to do it:
SSH into your Grafana server (Ubuntu EC2 instance) and run the following commands:
sudo apt-get update sudo apt-get install -y software-properties-common sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main" wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add - sudo apt-get update sudo apt-get install grafana
Start the Grafana service and enable it to start at boot:
sudo systemctl start grafana-server sudo systemctl enable grafana-server
Access the Grafana web interface by opening your web browser and navigating to
http://<grafana-server-ip>:3000
. The default username and password are both set toadmin
. You should change the password after your initial login.
Step 2: Install Data Source Plugins
To monitor different server components, Grafana needs data source plugins. We'll use Prometheus and Telegraf.
Install Prometheus: Run the following commands on your Grafana server:
sudo apt-get install -y prometheus
Install Telegraf: On both the Ubuntu and Windows EC2 instances, download and install Telegraf:
For Ubuntu:
sudo apt-get install -y telegraf
For Windows: Download the Telegraf installer from the official website (portal.influxdata.com/downloads), run it, and follow the installation instructions.
Step 3: Configure Data Sources
Configure Prometheus Data Source in Grafana:
Open the Grafana web interface.
Navigate to "Configuration" > "Data Sources."
Click on "Add data source" and select "Prometheus."
Configure the Prometheus data source with the address of your Prometheus server (usually
http://localhost:9090
).
Configure Telegraf on Ubuntu:
Edit the Telegraf configuration file:
sudo nano /etc/telegraf/telegraf.conf
Configure inputs to monitor Ubuntu server components such as CPU, memory, and disk usage. Here's an example:
[[inputs.cpu]] percpu = true totalcpu = true collect_cpu_time = false report_active = false [[inputs.memory]] swap = false [[inputs.disk]] ignore_fs = ["tmpfs", "devtmpfs", "devfs"]
Restart Telegraf:
sudo systemctl restart telegraf
Configure Telegraf on Windows:
Edit the Telegraf configuration file (usually located at
C:\Program Files\Telegraf\telegraf.conf
).Configure inputs to monitor Windows server components, such as CPU, memory, and disk usage.
Verify Data Collection:
In Grafana, create dashboards and panels to visualize the data collected from your Ubuntu and Windows instances.
You can use the Prometheus data source for Linux monitoring and query the Telegraf-collected metrics for Windows.
Step 4: Set Up Alerts
Grafana allows you to set up alerts based on specific conditions. For example, you can configure alerts to notify you when CPU usage exceeds a certain threshold or when disk space is running low.
Create an alert rule in Grafana by navigating to "Alerting" in your dashboard and setting up conditions and notification channels.
Configure notification channels in Grafana to send alerts via email, Slack, or other methods.
Conclusion
By following these steps, you've successfully connected an Ubuntu Linux and a Windows EC2 instance to Grafana for monitoring various server components. You can now create comprehensive dashboards and set up alerts to ensure the health and performance of your server infrastructure. Monitoring is a critical aspect of DevOps, and with Grafana, you have a powerful tool to keep your systems running smoothly.