Sometimes there is need to dig trough logs stored in Grafana Loki on CLI. Building temporary docker container for just logcli is an option.
-
Start debian docker.
docker run --name debian --network loki -ti debian:latest
You should end up in root shell prompt inside debian docker container. If you need data exported to host’s disk than bind mount some folder inside container. - Install prerequisites.
apt update apt install wget unzip
- Pull precompiled logcli from github. replace ‘'’v2.8.2’’’ with whatever current and do not forget select correct CPU architecture.
cd root wget https://github.com/grafana/loki/releases/download/v2.8.2/logcli-linux-amd64.zip
- unzip and rename
unzip logcli-linux-amd64.zip Archive: logcli-linux-amd64.zip inflating: logcli-linux-amd64 mv logcli-linux-amd64 logcli
- Point logcli to where is your Loki server is located
export LOKI_ADDR="http://loki.example.com:3100"
- Run your queries
./logcli query --timezone=Local --from="2023-05-02T00:00:00Z" --to="2023-05-02T01:00:00Z" --limit=0 '{job="syslog"}'