Grafana+Loki+Promtail 日志监控

news/2024/10/6 3:30:57/文章来源:https://www.cnblogs.com/jruing/p/18288425

目录
  • 前置工作
  • 用户组(按需创建)
  • Grafana
  • Loki
  • Loki 配置文件
  • Promtail
  • 配置文件
  • 配置数据源
  • 创建仪表盘
  • 添加查询项

前置工作

  1. Centos 7
  2. 关闭防火墙 (systemctl stop firewalld)
  3. 独立的用户组(可以不创建)

用户组(按需创建)

# 创建用户组
groupadd grafana
# 新建一个家目录为`/home/grafana`,用户组为`grafana`,用户名为`grafana`的用户
useradd -d /home/grafana -g grafana grafana
# 切换用户
su - grafana
# 创建软件目录及按安装包目录
mkdir -p software
mkdir -p packages

Grafana

# 切换目录
cd packages
# 下载grafana
wget https://dl.grafana.com/enterprise/release/grafana-enterprise-11.1.0.linux-amd64.tar.gz
# 解压
tar -zxf grafana-enterprise-11.1.0.linux-amd64.tar.gz
# 移动目录
mv grafana-v11.1.0 ../software
# 切换目录
cd ../software/grafana-v11.1.0
# 启动服务(访问地址: http://ip:3000,默认用户名及密码:admin/admin),若出现无法访问,请检查防火墙状态是否为关闭的状态
./bin/grafana server

Loki

# 下载地址:https://github.com/grafana/loki/releases,请根据当前系统版本下载相应的文件,并将下载的文件放到packages目录中
# 解压并移动目录
unzip loki-linux-amd64.zip -d ../software/loki
# 创建loki配置文件
touch ../software/loki/loki.yaml
# 启动loki服务(-config.file 指定配置文件位置)
./loki-linux-amd64 -config.file=loki.yaml

Loki 配置文件

auth_enabled: falseserver:http_listen_port: 3100 # 服务http监听端口grpc_listen_port: 9096 # 服务grpc监听端口common:instance_addr: 127.0.0.1path_prefix: /tmp/lokistorage:filesystem:chunks_directory: /tmp/loki/chunksrules_directory: /tmp/loki/rulesreplication_factor: 1ring:kvstore:store: inmemoryquery_range:results_cache:cache:embedded_cache:enabled: truemax_size_mb: 100schema_config:configs:- from: 2020-10-24store: tsdbobject_store: filesystemschema: v13index:prefix: index_period: 24hruler:alertmanager_url: http://localhost:9093# By default, Loki will send anonymous, but uniquely-identifiable usage and configuration
# analytics to Grafana Labs. These statistics are sent to https://stats.grafana.org/
#
# Statistics help us better understand how Loki is used, and they show us performance
# levels for most users. This helps us prioritize features and documentation.
# For more information on what's sent, look at
# https://github.com/grafana/loki/blob/main/pkg/analytics/stats.go
# Refer to the buildReport method to see what goes into a report.
#
# If you would like to disable reporting, uncomment the following lines:
#analytics:
#  reporting_enabled: false

Promtail

# 下载地址:https://github.com/grafana/loki/releases,请根据当前系统版本下载相应的文件,并将下载的文件放到packages目录中
# 解压并移动目录
unzip promtail-linux-amd64.zip -d ../software/promtail
# 创建promtail配置文件
touch ../software/promtail/promtail.yaml
# 启动Promtail服务
./promtail-linux-amd64 -config.file=promtail.yaml  -config.expand-env=true

配置文件

Promtail.yaml ,详细配置参考官方文档:https://grafana.com/docs/loki/latest/send-data/promtail/configuration/

server:http_listen_port: 9080grpc_listen_port: 0positions:filename: /home/grafana/software/promtail/pos/positions.yamlsync_period: 10clients:- url: http://192.168.200.128:3100/loki/api/v1/push # 这里需要修改为loki服务的ip地址scrape_configs:- job_name: test_1 # 任务名称(可以通过job_name字段区分项目)static_configs:- targets:- localhostlabels: # 可以自定义标签,比如主机ip,项目名称,项目环境等等ip: 192.168.200.128name: test_1env: test__path__: /home/grafana/logs/test_1.log # 日志路径pipeline_stages:- json:expressions:log_level: levelmsg: msgtimestamp: tsuuid: uuidrequest_data: request_data
{"level":"info","ts":"2024-07-04T22:53:26+08:00","msg":"用户查询函数","uuid":"2613d4a4-719e-488e-80c5-a18076ed041f","request_data":"map[]"}
{"level":"info","ts":"2024-07-04T22:53:26+08:00","msg":"用户查询成功","uuid":"2613d4a4-719e-488e-80c5-a18076ed041f"}
{"level":"info","ts":"2024-07-04T22:57:28+08:00","msg":"用户查询函数","uuid":"7887f8bf-8c29-407c-8534-d16ac9e779de","request_data":"map[page:1 pageSize:10]"}
{"level":"error","ts":"2024-07-04T22:57:28+08:00","msg":"用户查询失败","uuid":"7887f8bf-8c29-407c-8534-d16ac9e779de"}
{"level":"info","ts":"2024-07-04T22:57:31+08:00","msg":"用户查询函数","uuid":"d2734fb9-26e5-4828-99b8-1eb68cfb05c4","request_data":"map[page:1 pageSize:1]"}
{"level":"info","ts":"2024-07-04T22:57:31+08:00","msg":"用户查询成功","uuid":"d2734fb9-26e5-4828-99b8-1eb68cfb05c4"}

配置数据源

image-20240706143157243

image-20240706143234638

image-20240706143349698

image-20240706143444296

创建仪表盘

image-20240706163329677

image-20240706163539478

image-20240706163658091

添加查询项

image-20240706170323759

image-20240706170350247

image-20240706170556009

image-20240706170744977

image-20240706170842834

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/739754.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

source

进入题目右键源码发现一个假的flag base64解码啥也不是 目录扫描发现.git源码泄露,假的flag.txt下载.git进入目录 查看历史版本一一查看各个版本改动找到flag

cookies

进入题目,提示cookies伪造查看url发现filename为base64加密,发现参数line尝试查看index.php,base64加密对参数line进行遍历得到源码 error_reporting(0); $file=base64_decode(isset($_GET[filename])?$_GET[filename]:""); $line=isset($_GET[line])?intval($_…

成绩查询

进入题目猜测为sql注入 直接sqlmap一把梭 数据库表内容得到flag

秋名山车神

进入题目没刷新一次数字改变一次 直接上脚本 注意正则表达式得到flag

xxx二手交易市场

进入题目注册账号登陆后点击头像发现可以上传图片 上传正常图片bp抓包发现为jpeg类型且base64加密修改为php类型知道文件上传路径 蚁剑连接得到flag

《已解决》无法将“pip”项识别为 cmdlet、函数、脚本文件或可运行程序的名称

原因: Python 环境未正确配置:可能你没有将 Python 添加到系统的环境变量中。 你需要手动将 Python 的安装目录(以及包含 pip.exe 的文件夹)添加到系统的环境变量 PATH 中。解决: 1. 找到python的安装目录 键盘按下 win键+R键, 输入cmd回车。 随后输入 where pythonwhe…

最新扣子(Coze)实战案例:图像流工具之空间风格化,完全免费教程

🧙‍♂️ 大家好,我是斜杠君,手把手教你搭建扣子AI应用。 📜 本教程是《AI应用开发系列教程之扣子(Coze)实战教程》,完全免费学习。 👀 免费扣子Coze教程地址:https://www.bzfree.com/如果想学习AI应用搭建,请关注公众号,及时获取最新免费教程。 上节课讲了人像风格…

认识终端和shell

【教程】在macOS上用VSCode写C++代码 4 认识终端和shell 内建程序与内建命令 打开终端,其实相当于打开了shell。shell 可以运行一些程序(例如 sayhello、 /bin/mkdir )。 shell自身也带着一些程序(二进制可执行文件),这些程序就叫内建程序。 特点:调用shell内建程序的时…

LVGL一键打包图片工具,全部图片打包成一个bin文件,支持nor flash XIP模式下直接访问数据显示

最近做工程项目,需要用到LVGL,但是搜了很长时间没有看到合适的图片打包工具,大多都是生成数组或者单个的bin文件,这样烧录到nor flash很麻烦 后来看到一篇博客,博主的想法与我类似,不过他后面部分就做的麻烦了,所以,我直接从头写了一个工具,他的博客地址:https://www…

mini-lsm通关笔记-字符相关操作

本文捋一下mini-lsm中的字符相关操作[u8] Vec<u8> Bytes Buf KeySlice KeyBytes[u8]和Vec<u8> 这两个是rust内置的数据类型。 [u8]: 切片本身并不拥有数据,而是引用了数据。它由一个指向数组开始处的指针和一个表示数组长度的计数器组成。[u8]类型通常写作&[u…

张高兴的 MicroPython 入门指南:(二)GPIO 的使用

目录什么是 GPIO使用方法使用微动开关点亮板载 LED硬件需求电路代码参考 什么是 GPIO GPIO 是 General Purpose Input Output 的缩写,即“通用输入输出”。 Raspberry Pi Pico 左右两侧各有一列 GPIO 引脚, Pico 通过这两列引脚进行一些硬件上的扩展,与传感器进行交互等等。…

MySQL-17.其他数据日志

C-17.其他数据日志 在之前的数据库事务的章节中,已经讲过,redo log和undo log。 对于线上数据库应用系统,突然遭遇数据库宕机怎么办?在这种情况下,定位宕机的原因就非常关键。我们可以查看数据库的错误日志。因为日志中记录了数据库运行中的诊断信息,包括了错误,警告和注…