grafana / loki
- четверг, 13 декабря 2018 г. в 00:17:17
Go
Like Prometheus, but for logs.
Loki is a horizontally-scalable, highly-available, multi-tenant log aggregation system inspired by Prometheus. It is designed to be very cost effective and easy to operate, as it does not index the contents of the logs, but rather a set of labels for each log stream.
Compared to other log aggregation systems, Loki:
Loki consists of 3 components:
loki is the main server, responsible for storing logs and processing queries.promtail is the agent, responsible for gathering logs and sending them to loki.Currently there are three ways to try out Loki: using our free hosted demo, running it locally with Docker or building from source.
Grafana is running a free, hosted demo cluster of Loki; instructions for getting access can be found at grafana.com.
The Docker images for Loki and Promtail are available on DockerHub.
To test locally using docker run:
Create a Docker network that the Docker containers can share:
docker network create lokiStart the Loki server:
docker run --name loki --network=loki -p 3100:3100 --volume "$PWD/docs:/etc/loki" grafana/loki:master -config.file=/etc/loki/loki-local-config.yamlThen start the Promtail agent. The default config polls the contents of your /var/log directory.
docker run --name promtail --network=loki --volume "$PWD/docs:/etc/promtail" --volume "/var/log:/var/log" grafana/promtail:master -config.file=/etc/promtail/promtail-docker-config.yamlIf you also want to run Grafana in docker:
docker run --name grafana --network=loki -p 3000:3000 -e "GF_EXPLORE_ENABLED=true" grafana/grafana:masterFollow the steps for configuring the datasource in Grafana in the section below and set the URL field to: http://loki:3100
Another option is to use the docker-compose file in the docs directory:
docker-compose.yaml)cd loki/docsdocker-compose upIf you have have an older cached version of the grafana/grafana:master container then start by doing either:
docker pull grafana/grafana:masterOr for docker-compose:
docker-compose pullGrafana ships with built-in support for Loki in the latest nightly builds. Loki support will be officially released in Grafana 6.0.
+ Add data source button in the top header.http://localhost:3100Read more about the Explore feature in the Grafana docs and on how to search and filter logs with Loki.
Loki can be run in a single host, no-dependencies mode using the following commands.
$ go build ./cmd/loki
$ ./loki -config.file=./docs/loki-local-config.yaml
...To run promtail, use the following commands:
$ go build ./cmd/promtail
$ ./promtail -config.file=./docs/promtail-local-config.yaml
...Grafana is Loki's UI, so you'll also want to run one of those:
$ docker run -ti -p 3000:3000 -e "GF_EXPLORE_ENABLED=true" grafana/grafana:masterIn the Grafana UI (http://localhost:3000), log in with "admin"/"admin", add a new "Grafana Loki" datasource for http://host.docker.internal:3100, then go to explore and enjoy!
It is possible to configure Grafana datasources using config files with Grafana’s provisioning system. You can read more about how it works in the Grafana documentation.
Here is a simple example of the provisioning yaml config for the Grafana Loki datasource:
apiVersion: 1
datasources:
- name: Loki
type: loki
access: proxy
url: http://localhost:3100
editable: falseExample with basic auth:
apiVersion: 1
datasources:
- name: Loki
type: loki
access: proxy
url: http://localhost:3100
editable: false
basicAuth: true
basicAuthUser: my_user
basicAuthPassword: test_password