DEV Community

Eduardo Lomeli
Eduardo Lomeli

Posted on

Kamal: How to use Grafana Loki as a logging driver

You can easily configure Grafana Loki as a logging driver in your Kamal deployments.

In this guide I'm using Grafana Cloud and Loki Docker driver client.

Install Loki Docker driver in your Kamal hosts

This step can be automated using Kamal docker-setup hook. Which runs right after Docker is installed, usually when you run kamal setup.

docker-setup

This script example is prepared to use multiple destinations.

File location: .kamal/hooks/docker-setup

#!/bin/sh

echo "Docker set up on $KAMAL_HOSTS. Destination $KAMAL_DESTINATION"

# Check if the Loki Docker Driver plug-in is already installed
if ! kamal server exec "docker plugin ls" -d $KAMAL_DESTINATION | grep -q "loki"; then
  echo "Installing Loki Docker Driver plug-in..."
  kamal server exec \
  "docker plugin install grafana/loki-docker-driver:2.9.2 --alias loki --grant-all-permissions" \
  -d $KAMAL_DESTINATION
else
  echo "Loki Docker Driver plug-in is already installed."
fi
Enter fullscreen mode Exit fullscreen mode

Configure Kamal logging driver

deploy.yaml

logging:
  driver: loki
  options:
    loki-url: https://<user_id>:<password>@logs-us-west1.grafana.net/loki/api/v1/push
    loki-batch-size: "400"
Enter fullscreen mode Exit fullscreen mode

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay