K8s 下通过prometheus监控 nginx
k8s 下有两个版本的nginx ingress 分别是
ingress nginx 以及 nginx ingress
Ingress-nginx 与 Nginx-ingress - LeoZhanggg - 博客园
这里我讨论的是 nginx ingress
Nginx Ingress 使用Prometheus 导出数据
nginx ingress 本身支持通过支持这个提供prometheus 格式的 metrics 供prometheus 抓取, 需要配置 -enable-prometheus-metrics。 如果需要响应时间则需要单独配置 -enable-latency-metrics.
Prometheus | NGINX Ingress Controller
遇到的bug
一开始看上面的教程 在deployment 中设置好参数之后,发现没有latency 相关的内容。 一看 nginx 的log 就发现了
2024/11/23 10:33:36 [alert] 44#44: connect() failed (13: Permission denied) while logging to syslog, server: unix:/var/lib/nginx/nginx-syslog.sock
2024/11/23 10:33:36 [alert] 46#46: connect() failed (13: Permission denied) while logging to syslog, server: unix:/var/lib/nginx/nginx-syslog.sock
2024/11/23 10:33:36 [warn] 46#46: *20 send() to syslog failed while logging request, client: 192.168.65.6, server: example.api.com, request: "OPTIONS /Auth/GetUserDetail HTTP/1.1", upstream: "http://10.1.1.143:5036/Auth/GetUserDetail", host: "example.api.com:30080", referrer: "http://example.itpp.com:30080/"
2024/11/23 10:33:36 [warn] 44#44: *16 send() to syslog failed while logging request, client: 192.168.65.6, server: example.api.com, request: "OPTIONS /Auth/GetUserDetail HTTP/1.1", upstream: "http://10.1.1.143:5036/Auth/GetUserDetail", host: "example.api.com:30080", referrer: "http://example.itpp.com:30080/"
因为 nginx 读取响应时间延迟是通过首先记录API到 syslog 再通过读取syslog 产生 metrics。 如果不做特殊配置的话,虽然nginx 能够运行起来但是实际上是没有配置好 syslog 的 需要配置相关 configmap 来指定好 nginx.conf 里面 syslog 相关
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-config
data:
nginx.conf: |
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
error_log syslog:server=unix:/var/lib/nginx/nginx-syslog.sock debug;
access_log syslog:server=unix:/var/lib/nginx/nginx-syslog.sock combined;
server {
listen 8080;
location /stub_status {
stub_status;
allow 127.0.0.1;
allow 10.0.0.0/8;
deny all;
}
location / {
root /usr/share/nginx/html;
index index.html;
}
}
}
这样卸载 再重新安装就没有问题了。
原文地址:https://blog.csdn.net/weixin_38990443/article/details/144004647
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!