四、日志收集loki+ promtail+grafana

一、简介

Loki是受Prometheus启发由Grafana Labs团队开源的水平可扩展,高度可用的多租户日志聚合系统。 开发语言: Google Go。它的设计具有很高的成本效益,并且易于操作。使用标签来作为索引,而不是对全文进行检索,也就是说,你通过这些标签既可以查询日志的内容也可以查询到监控的数据签,极大地降低了日志索引的存储。系统架构十分简单,由以下3个部分组成 :

Loki 是主服务器,负责存储日志和处理查询 ;

promtail 是代理,负责收集日志并将其发送给 loki ;

Grafana 用于 UI 展示;

只要在应用程序服务器上安装promtail来收集日志然后发送给Loki存储,就可以在Grafana UI界面通过添加Loki为数据源进行日志查询(如果Loki服务器性能不够,可以部署多个Loki进行存储及查询)。作为一个日志系统不光只有查询分析日志的能力,还能对日志进行监控和报警。

promtail收集并将日志发送给loki的 Distributor 组件 Distributor会对接收到的日志流进行正确性校验,并将验证后的日志分批并行发送到Ingester Ingester 接受日志流并构建数据块,压缩后存放到所连接的存储后端 Querier 收到HTTP查询请求,并将请求发送至Ingester 用以获取内存数据 ,Ingester 收到请求后返回符合条件的数据 ; 如果 Ingester 没有返回数据,Querier 会从后端存储加载数据并遍历去重执行查询 ,通过HTTP返回查询结果

二、下载安装
1.下载
https://github.com/grafana/loki/releases
loki-linux-amd64.zip
promtail-linux-amd64.zip
2.创建目录并解压
mkdir loki
cd loki
mkdir chunks
mkdir index
unzip loki-linux-amd64.zip
3.创建配置文件vim config.yaml
# This is a complete configuration to deploy Loki backed by the filesystem.
# The index will be shipped to the storage via tsdb-shipper.

auth_enabled: false

server:
  http_listen_port: 3100

common:
  ring:
    instance_addr: 172.17.0.122
    kvstore:
      store: inmemory
  replication_factor: 1
  path_prefix: /data/prometheus/loki

schema_config:
  configs:
  - from: 2024-07-10
    store: tsdb
    object_store: filesystem
    schema: v13
    index:
      prefix: index_
      period: 24h

storage_config:
  filesystem:
    directory: /data/prometheus/loki/chunks
4.启动Loki:
nohup loki-linux-amd64 -config.file=config.yaml >loki.log 2>&1 &
5.应用服务器安装promtail
mkdir promtail
unzip promtail-linux-amd64.zip
6.创建配置文件vim promtail.yaml
server:
  http_listen_port: 9080
  grpc_listen_port: 0

positions:
  filename: ./positions.yaml

clients:
  - url: http://172.17.0.122:3100/loki/api/v1/push

scrape_configs:
 - job_name: ehr
   static_configs:
   - targets:
       - 172.17.0.112
   - labels:
      job: ehr
      host: 172.17.0.112
      __path__: /data/ehr/output.log #应用服务日志
7.启动promtail
nohup ./promtail-linux-amd64 -config.file=./promtail.yaml > ./promtail.log 2>&1 &
8.grafana操作
连接-》数据源-》添加新数据源-》选择loki-》填写loki地址并保存-》数据源列表loki点击Explore-》label fiters下选择job以及promtail中的job_name-》右上角运行查询

之后可导入仪表板进行查看

相关推荐
范范08257 小时前
Grafana进阶教程:使用Loki、Tempo进行日志与追踪可视化
grafana
神即道 道法自然 如来1 天前
如何在Centos7构建调试“Jmeter-InfluxDB-Grafana“?
jmeter·grafana
henan程序媛2 天前
K8S日志收集
容器·kubernetes·loki·efk
景天科技苑3 天前
【Grafana】Prometheus结合Grafana打造智能监控可视化平台
grafana·prometheus·监控可视化
地球空间-技术小鱼3 天前
Grafana 在 Linux 系统上安装
linux·运维·grafana
神即道 道法自然 如来4 天前
“Jmeter-InfluxDB-Grafana“常见错误有哪些如何解决?
jmeter·grafana
一缕82年的清风4 天前
docker安装prometheus、grafana监控SpringBoot
docker·grafana·prometheus
钡铼技术物联网关5 天前
ARM 工业计算机搭载 FUXA 组态软件:开启智能制造新时代
arm开发·信息可视化·自动化·硬件工程·grafana
范范08255 天前
Grafana仪表盘设计最佳实践:如何创建有效的监控面板
信息可视化·grafana
王羲之的之5 天前
[解决]Prometheus 与 Grafana进行组合,但是不显示数据与图像
grafana·prometheus