Grafana Loki Quick Try

Insert image description here
Grafana Loki is an aggregated log system that supports horizontal expansion and high availability. Unlike other aggregated log systems, Loki only indexes the metadata-tags of the log. The log data will be compressed and stored in object storage, and can even be stored in the object storage. In the local file system, costs can be effectively reduced; multi-tenant, Loki allows multiple tenants to share a Loki instance, and tenant data is completely isolated; third-party agents are supported through plug-ins; logs are queried through LogQL, similar to PromQL; alarms can be communicated with Prometheus , Grafana’s alarm system is seamlessly integrated; it can be seamlessly integrated with Mimir and Tempo to achieve long-term log storage and link tracking.

As shown in the figure below, it is a typical aggregated log system architecture based on Loki deployment
Insert image description here
It consists of three parts:

  • Agent clients, such as Promtail and Grafana Agent, the system captures logs through the agent, converts the logs into streams after adding tags, and pushes the streams to Loki through HTTP API
  • Loki, the main server, is responsible for receiving and storing logs and queries, and supports deployment in different modes.
  • Grafana is used to query and display log data. You can also use LogCLI or Loki API to query logs.

Loki installation

Loki supports 6 installation methods: Helm, Docker, Tanka, Local, Istio, and through source code. The most convenient and quickest way to test locally is to use Docker. Here is the Docker method.

First create a directory to store Loki configuration files, enter the directory and execute the following command:

Mac/Linux

wget https://raw.githubusercontent.com/grafana/loki/v2.9.1/cmd/loki/loki-local-config.yaml -O loki-config.yaml
docker run --name loki -d -v $(pwd):/mnt/config -p 3100:3100 grafana/loki:2.9.1 -config.file=/mnt/config/loki-config.yaml
wget https://raw.githubusercontent.com/grafana/loki/v2.9.1/clients/cmd/promtail/promtail-docker-config.yaml -O promtail-config.yaml
docker run --name promtail -d -v $(pwd):/mnt/config -v /var/log:/var/log --link loki grafana/promtail:2.9.1 -config.file=/mnt/config/promtail-config.yaml

1. macOS 14 does not support the wget command. You can directly download the file through the address and 改名
2. The command /var/log is a local system Log, here you need to replace it with the log path of your own service

Windows

cd "<local-path>"
wget https://raw.githubusercontent.com/grafana/loki/v2.9.1/cmd/loki/loki-local-config.yaml -O loki-config.yaml
docker run --name loki -v <local-path>:/mnt/config -p 3100:3100 grafana/loki:2.9.1 --config.file=/mnt/config/loki-config.yaml
wget https://raw.githubusercontent.com/grafana/loki/v2.9.1/clients/cmd/promtail/promtail-docker-config.yaml -O promtail-config.yaml
docker run -v <local-path>:/mnt/config -v /var/log:/var/log --link loki grafana/promtail:2.9.1 --config.file=/mnt/config/promtail-config.yaml

After the installation is complete, visit http://localhost:3100/metrics to see the Loki metrics.

Configure log reading

We want to see the effect simply and quickly, then use the static configuration log path method, openpromtail-config.yaml, and modify the following configuration

scrape_configs:
- job_name: local
  static_configs:
  - targets:
      - localhost
    labels:
      job: 服务名
      __path__: /data/logs/日志路径/*log

Configure Grafana

Add Loki data source in Grafana, fill in the Loki address as shown in the figure, and save after passing the test
Insert image description here
Insert image description here
Query the log through Explore:
Insert image description here
Through Label filters , you can select the log to be queried by file name or task name. Supports querying by time range and viewing logs in real time.

some problems

During the early adopter process, I also encountered some problems. The newly created Eureka Demo could never find the log on Grafana, and there was no corresponding job and filename. When using the real-time log to observe the log, it was easy to get disconnected and the log was not displayed. This I don’t know the cause of these two problems, but they don’t affect use.


Other articles recommended by the author, welcome to study:
Prometheus series articles

  1. Introduction and installation of Prometheus
  2. Intuitively feel PromQL and its data types
  3. PromQL selectors and operators
  4. PromQL functions
  5. Introduction to Prometheus alarm mechanism and command interpretation
  6. In-depth analysis of Prometheus alarm module configuration
  7. Prometheus configuration authentication
  8. Prometheus dynamic pull monitoring service
  9. Prometheus monitors cloud Mysql and self-built Mysql

Grafana series of articles, version: OOS v9.3.1

  1. Introduction and installation of Grafana
  2. Introduction to configuration parameters of Grafana monitoring large screen (1)
  3. Introduction to configuration parameters of Grafana monitoring large screen (2)
  4. Grafana monitors large-screen visualization charts
  5. Grafana query data and transform data
  6. Introduction to Grafana alarm module
  7. Grafana alarm access Feishu notification

Guess you like

Origin blog.csdn.net/weixin_40972073/article/details/135036756
try