监控ingress服务访问日志
655 字
3 分钟
监控ingress服务访问日志
1 配置 ingress ConfigMap
log-format-upstream: |- {' '"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",' '"geoip_country_code": "$geoip_city"' #注意这里,我把国家换成城市ip地址了 '}2 配置 ingress Deployment
注意配置污点,要不然就挂载 pv
kubectl edit deployment nginx-ingress-controller -n kube-system
volumeMounts: - mountPath: /etc/localtime name: localtime readOnly: true - mountPath: /var/log/access/ #gateway容器日志路径 name: access_log - mountPath: /etc/nginx/geoip/ #geoip库容器路径 name: geoip volumes: - hostPath: path: /var/log/ingress/ #gateway宿主机日志路径 type: "" name: access_log - hostPath: path: /var/app/prod-k8s/ingress_geoip2_mmdb #geoip库宿主机路径,因为ip地址不准,就不分享了 type: "" name:geoip
3 配置 gatewayingress 日志路径
在 ingress 里添加注解
apiVersion: extensions/v1beta1kind: Ingressmetadata: annotations: nginx.ingress.kubernetes.io/configuration-snippet: | access_log /var/log/access/gateway.access.log upstreaminfo if=$loggable;4 更新完会在 grafana 看到如下日志

5 导入面板
地址:下载下来导入进去

这个时候没有地图插件会报错
6 grafana 安装地图插件
grafana-cli plugins install grafana-worldmap-panel
编辑配置文件,要不然地图会空白
cd /var/lib/grafana/plugins/grafana-worldmap-panel/
sed -i 's/https:\/\/cartodb-basemaps-{s}.global.ssl.fastly.net\/dark_all\/{z}\/{x}\/{y}.png/http:\/\/{s}.basemaps.cartocdn.com\/dark_all\/{z}\/{x}\/{y}.png/' dist/module.js module.js.map
sed -i 's/https:\/\/cartodb-basemaps{s}.global.ssl.fastly.net\/light_all\/{z}\/{x}\/{y}.png/http:\/\/{s}.basemaps.cartocdn.com\/light_all\/{z}\/{x}\/{y}.png/' module.js module.js.map
7 配置坐标库
cat data/countries.json
[ { "key": "Tianjin", "latitude": 39.125595, "longitude": 117.190186, "name": "天津" }, { "key": "Beijing", "latitude": 39.904987, "longitude": 116.405289, "name": "北京" }, { "key": "Guangzhou", "latitude": 23.125177, "longitude": 113.28064, "name": "广州" }, { "key": "Shenzhen", "latitude": 22.55329, "longitude": 113.88308, "name": "深圳" }, { "key": "Hangzhou", "latitude": 30.2084, "longitude": 120.21201, "name": "杭州" }]这里我只配了五个坐标,相加城市去经纬度查询 - 坐标拾取系统搜索经纬度
{ "key": "Hangzhou", #geoip_country_code字段名称 "latitude": 30.2084, #经度 "longitude": 120.21201, #纬度 "name": "杭州" #显示名称 }重启 grafana 后会看到这样一个大盘


文章分享
如果这篇文章对你有帮助,欢迎分享给更多人!
相关文章 智能推荐
1
Nginx Ingress常用配置
🐳云原生 Nginx Ingress工作中用到的常用配置
2
OpenClaw安装
💻Linux 龙虾安装笔记
3
通过 Ngnix 日志监控
🔍监控 通过 Ngnix 日志监控
4
Prometheus监控RocketMQ
🔍监控 Prometheus监控RocketMQ
5
如何优雅的使用SkyWalking
🔍监控 如何优雅的使用SkyWalking,应用直接链路追踪
随机文章 随机推荐