提交 a3f5d458 编写于 作者: U Ulric Qin

add nginx markdown

上级 76bfb130
{
"name": "Nginx Stub",
"tags": "",
"configs": {
"version": "2.0.0",
"links": [],
"var": [
{
"name": "server",
"allOption": false,
"multi": false,
"definition": "label_values(nginx_active,server)"
}
],
"panels": [
{
"targets": [
{
"refId": "A",
"expr": "nginx_requests{server=\"$server\"}",
"legend": ""
}
],
"name": "Requests",
"links": [],
"custom": {
"textMode": "value",
"colorMode": "value",
"calc": "lastNotNull",
"colSpan": 1,
"textSize": {}
},
"options": {
"valueMappings": [
{
"type": "special",
"match": {
"special": 1
},
"result": {
"text": "UP"
}
},
{
"type": "special",
"match": {
"special": 0
},
"result": {
"text": "DOWN"
}
}
],
"standardOptions": {}
},
"version": "2.0.0",
"type": "stat",
"layout": {
"h": 7,
"w": 2,
"x": 0,
"y": 0,
"i": "f29b8521-eb9f-41d5-8a79-1e222baabf9d",
"isResizable": true
},
"id": "f29b8521-eb9f-41d5-8a79-1e222baabf9d"
},
{
"targets": [
{
"refId": "A",
"expr": "nginx_active{server=\"$server\"}",
"legend": ""
}
],
"name": "Active connections",
"links": [],
"custom": {
"textMode": "value",
"colorMode": "value",
"calc": "lastNotNull",
"colSpan": 1,
"textSize": {}
},
"options": {
"standardOptions": {}
},
"version": "2.0.0",
"type": "stat",
"layout": {
"h": 7,
"w": 6,
"x": 2,
"y": 0,
"i": "c0d3d10a-fd3b-485c-97e4-9f68ffc7a026",
"isResizable": true
},
"id": "c0d3d10a-fd3b-485c-97e4-9f68ffc7a026"
},
{
"targets": [
{
"refId": "A",
"expr": "nginx_waiting{server=\"$server\"}",
"legend": ""
}
],
"name": "Waiting connections",
"links": [],
"custom": {
"textMode": "value",
"colorMode": "value",
"calc": "lastNotNull",
"colSpan": 1,
"textSize": {}
},
"options": {
"standardOptions": {}
},
"version": "2.0.0",
"type": "stat",
"layout": {
"h": 7,
"w": 6,
"x": 8,
"y": 0,
"i": "abbce8f8-222f-4e07-9e5e-fc85e7780672",
"isResizable": true
},
"id": "abbce8f8-222f-4e07-9e5e-fc85e7780672"
},
{
"targets": [
{
"refId": "A",
"expr": "nginx_reading{server=\"$server\"}",
"legend": ""
}
],
"name": "Reading connections",
"links": [],
"custom": {
"textMode": "value",
"colorMode": "value",
"calc": "lastNotNull",
"colSpan": 1,
"textSize": {}
},
"options": {
"standardOptions": {}
},
"version": "2.0.0",
"type": "stat",
"layout": {
"h": 7,
"w": 5,
"x": 14,
"y": 0,
"i": "52f77144-19ba-4349-a7de-cedeb41ac3d7",
"isResizable": true
},
"id": "52f77144-19ba-4349-a7de-cedeb41ac3d7"
},
{
"targets": [
{
"refId": "A",
"expr": "nginx_writing{server=\"$server\"}",
"legend": ""
}
],
"name": "Writing connections",
"links": [],
"custom": {
"textMode": "value",
"colorMode": "value",
"calc": "lastNotNull",
"colSpan": 1,
"textSize": {}
},
"options": {
"standardOptions": {}
},
"version": "2.0.0",
"type": "stat",
"layout": {
"h": 7,
"w": 5,
"x": 19,
"y": 0,
"i": "4c02d0ab-7dc7-466d-a610-be5810b7a1e6",
"isResizable": true
},
"id": "4c02d0ab-7dc7-466d-a610-be5810b7a1e6"
},
{
"targets": [
{
"refId": "A",
"expr": "nginx_handled{server=\"$server\"}",
"legend": ""
}
],
"name": "handled",
"links": [],
"custom": {
"textMode": "value",
"colorMode": "value",
"calc": "lastNotNull",
"colSpan": 1,
"textSize": {}
},
"options": {
"standardOptions": {}
},
"version": "2.0.0",
"type": "stat",
"layout": {
"h": 7,
"w": 5,
"x": 0,
"y": 7,
"i": "b13dce58-7f2a-4680-a9e4-507f7d5a2af8",
"isResizable": true
},
"id": "5e837a2b-b919-4ee5-8edf-b6bb490030ff"
}
]
}
}
\ No newline at end of file
{
"name": "Nginx Upstream",
"tags": "",
"configs": {
"version": "2.0.0",
"links": [],
"var": [
{
"name": "target",
"allOption": false,
"multi": false,
"definition": "label_values(nginx_upstream_check_status_code,target)",
"reg": "/http:\\/\\//"
},
{
"name": "upstream",
"definition": "label_values(nginx_upstream_check_status_code,upstream)"
}
],
"panels": [
{
"targets": [
{
"refId": "A",
"expr": "nginx_upstream_check_status_code{target=\"$target\"}",
"legend": ""
}
],
"name": "Requests",
"links": [],
"custom": {
"textMode": "value",
"colorMode": "value",
"calc": "lastNotNull",
"colSpan": 1,
"textSize": {}
},
"options": {
"valueMappings": [
{
"type": "special",
"match": {
"special": 1
},
"result": {
"text": "UP"
}
},
{
"type": "special",
"match": {
"special": 0
},
"result": {
"text": "DOWN"
}
}
],
"standardOptions": {}
},
"version": "2.0.0",
"type": "stat",
"layout": {
"h": 7,
"w": 2,
"x": 0,
"y": 0,
"i": "f29b8521-eb9f-41d5-8a79-1e222baabf9d",
"isResizable": true
},
"id": "f29b8521-eb9f-41d5-8a79-1e222baabf9d"
},
{
"targets": [
{
"refId": "A",
"expr": "nginx_upstream_check_rise{target=\"$target\",upstream=\"$upstream\"}",
"legend": ""
}
],
"name": "Rise check",
"links": [],
"custom": {
"textMode": "value",
"colorMode": "value",
"calc": "lastNotNull",
"colSpan": 1,
"textSize": {}
},
"options": {
"standardOptions": {}
},
"version": "2.0.0",
"type": "stat",
"layout": {
"h": 7,
"w": 6,
"x": 2,
"y": 0,
"i": "c0d3d10a-fd3b-485c-97e4-9f68ffc7a026",
"isResizable": true
},
"id": "c0d3d10a-fd3b-485c-97e4-9f68ffc7a026"
},
{
"targets": [
{
"refId": "A",
"expr": "nginx_upstream_check_fall{target=\"$target\",upstream=\"$upstream\"}",
"legend": ""
}
],
"name": "Fall Check",
"links": [],
"custom": {
"textMode": "value",
"colorMode": "value",
"calc": "lastNotNull",
"colSpan": 1,
"textSize": {}
},
"options": {
"standardOptions": {}
},
"version": "2.0.0",
"type": "stat",
"layout": {
"h": 7,
"w": 6,
"x": 8,
"y": 0,
"i": "abbce8f8-222f-4e07-9e5e-fc85e7780672",
"isResizable": true
},
"id": "abbce8f8-222f-4e07-9e5e-fc85e7780672"
}
]
}
}
\ No newline at end of file
此差异已折叠。
- 该插件依赖**nginx****http_stub_status_module
# Nginx
# 应用场景
一般用于业务系统做对外或对外路由映射时使用代理服务,是运维最常见且最重要的代理工具。
Nginx 监控有多种方式,最推荐的是 vts 插件:
# 部署场景
需要在装有nginx服务的虚拟机启用此插件。
**[http_stub_status_module](https://github.com/flashcatcloud/categraf/blob/main/inputs/nginx/README.md)**
配置样例如下:
# 前置条件
```
条件1:nginx服务需要启用http_stub_status_module模块
推荐源码编译方式安装模块,如不清楚要安装哪些模块,可参考:
cd /opt/nginx-1.20.1 && ./configure \
--prefix=/usr/share/nginx \
--sbin-path=/usr/sbin/nginx \
--modules-path=/usr/lib64/nginx/modules \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--http-client-body-temp-path=/var/lib/nginx/tmp/client_body \
--http-proxy-temp-path=/var/lib/nginx/tmp/proxy \
--http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi \
--http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi \
--http-scgi-temp-path=/var/lib/nginx/tmp/scgi \
--pid-path=/var/run/nginx.pid \
--lock-path=/run/lock/subsys/nginx \
--user=nginx \
--group=nginx \
--with-compat \
--with-threads \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_mp4_module \
--with-http_random_index_module \
--with-http_realip_module \
--with-http_secure_link_module \
--with-http_slice_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_sub_module \
--with-http_v2_module \
--with-mail \
--with-mail_ssl_module \
--with-stream \
--with-stream_realip_module \
--with-stream_ssl_module \
--with-stream_ssl_preread_module \
--with-select_module \
--with-poll_module \
--with-file-aio \
--with-http_xslt_module=dynamic \
--with-http_image_filter_module=dynamic \
--with-http_perl_module=dynamic \
--with-stream=dynamic \
--with-mail=dynamic \
--with-http_xslt_module=dynamic \
--add-module=/etc/nginx/third-modules/nginx_upstream_check_module \
--add-module=/etc/nginx/third-modules/ngx_devel_kit-0.3.0 \
--add-module=/etc/nginx/third-modules/lua-nginx-module-0.10.13 \
--add-module=/etc/nginx/third-modules/nginx-module-vts \
--add-module=/etc/nginx/third-modules/ngx-fancyindex-0.5.2
# 根据cpu核数
make -j2
make install
注意:第三方模块nginx_upstream_check_module lua-nginx-module nginx-module-vts 都是相关插件所必备的依赖。
```
```
条件2:nginx启用stub_status配置。
[root@aliyun conf.d]# cat nginx.domains.com.conf
server {
listen 80;
listen 443 ssl;
server_name nginx.domains.com;
include /etc/nginx/ssl_conf/domains.com.conf;
location / {
stub_status on;
include /etc/nginx/ip_whitelist.conf;
}
access_log /var/log/nginx/nginx.domains.com.access.log main;
error_log /var/log/nginx/nginx.domains.com.error.log warn;
}
浏览器访问https://nginx.domains.com出现:
Active connections: 5
server accepts handled requests
90837 90837 79582
Reading: 0 Writing: 1 Waiting: 4
Nginx状态解释:
Active connections Nginx正处理的活动连接数5个
server Nginx启动到现在共处理了90837个连接。
accepts Nginx启动到现在共成功创建90837次握手。
handled requests Nginx总共处理了79582次请求。
Reading Nginx读取到客户端的 Header 信息数。
Writing Nginx返回给客户端的 Header 信息数。
Waiting Nginx已经处理完正在等候下一次请求指令的驻留链接,Keep-alive启用情况下,这个值等于active-(reading + writing)。
请求丢失数=(握手数-连接数)可以看出,本次状态显示没有丢失请求。
```
# 配置场景
```
本配置启用或数据定义如下功能:
增加自定义标签,可通过自定义标签筛选数据及更加精确的告警推送。
响应超时时间为5秒。
urls字段填写条件2所定义好的域名。
```
# 修改nginx.toml文件配置
```
[root@aliyun input.nginx]# cat nginx.toml
# # collect interval
# interval = 15
```toml
[[instances]]
## An array of Nginx stub_status URI to gather stats.
urls = [
"https://nginx.domains.com"
# "http://192.168.0.216:8000/nginx_status",
# "https://www.baidu.com/ngx_status"
]
## append some labels for series
labels = { cloud="my-cloud", region="my-region",azone="az1", product="my-product" }
# labels = { region="cloud", product="n9e" }
## interval = global.interval * interval_times
# interval_times = 1
......@@ -156,49 +40,68 @@ response_timeout = "5s"
# tls_key = "/etc/categraf/key.pem"
## Use TLS but skip chain & host verification
# insecure_skip_verify = false
```
# 测试配置
```
./categraf --test --inputs nginx
**[nginx_upstream_check](https://github.com/flashcatcloud/categraf/blob/main/inputs/nginx_upstream_check/README.md)**
21:46:46 nginx_waiting agent_hostname=aliyun.tjf.n9e.001 azone=az1 cloud=huaweicloud port=443 product=nginx region=huabei-beijing-4 server=nginx.devops.press 0
21:46:46 nginx_active agent_hostname=aliyun.tjf.n9e.001 azone=az1 cloud=huaweicloud port=443 product=nginx region=huabei-beijing-4 server=nginx.devops.press 1
21:46:46 nginx_accepts agent_hostname=aliyun.tjf.n9e.001 azone=az1 cloud=huaweicloud port=443 product=nginx region=huabei-beijing-4 server=nginx.devops.press 90794
21:46:46 nginx_handled agent_hostname=aliyun.tjf.n9e.001 azone=az1 cloud=huaweicloud port=443 product=nginx region=huabei-beijing-4 server=nginx.devops.press 90794
21:46:46 nginx_requests agent_hostname=aliyun.tjf.n9e.001 azone=az1 cloud=huaweicloud port=443 product=nginx region=huabei-beijing-4 server=nginx.devops.press 79458
21:46:46 nginx_reading agent_hostname=aliyun.tjf.n9e.001 azone=az1 cloud=huaweicloud port=443 product=nginx region=huabei-beijing-4 server=nginx.devops.press 0
21:46:46 nginx_writing agent_hostname=aliyun.tjf.n9e.001 azone=az1 cloud=huaweicloud port=443 product=nginx region=huabei-beijing-4 server=nginx.devops.press 1
配置样例如下:
```
# 重启服务
```
重启categraf服务生效
systemctl daemon-reload && systemctl restart categraf && systemctl status categraf
```toml
[[instances]]
targets = [
# "http://127.0.0.1/status?format=json",
# "http://10.2.3.56/status?format=json"
]
查看启动日志是否有错误
journalctl -f -n 500 -u categraf | grep "E\!" | grep "W\!"
```
# # append some labels for series
# labels = { region="cloud", product="n9e" }
# 检查数据呈现
等待1-2分钟后数据就会在图表中展示出来,如图:
![image](https://user-images.githubusercontent.com/12181410/220639442-5d02a9ec-f0ae-48f5-91f0-4c7839b747b5.png)
# # interval = global.interval * interval_times
# interval_times = 1
## Set http_proxy (categraf uses the system wide proxy settings if it's is not set)
# http_proxy = "http://localhost:8888"
# 监控告警规则配置
```
```
个人经验仅供参考:
超过2000毫秒,为P2级别,启用企业微信应用推送告警,3分钟内恢复发出恢复告警。
超过5000毫秒,为P1级别,启用电话语音告警&企业微信应用告警,3分钟内恢复发出恢复告警。
```
## Interface to use when dialing an address
# interface = "eth0"
# 监控图表配置
## HTTP Request Method
# method = "GET"
https://github.com/flashcatcloud/categraf/blob/main/inputs/nginx_vts/dashboards.json
## Set timeout (default 5 seconds)
# timeout = "5s"
# 故障自愈配置
## Whether to follow redirects from the server (defaults to false)
# follow_redirects = false
## Optional HTTP Basic Auth Credentials
# username = "username"
# password = "pa$$word"
## Optional headers
# headers = ["X-From", "categraf", "X-Xyz", "abc"]
## Optional TLS Config
# use_tls = false
# tls_ca = "/etc/categraf/ca.pem"
# tls_cert = "/etc/categraf/cert.pem"
# tls_key = "/etc/categraf/key.pem"
## Use TLS but skip chain & host verification
# insecure_skip_verify = false
```
先略过
**[nginx vts](https://github.com/flashcatcloud/categraf/blob/main/inputs/nginx_vts/README.md)**
nginx_vts 已经支持输出 prometheus 格式的数据,所以,其实已经不需要这个采集插件了,直接用 categraf 的 prometheus 采集插件,读取 nginx_vts 的 prometheus 数据即可。配置样例如下:
```toml
[[instances]]
urls = [
"http://IP:PORT/vts/format/prometheus"
]
labels = {job="nginx-vts"}
```
## 仪表盘
夜莺内置了相关仪表盘,克隆到自己的业务组即可使用。
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册