Sending Docker Logs to Grafana
In this blog, we embarked on an illuminating journey into Grafana and Loki, discovering their installation, setup, and integration for robust monitoring and visualization.
We learned how to install and start Grafana, set up Loki and Promtail via Docker, and configure Loki as a data source in Grafana.
Armed with these insights, you’re now well-prepared to navigate the world of efficient data visualization and comprehensive system monitoring. Stay tuned for more exciting explorations in our upcoming blogs!
TABLE OF CONTENTS
- Install & Start Grafana
- Install Loki & Promtail using Docker
- Configure Loki as a Data Source
Install & Start Grafana
For the installation of Grafana, please follow my Day 73,74 Blog “Grafana Installation.” Grafana Installation
Install Loki & Promtail using Docker
- Before installing Loki & Promtail make sure you have docker installed in your instance.
sudo apt-get update
sudo apt-get install docker.io -y
# Giving docker permission to current user
sudo usermod -aG docker $USER
sudo reboot
# Verify Docker version
docker --version
- Download the Loki Config file into your current directory.
wget https://raw.githubusercontent.com/grafana/loki/v2.8.0/cmd/loki/loki-local-config.yaml -O loki-config.yaml
- Run the Loki container using the following Docker command.
docker run -d --name loki -v $(pwd):/mnt/config -p 3100:3100 grafana/loki:2.8.0 --config.file=/mnt/config/loki-config.yaml
- We can verify Loki is running using the docker container by using the following Docker command :
docker ps
- Now to access Loki, Go to the Security Group of your EC2 instance and add port 3100.
- We can see Loki’s metrics using the IPv4 address followed by port 3100 and metrics.
http://<public_ipV4>:3100/metrics
- To verify whether Loki is ready or not, access the IPv4 address followed by port 3100 and ready.
http://public_ipV4:3100/ready
- Now download the Promtail Config yaml file into your directory by using the following command:
wget https://raw.githubusercontent.com/grafana/loki/v2.8.0/clients/cmd/promtail/promtail-docker-config.yaml -O promtail-config.yaml
- We can verify Promtail configuration file is there in the directory by using the following command:
ls
cat promtail-config.yaml
- Now execute the Promtail container by using the following Docker command:
docker run -d --name promtail -v $(pwd):/mnt/config -v /var/log:/var/log --link loki grafana/promtail:2.8.0 --config.file=/mnt/config/promtail-config.yaml
- We can verify both Loki and Promtail are running using
docker ps
command.
Configure Loki as a Data Source
- Once both Loki and Promtail are configured in the instance, Login to the Grafana Home Page
- In the navigation drawer either there is DataSource click on it or you can get it by clicking on the left hamburger menu, hovering over there is a gear icon (second last one) and clicking on “Data Sources”.
- Click on “Add data source” and search for “Loki”. Click on it.
- As the Loki prompt is opened fill in the details like Name and in the HTTP provide the URL i.e, http://127.0.0.1:3100
- Click on “Save and Test”. You will get a prompt saying “Data Source Successfully Connted” so you can conclude that your connection to Grafana using Loki and Promtail is successful.
- Now click on Explore to create metrics.
- We will create metrics that will show logs containing Docker in it.
Name -> System Generated Logs
Label Filters -> jobs, varlogs
Line Contains -> docker
- Once you get the output we can put the result into a new dashboard, before that named it.
Thanks for delving into Grafana, Loki, and Promtail through Docker installation! Now equipped with powerful monitoring tools, from Grafana setup to Loki and Promtail configuration, you’re ready for efficient system monitoring and visualization. Let’s stay connected on (https://www.linkedin.com/in/mudit--mathur/) for more insights, discussions, and your valuable feedback as we explore further topics. Keep exploring, keep monitoring, and keep innovating!