Files
loki/docs/getting-started/logcli.md
Robert Fratto 65ba42a6e7 Documentation Rewrite (#982)
* docs: create structure of docs overhaul

This commit removes all old docs and lays out the table of contents and
framework for how the new documentation will be intended to be read.

* docs: add design docs back in

* docs: add community documentation

* docs: add LogQL docs

* docs: port existing operations documentation

* docs: add new placeholder file for promtail configuration docs

* docs: add TOC for operations/storage

* docs: add Loki API documentation

* docs: port troubleshooting document

* docs: add docker-driver documentation

* docs: link to configuration from main docker-driver document

* docs: update API for new paths

* docs: fix broken links in api.md and remove json marker from examples

* docs: incorporate api changes from #1009

* docs: port promtail documentation

* docs: add TOC to promtail configuration reference

* docs: fix promtail spelling errors

* docs: add loki configuration reference

* docs: add TOC to configuration

* docs: add loki configuration example

* docs: add Loki overview with brief explanation about each component

* docs: add comparisons document

* docs: add info on table manager and update storage/README.md

* docs: add getting started

* docs: incorporate config yaml changes from #755

* docs: fix typo in releases url for promtail

* docs: add installation instructions

* docs: add more configuration examples

* docs: add information on fluentd client

fluent-bit has been temporarily removed until the PR for it is merged.

* docs: PR review feedback

* docs: add architecture document

* docs: add missing information from old docs

* `localy` typo

Co-Authored-By: Ed Welch <ed@oqqer.com>

* docs: s/ran/run/g

* Typo

* Typo

* Tyop

* Typo

* docs: fixed typo

* docs: PR feedback

* docs: @cyriltovena PR feedback

* docs: add more details to promtail url config option

* docs: expand promtail's pipelines document with extra detail

* docs: remove reference to Stage interface in pipelines.md

* docs: fixed some spelling

* docs: clarify promtail configuration and scraping

* docs: attempt #2 at explaining promtail's usage of machine hostname

* docs: spelling fixes

* docs: add reference to promtail custom metrics and fix silly typo

* docs: cognizant -> aware

* docs: typo

* docs: typos

* docs: add which components expose which API endpoints in microservices mode

* docs: change ksonnet installation to tanka

* docs: address most @pracucci feedback

* docs: fix all spelling errors so reviewers don't have to keep finding them :)

* docs: incorporate changes to API endpoints made in #1022

* docs: add missing loki metrics

* docs: add missing promtail metrics

* docs: @pstribrany feedback

* docs: more @pracucci feedback

* docs: move metrics into a table

* docs: update push path references to /loki/api/v1/push

* docs: add detail to further explain limitations of monolithic mode

* docs: add alternative names to modes_of_operation diagram

* docs: add log ordering requirement

* docs: add procedure for updating docs with latest version

* docs: separate out stages documentation into one document per stage

* docs: list supported stores in storage documentation

* docs: add info on duplicate log lines in pipelines

* docs: add line_format as key feature to fluentd

* docs: hopefully final commit :)
2019-09-25 13:54:21 -04:00

4.6 KiB

Querying Loki with LogCLI

If you prefer a command line interface, LogCLI also allows users to run LogQL queries against a Loki server.

Installation

Navigate to the Loki Releases page and download the logcli binary for your OS:

# download a binary (adapt app, os and arch as needed)
# 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"
$ gunzip "/usr/local/bin/logcli.gz"

# make sure it is executable
$ chmod a+x "/usr/local/bin/logcli"

From source

Use go get to install logcli to $GOPATH/bin:

$ go get github.com/grafana/loki/cmd/logcli

Usage

Example

If you are running on Grafana Cloud, use:

$ export GRAFANA_ADDR=https://logs-us-west1.grafana.net
$ export GRAFANA_USERNAME=<username>
$ export GRAFANA_PASSWORD=<password>

Otherwise you can point LogCLI to a local instance directly without needing a username and password:

$ export GRAFANA_ADDR=http://localhost:3100

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.

$ logcli labels job
https://logs-dev-ops-tools1.grafana.net/api/prom/label/job/values
cortex-ops/consul
cortex-ops/cortex-gw
...

$ logcli query '{job="cortex-ops/consul"}'
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&regexp=
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

Configuration

Configuration values are considered in the following order (lowest to highest):

  • Environment variables
  • Command line flags

Details

$ logcli help
usage: logcli [<flags>] <command> [<args> ...]

A command-line for loki.

Flags:
      --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]
      --addr="https://logs-us-west1.grafana.net"
                         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.

Commands:
  help [<command>...]
    Show help.

  query [<flags>] <query> [<regex>]
    Run a LogQL query.

  labels [<label>]
    Find values for a given label.

$ logcli help query
usage: logcli query [<flags>] <query> [<regex>]

Run a LogQL query.

Flags:
      --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]
      --addr="https://logs-us-west1.grafana.net"
                         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.
  -t, --tail             Tail the logs
      --delay-for=0      Delay in tailing by number of seconds to accumulate logs for re-ordering
      --no-labels        Do not print any labels
      --exclude-label=EXCLUDE-LABEL ...
                         Exclude labels given the provided key during output.
      --include-label=INCLUDE-LABEL ...
                         Include labels given the provided key during output.
      --labels-length=0  Set a fixed padding to labels

Args:
  <query>    eg '{foo="bar",baz="blip"}'
  [<regex>]