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. Http 编码格式简介

    Http 格式简介 Http 是用于在客户端和服务端之间进行通信的一种消息格式,一般由以下几个部分组成: 起始行:这部分在 Http 响应中也被称为状态行,针对不同的 Http 类型,其中包含的内容也 ...

  2. 华为云Classroom聚焦人才数字化转型,引领智慧教育改革新模式

    随着教育行业数字化转型进程加快,利用现代化云端技术手段,线上线下相结合方式建立的全新OMO产教融合一体化已成为行业趋势.华为云Classroom平台沉淀了华为多年研发实践经验和多种前沿技术,以赋能伙伴 ...

  3. LiteOS内核源码分析:动态内存之Bestfit分配算法

    摘要:本文为大家剖析LiteOS动态内存模块bestfit算法的源代码,包含动态内存的结构体.动态内存池初始化.动态内存申请.释放等. 内存管理模块管理系统的内存资源,它是操作系统的核心模块之一,主要 ...

  4. 云小课 | 大数据融合分析:GaussDW(DWS)轻松导入MRS-Hive数据源

    摘要:通过建立GaussDB(DWS)与MRS的连接,支持数据仓库服务SQL on Hadoop,以外表方式实现Hive数据的快捷导入,满足大数据融合分析的应用场景. 本文分享自华为云社区<[云 ...

  5. CNCF Serverless工作流社区携手华为云FunctionGraph,开拓Serverless编排新时代

    摘要:华为云以CNCF Serverless Workflow 规范为标准,联合2012实验室华为元戎团队共同打造了华为云FunctionGraph Workflow,为用户提供函数流管理功能,并支持 ...

  6. Solon2 开发之插件,一、插件

    Solon Plugin 是框架的核心接口,简称"插件".其本质是一个"生命周期"接口.它可让一个组件类参与程序的生命周期过程(这块看下:<应用启动过程与 ...

  7. 基于AIO架构smarthttp开发的完整MVC框架

    基于AIO架构smarthttp开发的完整MVC框架 写了篇<基于jdk自带httpserver开发的最小完整MVC框架>,就再写篇AIO的MVC DEMO启动时间:0.1s(应该算少的吧 ...

  8. 高性能 Jsonpath 框架,Snack3 v3.2.44 发布

    Snack3,一个高性能的 JsonPath 框架 借鉴了 Javascript 所有变量由 var 申明,及 Xml dom 一切都是 Node 的设计.其下一切数据都以ONode表示,ONode也 ...

  9. 使用 FHE 实现加密大语言模型

    近来,大语言模型 (LLM) 已被证明是提高编程.内容生成.文本分析.网络搜索及远程学习等诸多领域生产力的可靠工具. 大语言模型对用户隐私的影响 尽管 LLM 很有吸引力,但如何保护好 输入给这些模型 ...

  10. 【Vue day01】前端发展介绍 Vue的快速使用 插值语法 指令系统之文本指令、事件指令、属性指令

    目录 前端发展介绍 Vue框架入门 M-V-VM思想(重要) 组件化开发 单页面应用 Vue的快速使用 前期准备 快速使用 对象与标签绑定 查看Vue对象 插值语法 三目运算符 指令系统之文本指令 v ...