Hey Learners! Welcome back. In the previous challenge, we installed Grafana on the EC2 instance. Moving forward in this challenge we'll add Loki integrated with Promtail as a data source and create Dashboards in Grafana to monitor. Let's start...
Prerequisite:-
Grafana should be installed Refer DAY73Challenge
Docker should be present with appropriate permissions
Steps:-
Download the Config file for Loki to run Loki in the Docker container
Download the Config file for Promtail to run Promtail in the Docker container
Add Data source in Grafana and check logs
Create Dashboard
Step 1- Download the Config file for Loki to run Loki in the Docker container
Use the following command to download and store Loki's configuration file in the local
wget https://raw.githubusercontent.com/grafana/loki/v2.8.0/cmd/loki/loki-local-config.yaml -O loki-config.yaml
Run the docker container using the following command.
sudo docker run -d --name loki -v $(pwd):/mnt/config -p 3100:3100 grafana/loki:2.8.0 --config.file=/mnt/config/loki-config.yaml
Allow port 3100 in the EC2 instance's security group and check in the browser. Refer following screenshot.
Step 2- Download the Config file for Promtail to run Promtail in the Docker container
Use the following command to download and store Promtail's configuration file in the local
wget https://raw.githubusercontent.com/grafana/loki/v2.8.0/clients/cmd/promtail/promtail-docker-config.yaml -O promtail-config.yaml
Run the Docker container using the following 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
Step 3- Add Data source in Grafana and check logs
As we successfully run the container for Loki and Promtail we have to add Loki as a Data source in Grafana
Access your Grafana web interface <PublicIP:3000>
Go to Home Click on DATA SOURCES to add data source
-
Choose Loki from the list. Enter the URL as
http://localhost:3100
as we running Loki on the same host machine. -
Check the system logs sent to Grafana by Loki as mentioned in the config file.
Click on New Dashboard click Add Visualization then select Loki as the Data source. Select Job in the Label filter option. Refer below screenshots
Step 4- Create Dashboard
Click on Dashboards and select New dashboard from the New button as shown below.
Select Loki as a data source and try to add all logs as shown below
Click Apply to apply and place the panel where you want to place.
We have to add the Grafana log path in the Promtail configuration file to display Grafana logs. Make changes in the Promtail conf file as shown below
After changing the conf file restart the Oromtail container using the
sudo docker restart promtail
command. Make sure Grafana logs show while selecting Loki as a data source.Go to the Grafana dashboard and click Add to add a new Panel.
We'll add a new panel of log errors for Grafana and then add a new panel for the number of errors encountered in the last 5 min
The final simple dashboard will look like below
This is the simple dashboard but you can explore Grafana and make new dashboards.
Thank you so much for taking the time to read till the end! Hope you found this blog informative.
Feel free to explore more of my content, and don't hesitate to reach out if need any assistance from me or in case of you have any questions.
Find me on:- Hashnode LinkedIn Github
Happy Learning!