Skip to content

Instantly share code, notes, and snippets.

@ruanbekker
Last active January 22, 2024 07:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ruanbekker/99e110020baafb8f480d2ffa46ea75c4 to your computer and use it in GitHub Desktop.
Save ruanbekker/99e110020baafb8f480d2ffa46ea75c4 to your computer and use it in GitHub Desktop.
Quick Demonstration how to Pipe to Loki with Loki, LogCLI and Promtail

Provision a VM with Multipass:

$ multipass shell
$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.4 LTS
Release:	18.04
Codename:	bionic

Download logcli, loki, promtail and loki-config:

$ wget https://github.com/grafana/loki/releases/download/v2.0.0/logcli-linux-amd64.zip
$ wget https://github.com/grafana/loki/releases/download/v2.0.0/loki-linux-amd64.zip
$ wget https://github.com/grafana/loki/releases/download/v2.0.0/promtail-linux-amd64.zip
$ wget https://raw.githubusercontent.com/grafana/loki/v2.0.0/cmd/loki/loki-local-config.yaml
$ wget https://raw.githubusercontent.com/grafana/loki/v2.0.0/cmd/promtail/promtail-local-config.yaml # if needed

Unzip and start loki:

$ sudo apt update && sudo apt install unzip screen -y
$ unzip loki-linux-amd64.zip
$ unzip logcli-linux-amd64.zip
$ unzip promtail-linux-amd64.zip
$ ./loki-linux-amd64 -config.file=loki-local-config.yaml &

Redirect output to loki and add labels {app=“cli”}:

$ echo "this is a test" | ./promtail-linux-amd64 --stdin --client.url http://localhost:3100/loki/api/v1/push --client.external-labels=app=cli -server.disable

Verify if the labels are present

$ ./logcli-linux-amd64 --addr="http://localhost:3100" labels app
http://localhost:3100/loki/api/v1/label/app/values?end=1605007379076311840&start=1605003779076311840
cli

Run a query:

$ ./logcli-linux-amd64 --addr="http://localhost:3100" query '{app="cli"}' --quiet --output raw
level=info ts=2020-11-10T11:22:36.264048352Z caller=metrics.go:81 org_id=fake traceID=4b0dac0a6ae87410 latency=fast query="{app=\"cli\"}" query_type=limited range_type=range length=1h0m0s step=14s duration=627.474µs status=200 throughput_mb=0.022311 total_bytes_mb=1.4e-05
this is a test

Resources:

sudo apt update && sudo apt install unzip -y
sudo apt update && sudo apt install unzip screen -y
for app in loki logcli promtail; do wget "https://github.com/grafana/loki/releases/download/v2.0.0/${app}-linux-amd64.zip"; done
wget https://raw.githubusercontent.com/grafana/loki/v2.0.0/cmd/loki/loki-local-config.yaml
for app in loki logcli promtail; do unzip "${app}-linux-amd64.zip"; done
screen -S loki -m -d sh -c "./loki-linux-amd64 -config.file=loki-local-config.yaml"
echo "this is a test" | ./promtail-linux-amd64 --stdin --client.url http://localhost:3100/loki/api/v1/push --client.external-labels=app=cli -server.disable
./logcli-linux-amd64 --addr="http://localhost:3100" labels app
./logcli-linux-amd64 --addr="http://localhost:3100" query '{app="cli"}' --quiet --output raw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment