Skip to main content

Command Palette

Search for a command to run...

Day 75 - Sending Docker Log to Grafana

Updated
2 min read

Step 1: Install Docker Begin by installing Docker on your system. Run the following commands:

  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

After the system reboots, verify the Docker installation by running docker --version.

Step 2: Configure Loki Download the Loki configuration file using the following command:

  wget https://raw.githubusercontent.com/grafana/loki/v2.8.0/cmd/loki/loki-local-config.yaml -O loki-config.yaml

Next, start the Loki container with the downloaded configuration file:

docker run -d --name loki -v $(pwd)/loki-config.yaml:/mnt/config/loki-config.yaml -p 3100:3100 grafana/loki:2.8.0 --config.file=/mnt/config/loki-config.yaml

Now check the container

Make sure to open port 3100 in your security group to allow access to Loki. You can now check the Loki metrics using http://<public_ip>:3100/metrics.

verify its readiness with http://<public_ip>:3100/ready.

Step 3: Download and Configure Promtail Download the Promtail configuration file 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

check your promtail:

Run the Promtail container with the downloaded configuration file:

docker run -d --name promtail -v $(pwd)/promtail-config.yaml:/mnt/config/promtail-config.yaml -v /var/log:/var/log --link loki grafana/promtail:2.8.0 --config.file=/mnt/config/promtail-config.yaml

Verify that both Loki and Promtail containers are running by executing docker ps command.

Step 4: Configure Loki as a Data Source in Grafana

Login to your Grafana instance and follow these steps:

Go to "Configuration" > "Data Sources" from the left menu panel.

Click on "Add New Data Source" from the top right corner.

Search for "Loki" and click on it.

Fill in the details, such as the name of the data source and the HTTP URL (e.g., http://Your-IP:3100).

Click on "Save and Test" to verify the connection.

Step 5: Visualize Docker Logs in Grafana

To explore and visualize the Docker logs, follow these steps:

Click on "Explore" from the top right corner of the Grafana interface.

Select the desired time range and adjust other settings as needed.

Run queries to fetch the Docker logs and observe the results.

To create a dashboard, click on "Add to Dashboard" from the top right corner.

That was all for today. See you another day with another challenge.

More from this blog

Ajay Patel

116 posts