Loki-Promtail Setup Documentation

A simplified guide to automate the installation and configuration of Loki and Promtail for centralized logging with Grafana. This documentation covers setup steps, configuration details, and troubleshooting tips.

Introduction

This repository provides streamlined scripts to automate the setup of Loki and Promtail, offering centralized logging integrated with Grafana. The scripts are designed for ease of use and allow users to set up Loki and Promtail on any compatible Linux server with minimal manual intervention.

Features

Installation

Install Loki & Promtail

Run the following command to install both Loki and Promtail:

sudo bash -c "$(curl -fsSL https://raw.githubusercontent.com/abdulsaheel/Loki-Promtail-Setup/refs/heads/main/install_loki_promtail.sh)"

This command will:

Middleware Setup

You can skip this part if you plan to use lambda function

Run Middleware Script

To configure Grafana with Loki as a data source and set up a default dashboard, run:

sudo wget -O middleware.py https://raw.githubusercontent.com/abdulsaheel/Loki-Promtail-Setup/refs/heads/main/middleware.py && wget -O loki-dashboard.json https://raw.githubusercontent.com/abdulsaheel/Loki-Promtail-Setup/refs/heads/main/loki-dashboard.json && python3 middleware.py"

Grafana Data Source & Dashboard Setup

Generate a Grafana Bearer Token

To configure Grafana with Loki, you need a Bearer Token. Follow these steps to generate one:

Note: Store the token securely, as it grants access to configure Grafana and interact with data sources.

Using Flask Python Script

To automatically add Loki as a data source and create a default Grafana dashboard:

sudo bash -c "$(curl -fsSL https://raw.githubusercontent.com/abdulsaheel/Loki-Promtail-Setup/refs/heads/main/create_grafana_dashboard.sh)"

If Using Lambda Function

For AWS Lambda configuration:

sudo bash -c "$(curl -fsSL https://raw.githubusercontent.com/abdulsaheel/Loki-Promtail-Setup/refs/heads/main/create_grafana_dashboard_lamba_fn.sh)"

This script will prompt for:

Accessing Loki UI

Once Loki and Promtail are installed and running, access the Loki UI at:

http://<your-server-ip>:3100

Default Credentials:

Troubleshooting

Loki and Promtail Not Starting

Check the status of the services:

sudo systemctl status loki
sudo systemctl status promtail

If the services aren’t running, check logs with:

journalctl -u loki
journalctl -u promtail

Grafana Data Source Not Created

Verify the Loki URL and credentials in the middleware script. Ensure that the Grafana Bearer Token is valid and has permissions to create data sources.

Logs Not Showing in Grafana

Check the data source in Grafana: