3

【日志系统】Loki日志监控 - 入门初体验 - 怒放吧德德

 1 year ago
source link: https://www.cnblogs.com/lyd-code/p/16841789.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

使用Grafana+Loki+Promtail入门级部署分布式日志系统(windows环境)

😄生命不息,写作不止
🔥 继续踏上学习之路,学之分享笔记
👊 总有一天我也能像各位大佬一样
🏆 一个有梦有戏的人 @怒放吧德德
🌝分享学习心得,欢迎指正,大家一起学习成长!

简介

由于需求对日志进行监控,但是日志又很大,不能直接通过流的方式直接将text读取出来,可以使用grafana+loki+promtail搭建一个轻量级的日志系统,部署也简单方便。grafana提供可视化展示日志,然而loki是存储日志和处理查询,Promtail相当于loki的代理,收集日志发给loki。

1、安装grafana

2、安装loki

下载地址:https://github.com/grafana/loki/releases
下载loki-windows-amd64.exe.zip安装包,并进行解压到F:\soft\grafana\logmanager,解压得到loki-windows-amd64.exe
F:\soft\grafana\logmanager目录下添加loki-local-config.yaml文件,内容如下



auth_enabled: false server: http_listen_port: 3100

ingester: lifecycler: address: 127.0.0.1 ring: kvstore: store: inmemory replication_factor: 1 final_sleep: 0s chunk_idle_period: 5m chunk_retain_period: 30s max_transfer_retries: 0

schema_config: configs: - from: 2022-08-06 store: boltdb object_store: filesystem schema: v11 index: prefix: index_ period: 672h #每张表的时间范围28天

storage_config: boltdb: directory: /tmp/loki/index # 索引文件存储地址

filesystem: directory: /tmp/loki/chunks # 块存储地址

limits_config: enforce_metric_name: false reject_old_samples: true

chunk_store_config: max_look_back_period: 24h # 最大可查询历史日期 28天,这个时间必须是schema_config中的period的倍数,否则报错。

table_manager: # 配置保留多少天的数据,那么之前数据会被清除,Loki中默认保留所有数据 retention_deletes_enabled: true retention_period: 24h

打开cmd定位到exe目录,执行命令:.\loki-windows-amd64.exe --config.file=loki-local-config.yaml,loki服务启动成功
配置通信端口号:



server: http_listen_port: 3200 # http访问端口 grpc_listen_port: 9096 # 通信端口


.\loki-windows-amd64.exe --config.file=loki-local-config.yaml

3、安装promtail

下载地址:https://github.com/grafana/loki/releases
下载promtail-windows-amd64.exe.zip安装包,并解压到F:\soft\grafana\promtail目录,得到promtail-windows-amd64.exe
F:\soft\grafana\promtail目录下添加promtail-local-config.yaml文件,内容如下



server: http_listen_port: 9080 grpc_listen_port: 0

positions: filename: /tmp/positions.yaml

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

scrape_configs: - job_name: system static_configs: - targets: - localhost labels: job: viplogs __path__: F:\soft\grafana\testlogs\*.log - job_name: system static_configs: - targets: - localhost labels: job: viplogs __path__: F:\soft\grafana\testlogs\*.log

打开cmd定位到exe目录,执行命令: .\promtail-windows-amd64.exe --config.file=promtail-local-config.yaml,loki服务启动成功。



.\promtail-windows-amd64.exe --config.file=promtail-local-config.yaml

4、使用Grafana+loki+promtail查看日志

登录grafana后在Data sources -> Add data source选择loki配置好相应信息即可

输入labels标签,右上角可以设置查看时间,然后查询就可以看到,并且支持定时查询日志,笔者暂时没有开启收集日志,并且是使用loki+logback收集的日志(后期会提供相应的篇章介绍),因此截图中没有日志,但能看到标签。

这样就能够查看日志了,loki是比较轻量级的日志监控系统,通过logback可以定制自己打印日志,还能够自己实现可视化,对于一些工业项目中,可以将日志显示在后台上,方便实施人员查看,这个以后会有相关文章来介绍,这个只是简单的介绍。

👍创作不易,如有错误请指正,感谢观看!记得点赞哦!👍

__EOF__


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK