mirror of https://github.com/grafana/loki
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
141 lines
4.6 KiB
141 lines
4.6 KiB
|
6 years ago
|
# Querying Loki with LogCLI
|
||
|
7 years ago
|
|
||
|
6 years ago
|
If you prefer a command line interface, LogCLI also allows users to run LogQL
|
||
|
|
queries against a Loki server.
|
||
|
7 years ago
|
|
||
|
|
## Installation
|
||
|
|
|
||
|
6 years ago
|
### Binary (Recommended)
|
||
|
6 years ago
|
|
||
|
|
Navigate to the [Loki Releases page](https://github.com/grafana/loki/releases)
|
||
|
|
and download the `logcli` binary for your OS:
|
||
|
|
|
||
|
6 years ago
|
```bash
|
||
|
|
# download a binary (adapt app, os and arch as needed)
|
||
|
6 years ago
|
# installs v0.3.0. For up to date URLs refer to the release's description
|
||
|
|
$ curl -fSL -o "/usr/local/bin/logcli.gz" "https://github.com/grafana/logcli/releases/download/v0.3.0/logcli-linux-amd64.gz"
|
||
|
6 years ago
|
$ gunzip "/usr/local/bin/logcli.gz"
|
||
|
7 years ago
|
|
||
|
6 years ago
|
# make sure it is executable
|
||
|
|
$ chmod a+x "/usr/local/bin/logcli"
|
||
|
7 years ago
|
```
|
||
|
|
|
||
|
6 years ago
|
### From source
|
||
|
7 years ago
|
|
||
|
6 years ago
|
Use `go get` to install `logcli` to `$GOPATH/bin`:
|
||
|
|
|
||
|
7 years ago
|
```
|
||
|
6 years ago
|
$ go get github.com/grafana/loki/cmd/logcli
|
||
|
7 years ago
|
```
|
||
|
|
|
||
|
|
## Usage
|
||
|
|
|
||
|
|
### Example
|
||
|
|
|
||
|
6 years ago
|
If you are running on Grafana Cloud, use:
|
||
|
|
|
||
|
|
```bash
|
||
|
7 years ago
|
$ export GRAFANA_ADDR=https://logs-us-west1.grafana.net
|
||
|
|
$ export GRAFANA_USERNAME=<username>
|
||
|
|
$ export GRAFANA_PASSWORD=<password>
|
||
|
6 years ago
|
```
|
||
|
6 years ago
|
|
||
|
|
Otherwise you can point LogCLI to a local instance directly
|
||
|
|
without needing a username and password:
|
||
|
|
|
||
|
|
```bash
|
||
|
6 years ago
|
$ export GRAFANA_ADDR=http://localhost:3100
|
||
|
|
```
|
||
|
6 years ago
|
|
||
|
|
> Note: If you are running Loki behind a proxy server and you have
|
||
|
|
> authentication configured, you will also have to pass in GRAFANA_USERNAME
|
||
|
|
> and GRAFANA_PASSWORD accordingly.
|
||
|
6 years ago
|
|
||
|
6 years ago
|
```bash
|
||
|
7 years ago
|
$ logcli labels job
|
||
|
|
https://logs-dev-ops-tools1.grafana.net/api/prom/label/job/values
|
||
|
|
cortex-ops/consul
|
||
|
|
cortex-ops/cortex-gw
|
||
|
|
...
|
||
|
6 years ago
|
|
||
|
7 years ago
|
$ logcli query '{job="cortex-ops/consul"}'
|
||
|
6 years ago
|
https://logs-dev-ops-tools1.grafana.net/api/prom/query?query=%7Bjob%3D%22cortex-ops%2Fconsul%22%7D&limit=30&start=1529928228&end=1529931828&direction=backward®exp=
|
||
|
7 years ago
|
Common labels: {job="cortex-ops/consul", namespace="cortex-ops"}
|
||
|
|
2018-06-25T12:52:09Z {instance="consul-8576459955-pl75w"} 2018/06/25 12:52:09 [INFO] raft: Snapshot to 475409 complete
|
||
|
|
2018-06-25T12:52:09Z {instance="consul-8576459955-pl75w"} 2018/06/25 12:52:09 [INFO] raft: Compacting logs from 456973 to 465169
|
||
|
|
```
|
||
|
7 years ago
|
|
||
|
|
### Configuration
|
||
|
|
|
||
|
7 years ago
|
Configuration values are considered in the following order (lowest to highest):
|
||
|
7 years ago
|
|
||
|
6 years ago
|
- Environment variables
|
||
|
|
- Command line flags
|
||
|
7 years ago
|
|
||
|
7 years ago
|
### Details
|
||
|
7 years ago
|
|
||
|
6 years ago
|
```bash
|
||
|
7 years ago
|
$ logcli help
|
||
|
|
usage: logcli [<flags>] <command> [<args> ...]
|
||
|
|
|
||
|
|
A command-line for loki.
|
||
|
|
|
||
|
|
Flags:
|
||
|
6 years ago
|
--help Show context-sensitive help (also try --help-long and --help-man).
|
||
|
|
-q, --quiet suppress everything but log lines
|
||
|
|
-o, --output=default specify output mode [default, raw, jsonl]
|
||
|
6 years ago
|
--addr="https://logs-us-west1.grafana.net"
|
||
|
6 years ago
|
Server address.
|
||
|
|
--username="" Username for HTTP basic auth.
|
||
|
|
--password="" Password for HTTP basic auth.
|
||
|
|
--ca-cert="" Path to the server Certificate Authority.
|
||
|
|
--tls-skip-verify Server certificate TLS skip verify.
|
||
|
|
--cert="" Path to the client certificate.
|
||
|
|
--key="" Path to the client certificate key.
|
||
|
7 years ago
|
|
||
|
|
Commands:
|
||
|
|
help [<command>...]
|
||
|
|
Show help.
|
||
|
|
|
||
|
6 years ago
|
query [<flags>] <query> [<regex>]
|
||
|
7 years ago
|
Run a LogQL query.
|
||
|
|
|
||
|
7 years ago
|
labels [<label>]
|
||
|
7 years ago
|
Find values for a given label.
|
||
|
|
|
||
|
|
$ logcli help query
|
||
|
6 years ago
|
usage: logcli query [<flags>] <query> [<regex>]
|
||
|
7 years ago
|
|
||
|
|
Run a LogQL query.
|
||
|
|
|
||
|
|
Flags:
|
||
|
6 years ago
|
--help Show context-sensitive help (also try --help-long and --help-man).
|
||
|
|
-q, --quiet suppress everything but log lines
|
||
|
|
-o, --output=default specify output mode [default, raw, jsonl]
|
||
|
6 years ago
|
--addr="https://logs-us-west1.grafana.net"
|
||
|
6 years ago
|
Server address.
|
||
|
|
--username="" Username for HTTP basic auth.
|
||
|
|
--password="" Password for HTTP basic auth.
|
||
|
|
--ca-cert="" Path to the server Certificate Authority.
|
||
|
|
--tls-skip-verify Server certificate TLS skip verify.
|
||
|
|
--cert="" Path to the client certificate.
|
||
|
|
--key="" Path to the client certificate key.
|
||
|
|
--limit=30 Limit on number of entries to print.
|
||
|
|
--since=1h Lookback window.
|
||
|
|
--from=FROM Start looking for logs at this absolute time (inclusive)
|
||
|
|
--to=TO Stop looking for logs at this absolute time (exclusive)
|
||
|
|
--forward Scan forwards through logs.
|
||
|
6 years ago
|
-t, --tail Tail the logs
|
||
|
|
--delay-for=0 Delay in tailing by number of seconds to accumulate logs for re-ordering
|
||
|
6 years ago
|
--no-labels Do not print any labels
|
||
|
6 years ago
|
--exclude-label=EXCLUDE-LABEL ...
|
||
|
6 years ago
|
Exclude labels given the provided key during output.
|
||
|
6 years ago
|
--include-label=INCLUDE-LABEL ...
|
||
|
6 years ago
|
Include labels given the provided key during output.
|
||
|
|
--labels-length=0 Set a fixed padding to labels
|
||
|
7 years ago
|
|
||
|
|
Args:
|
||
|
6 years ago
|
<query> eg '{foo="bar",baz="blip"}'
|
||
|
|
[<regex>]
|
||
|
7 years ago
|
```
|