cover-img

Setup Loki dan Promptail

28 July, 2024

0

0

0

  1. Download Loki dan Promptail

https://github.com/grafana/loki/releases/

wget https://github.com/grafana/loki/releases/download/v2.9.9/loki-linux-amd64.zip
wget https://github.com/grafana/loki/releases/download/v2.9.9/promtail-linux-amd64.zip
  1. Unzip
unzip loki-linux-amd64.zip
unzip promtail-linux-amd64.zip
  • Buat folder untuk konfigurasi loki dan promtail
sudo mkdir /etc/loki
sudo mkdir /etc/promtail
  • Buat konfigurasi loki
cd /etc/loki/ && sudo nano loki-config.yaml
auth_enabled: false

server:
http_listen_port: 3100
grpc_listen_port: 9096

common:
instance_addr: 127.0.0.1
path_prefix: /tmp/loki
storage:
filesystem:
chunks_directory: /tmp/loki/chunks
rules_directory: /tmp/loki/rules
replication_factor: 1
ring:
kvstore:
store: inmemory

query_range:
results_cache:
cache:
embedded_cache:
enabled: true
max_size_mb: 100

schema_config:
configs:
- from: 2020-10-24
store: boltdb-shipper
object_store: filesystem
schema: v11
index:
prefix: index_
period: 24h

ruler:
alertmanager_url: http://localhost:9093

compactor:
retention_enabled: true # Aktifkan penghapusan otomatis
retention_delete_delay: 24h # Tunggu 24 jam sebelum menghapus
retention_delete_worker_count: 2 # Jumlah thread untuk penghapusan
delete_request_store: filesystem # Gunakan penyimpanan lokal

limits_config:
retention_period: 90d # Hapus log lebih dari 90 hari
  • Buat konfigurasi promtail
cd /etc/promtail/ && sudo nano promttail-config.yaml
server:
http_listen_port: 9080
grpc_listen_port: 0

positions:
filename: /tmp/positions.yaml

clients:
- url: http://127.0.0.1:3100/loki/api/v1/push

scrape_configs:
- job_name: job-name
static_configs:
- targets:
- localhost
labels:
job: registration-api-id
__path__: /var/www/app/storage/logs/*
pipeline_stages:
- json:
expressions:
message: message
status: level
channel: channel
timestamp: datetime
path: context.path
value: context.value
category: context.category
start_at: context.start_at
end_at: context.end_at
- match:
selector: '{message="execution_time"}'
stages:
- metrics:
execution_time:
type: Histogram
description: "Execution time duration"
source: value
config:
buckets: [0.001, 0.0025, 0.005, 0.010, 0.025, 0.050]
  • Pindahkan file executable Loki and Promtail
sudo mv loki-linux-amd64 promtail-linux-amd64 /usr/local/bin
  • Jalankan Loki di systemd
sudo nano /etc/systemd/system/loki.service
  • config systemd loki
[Unit]
Description=Loki

[Service]
User=root
Group=root
Type=simple
ExecStart=/usr/local/bin/loki-linux-amd64 \
-config.file=/etc/loki/loki-config.yaml

[Install]

WantedBy=multi-user.target
sudo systemctl enable --now loki.service
  • Jalankan Promtail di systemd
sudo nano /etc/systemd/system/promtail.service
  • config systemd Promtail
[Unit]
Description=Promtail

[Service]
User=root
Group=root
Type=simple
ExecStart=/usr/local/bin/promtail-linux-amd64 \
-config.file=/etc/promtail/promtail-config.yaml

[Install]

WantedBy=multi-user.target
sudo systemctl enable --now promtail.service

0

0

0

Hajar Aswad

Jakarta Selatan, Indonesia

Full Stack Developer | Web Developer | Backend Developer

More Articles

Showwcase is a professional tech network with over 0 users from over 150 countries. We assist tech professionals in showcasing their unique skills through dedicated profiles and connect them with top global companies for career opportunities.

© Copyright 2025. Showcase Creators Inc. All rights reserved.