Nginx loki监控日志的学习


背景

学习自:
https://mp.weixin.qq.com/s/Qt1r7vzWvCcJpNDilWHuxQ
增加了一些自己的理解

第一部分nginx日志的完善

在logformat的后面增加一个:
log_format json_analytics escape=json '{'
'"msec": "$msec", ' # request unixtime in seconds with a milliseconds resolution
'"connection": "$connection", ' # connection serial number
'"connection_requests": "$connection_requests", ' # number of requests made in connection
'"pid": "$pid", ' # process pid
'"request_id": "$request_id", ' # the unique request id
'"request_length": "$request_length", ' # request length (including headers and body)
'"remote_addr": "$remote_addr", ' # client IP
'"remote_user": "$remote_user", ' # client HTTP username
'"remote_port": "$remote_port", ' # client port
'"time_local": "$time_local", '
'"time_iso8601": "$time_iso8601", ' # local time in the ISO 8601 standard format
'"request": "$request", ' # full path no arguments if the request
'"request_uri": "$request_uri", ' # full path and arguments if the request
'"args": "$args", ' # args
'"status": "$status", ' # response status code
'"body_bytes_sent": "$body_bytes_sent", ' # the number of body bytes exclude headers sent to a client
'"bytes_sent": "$bytes_sent", ' # the number of bytes sent to a client
'"http_referer": "$http_referer", ' # HTTP referer
'"http_user_agent": "$http_user_agent", ' # user agent
'"http_x_forwarded_for": "$http_x_forwarded_for", ' # http_x_forwarded_for
'"http_host": "$http_host", ' # the request Host: header
'"server_name": "$server_name", ' # the name of the vhost serving the request
'"request_time": "$request_time", ' # request processing time in seconds with msec resolution
'"upstream": "$upstream_addr", ' # upstream backend server for proxied requests
'"upstream_connect_time": "$upstream_connect_time", ' # upstream handshake time incl. TLS
'"upstream_header_time": "$upstream_header_time", ' # time spent receiving upstream headers
'"upstream_response_time": "$upstream_response_time", ' # time spend receiving upstream body
'"upstream_response_length": "$upstream_response_length", ' # upstream response length
'"upstream_cache_status": "$upstream_cache_status", ' # cache HIT/MISS where applicable
'"ssl_protocol": "$ssl_protocol", ' # TLS protocol
'"ssl_cipher": "$ssl_cipher", ' # TLS cipher
'"scheme": "$scheme", ' # http or https
'"request_method": "$request_method", ' # request method
'"server_protocol": "$server_protocol", ' # request protocol, like HTTP/1.1 or HTTP/2.0
'"pipe": "$pipe", ' # "p" if request was pipelined, "." otherwise
'"gzip_ratio": "$gzip_ratio", '
'"http_cf_ray": "$http_cf_ray"'
'}';
然后日志修改为:
access_log /data/nginx/gscloudsu.log json_analytics ;
注意文件日志等属性.
重启ningx:
lsof -i:5000 |awk '{print $2}' |xargs kill -9
cd /data/nginx
./nginx -c 5000.conf

下载loki等组件

https://github.com/grafana/loki/releases/tag/v2.9.2

最新版本是 2.9.2 我这边下载了四个文件备用
promtail-linux-arm64.zip
promtail-linux-amd64.zip
loki-linux-arm64.zip
loki-linux-amd64.zip 将 x86的截止放到 /usr/bin 目录下面
scp loki-linux-amd64 /usr/bin/loki
scp promtail-linux-amd64 /usr/bin/promtail

解压缩开启服务等

下载loki的配置文件:
地址为:
https://raw.githubusercontent.com/grafana/loki/main/examples/getting-started/loki-config.yaml
详细内容为:
mkdir /etc/loki
cat >/etc/loki/loki.yaml <<EOF
---
server:
http_listen_port: 3100
#memberlist:
# join_members:
# - loki:7946
schema_config:
configs:
- from: 2021-08-01
store: tsdb
object_store: s3
schema: v12
index:
prefix: index_
period: 24h
common:
path_prefix: /loki
replication_factor: 1
storage:
s3:
endpoint: minio:9000
insecure: true
bucketnames: loki-data
access_key_id: loki
secret_access_key: supersecret
s3forcepathstyle: true
ring:
kvstore:
store: memberlist
ruler:
storage:
s3:
bucketnames: loki-ruler
EOF 启动服务:
nohup /usr/bin/loki -config.file=/etc/loki/loki.yaml -auth.enabled=false &

配置promtail

cat >/etc/loki/promtail.yaml <<EOF
server:
http_listen_port: 9080
grpc_listen_port: 0 positions:
filename: /tmp/positions.yaml clients:
- url: http://127.0.0.1:3100/loki/api/v1/push scrape_configs:
- job_name: nginx
static_configs:
- targets:
- localhost
labels:
job: nginx_logs
__path__: /data/nginx/gscloudsu.log
EOF # 启动服务
nohup /usr/bin/promtail -config.file=/etc/loki/promtail.yaml &

数据源以及grafana的dashboard

增加 loki的数据源
增加 12559 的 2022年版本的json导入文件
注意不能选择新版本的. 新版本换了数据源. todo:
1. loki 设置密码
2. nginx 的geoip的设置
3. 学习另外一个springboot的监控指标
https://grafana.com/grafana/dashboards/17175-spring-boot-observability/
https://github.com/blueswen/spring-boot-observability

效果

Nginx loki监控日志的学习的更多相关文章

  1. ELK监控系统nginx / mysql慢日志

    ELK监控系统nginx / mysql慢日志 elasticsearch logstash kibana ELK监控系统nginx日志 1.环境准备 centos6.8_64 mini IP:192 ...

  2. 学习总结 之 WebApi服务监控 log4net记录监控日志

    在请求WebApi 的时候,我们更想知道在请求数据的时候,调用了哪个接口传了什么参数过来,调用这个Action花了多少时间,有没有人恶意请求.我们可以通过记录日志,对Action进行优化,可以通过日志 ...

  3. 写一个nginx监控日志

    下面的代码是实现一个nginx监控日志功能,是不是很好玩呢.

  4. 使用 Loki 进行日志报警(二)

    转载自:https://mp.weixin.qq.com/s?__biz=MzU4MjQ0MTU4Ng==&mid=2247492374&idx=1&sn=d09f6db623 ...

  5. 使用 Loki 进行日志报警(一)

    转载自:https://mp.weixin.qq.com/s?__biz=MzU4MjQ0MTU4Ng==&mid=2247492352&idx=1&sn=9c0cc7927b ...

  6. zabbix监控日志文件

    环境: 操作系统:centos 6.8  ,zabbix软件版本:zabbix 3.0.1 前提条件:zabbix客户端已经配置了主动模式,如何配置主动模式,请参考此文 监控日志keys 首先要了解k ...

  7. (72)zabbix监控日志文件 MySQL日志为例

    一般情况下,日志最先反映出应用当前的问题,在海量日志里面找到我们异常记录,然后记录下来,并且根据情况报警,大家可以监控系统日志.nginx.Apache.业务日志. 这边我拿常见的MySQL日志做监控 ...

  8. Zabbix 监控MySQL、Apache、Nginx应用监控

    zabbix对第三方应用软件的监控,主要有两个工作难点,一个是编写自定义监控脚本,另一个是在编写模板并导入zabbix web中,编写脚本这个要根据 监控需求定制即可,而编写模板文件有些难度,不过网上 ...

  9. nginx状态监控统计

    nginx是一款很优秀的web服务器软件,很多地方都有接触和使用到他,大部分的场景压力还没达到需要调优的地步,而调优的难点其实不在于调,而在于各项状态的监控,能够很快的找到资源在什么时候出现问题,调整 ...

  10. nginx 配置文件与日志模块

    内容概要 Nginx 虚拟主机 基于多 IP 的方式 基于多端口的方式 基于多域名的方式 日志配置(日志格式详解) Nginx 访问控制模块(可以去 Nginx.org 文档 documentatio ...

随机推荐

  1. Python——第一章:数据类型介绍

    数据类型: 区分不同的数据.不同的数据类型应该有不同的操作 数字: 做加减乘除+-*/ 整数,int 小数,float a= 10 #整数 b = 20 print(a + b) #加法运算 c = ...

  2. 善用 vscode 的批量和模板技巧来提效

    vs code 其实有很多实用的技巧可以在日常工作中带来很大的提效,但可能是开发中没有相应的痛点场景,因此有些技巧接触的人不多 本篇就来介绍下多光标的批量操作和模板代码两种技巧在日常工作中的提效 涉及 ...

  3. kubernetes web管理页面安装(二)

    参考文件: https://cloud.tencent.com/developer/article/1919416 参考命令: https://blog.51cto.com/smbands/49038 ...

  4. [集训队作业2013] 城市规划(NTT)

    一周一博客二专题计划 题面 n 个点的简单 (无重边无自环) 有标号无向连通图数目. 看着就很典 思路 设\(f(n)\)为n点连通图数目.设\(g(n)\)为n点不一定联通图数目,显然直接枚举每条边 ...

  5. 使用Java 17中的record替代Lombok的部分功能

    在DD长期更新的Java新特性专栏中,已经介绍过Java 16中开始支持的新特性:record的使用. 之前只是做了介绍,但没有结合之前的编码习惯或规范来聊聊未来的应用变化.最近正好因为互相revie ...

  6. 华为云数据库内核专家为您揭秘:GaussDB(for MySQL)并行查询有多快?

    摘要:GaussDB(for MySQL)并行查询为何快人一步?华为云数据库内核专家这样说 本文分享自华为云社区<华为云数据库内核专家为您揭秘:GaussDB(for MySQL)并行查询有多快 ...

  7. iOS IPA包的制作和上传步骤详解​

    目录 前言 一.IPA包的原理 二.IPA包上传的步骤 1.注册开发者账号 2.创建应用程序 3.编码和设计 4.生成证书和配置文件 5.打包IPA包 6.上传IPA包 三.总结 前言 iOS IPA ...

  8. 通用漏洞评分系统 (CVSS)系统入门指南

    通用漏洞评分系统 (CVSS) 是一个公共框架 ,用于评估软件中安全漏洞的严重性.这是一个中立的评分系统,让所有企业能够使用相同的评分框架对各种软件产品(从操作系统.数据库再到 Web 应用程序)的 ...

  9. 线下Meetup:在数智化转型背景下,火山引擎VeDI的大数据技术揭秘

     更多技术交流.求职机会,欢迎关注字节跳动数据平台微信公众号,回复[1]进入官方交流群   近日,联合火山引擎开发者社区,火山引擎数智平台(VeDI)<数智化转型背景下的火山引擎大数据技术揭秘& ...

  10. 我教你解决 Ubuntu 常见的三个问题:Window和Ubuntu无法复制,有另一个软件包管理程序正在运行、无法获得锁 /var/lib/apt/lists/lock - open (11: 资源暂时不可用)

    第一个问题:当自己遇到这个问题的时候,查阅很多资料,发现很多需要安装一大推东西,又是安装,又是重启,最后还是没有搞定.最后还是通过这三行命令搞定了.sudo apt-get autoremove op ...