如何让 nginx 日志显示在 prometheus 中?
How to get nginx logs to display in prometheus?
我在随机端口 http://localhost:32774 上有一个 nginx docker 映像 运行
我在 http://localhost:9090/ 上也有一张普罗米修斯 docker 图片 运行
我想在我的 prometheus 上看到我的 nginx 日志
我已经在我的 nginx 容器上设置了 nginx_status,当我卷曲时
当我在容器
中时,我能够同时看到 Nginx 页面和 http://localhost/nginx_status 页面
我可以查看http://localhost:9090/graph --Prometheus
我可以在本地浏览器上查看 http://localhost:32774 --- nginx
我无法查看 http://localhost:32774/nginx_status -- 403 禁止访问
nginxexporter 背后的想法是什么我在 localhost:9113
上将其作为容器 运行
我的目标是在 Prometheus 上显示 nginx 日志
这是我的 default.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
allow ::1;
deny all;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
奇怪,prometheus是用来监控的,不是日志,nginx exporter是不导出日志的,它只导出监控指标,比如请求数,请求时间,返回码等。
奇怪的是,您可以在没有自定义端口的情况下使用本地主机访问 nginx...但这可以解释错误。
首先,prometheus 用于度量标准,而不是日志记录。对于日志记录,您可以结合使用 ElasticSearch 和 Logstash and/or Filebeat。
nginx_exporter从nginx的状态api读取数据。因此,nginx exporter 必须有权访问此 api 处于活动状态的 nginx 端口。在大多数 'how-to' 情况下,这是端口 8080,但是它是可配置的。
https://github.com/nginxinc/nginx-prometheus-exporter
看一下这些示例,其中 -nginx.scrape-uri
是 url / 到 nginx api 的路径和端口。
https://docs.nginx.com/nginx/admin-guide/monitoring/live-activity-monitoring/#configuring-the-api
看看这里设置你的 api,你必须为此添加或更改一些 nginx 配置。
您也可以像这样创建一个服务器块来启用 nginx api.:
server {
listen <fill_in_the_ip_of_your_server>:8080;
location /api {
api;
allow all;
###
# change the 'allow all' if the server block doesn't have any access limitations and is accessible to
# the world. You won't give the world access to your nginx data.
# allow takes multiple types of data, the most popular and built-in one is a simple IP in CIDR notation (IP + subnet in bits (192.168.1.1/16 for example will give all addresses in 192.168.x.x. access to this api. /24 will do 192.168.1.x and /32 will fix that specified address only to access that specific server or 'location' block.
###
}
}
之后,您必须在 prometheus 中添加 'scrape' 端点。普罗米修斯有时称之为 'targets'。请记住,nginx-exporter 的 docker 图像必须能够访问 nginx(-plus) 实例 api 并且 prometheus 机器应该能够访问 nginx-exporter 指标页面: 9113/指标。您可以更改 nginx 导出器的端口,但如果此端口尚未在导出器所在的 IP 上使用,则不需要。
还要记住,如果你在 docker 中的端口 运行 之外的另一个端口上启用你的 api,你应该终止容器并使用 `- 添加端口映射p- 首先,否则此端口仅在 docker 容器内处于活动状态,但从未暴露给其主机...在这种情况下可能是您的服务器或计算机。
祝你好运!
Prometheus 是一个收集和处理指标的系统,而不是一个事件日志系统。
https://prometheus.io/docs/introduction/faq/#how-to-feed-logs-into-prometheus?
您可以设置 fluentd -> ES -> Grafana
以可视化日志。
nginx_exporter 仅检索 nginx 统计信息并导出。
我们开始使用这个导出器
https://github.com/martin-helmich/prometheus-nginxlog-exporter
持续读取 NGINX 日志文件(或任何类型的类似日志文件)并将指标导出到 Prometheus 的帮助工具。
我在随机端口 http://localhost:32774 上有一个 nginx docker 映像 运行 我在 http://localhost:9090/ 上也有一张普罗米修斯 docker 图片 运行 我想在我的 prometheus 上看到我的 nginx 日志
我已经在我的 nginx 容器上设置了 nginx_status,当我卷曲时 当我在容器
中时,我能够同时看到 Nginx 页面和 http://localhost/nginx_status 页面我可以查看http://localhost:9090/graph --Prometheus 我可以在本地浏览器上查看 http://localhost:32774 --- nginx 我无法查看 http://localhost:32774/nginx_status -- 403 禁止访问 nginxexporter 背后的想法是什么我在 localhost:9113
上将其作为容器 运行我的目标是在 Prometheus 上显示 nginx 日志
这是我的 default.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
allow ::1;
deny all;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
奇怪,prometheus是用来监控的,不是日志,nginx exporter是不导出日志的,它只导出监控指标,比如请求数,请求时间,返回码等。
奇怪的是,您可以在没有自定义端口的情况下使用本地主机访问 nginx...但这可以解释错误。
首先,prometheus 用于度量标准,而不是日志记录。对于日志记录,您可以结合使用 ElasticSearch 和 Logstash and/or Filebeat。
nginx_exporter从nginx的状态api读取数据。因此,nginx exporter 必须有权访问此 api 处于活动状态的 nginx 端口。在大多数 'how-to' 情况下,这是端口 8080,但是它是可配置的。
https://github.com/nginxinc/nginx-prometheus-exporter
看一下这些示例,其中 -nginx.scrape-uri
是 url / 到 nginx api 的路径和端口。
https://docs.nginx.com/nginx/admin-guide/monitoring/live-activity-monitoring/#configuring-the-api 看看这里设置你的 api,你必须为此添加或更改一些 nginx 配置。
您也可以像这样创建一个服务器块来启用 nginx api.:
server {
listen <fill_in_the_ip_of_your_server>:8080;
location /api {
api;
allow all;
###
# change the 'allow all' if the server block doesn't have any access limitations and is accessible to
# the world. You won't give the world access to your nginx data.
# allow takes multiple types of data, the most popular and built-in one is a simple IP in CIDR notation (IP + subnet in bits (192.168.1.1/16 for example will give all addresses in 192.168.x.x. access to this api. /24 will do 192.168.1.x and /32 will fix that specified address only to access that specific server or 'location' block.
###
}
}
之后,您必须在 prometheus 中添加 'scrape' 端点。普罗米修斯有时称之为 'targets'。请记住,nginx-exporter 的 docker 图像必须能够访问 nginx(-plus) 实例 api 并且 prometheus 机器应该能够访问 nginx-exporter 指标页面: 9113/指标。您可以更改 nginx 导出器的端口,但如果此端口尚未在导出器所在的 IP 上使用,则不需要。
还要记住,如果你在 docker 中的端口 运行 之外的另一个端口上启用你的 api,你应该终止容器并使用 `- 添加端口映射p- 首先,否则此端口仅在 docker 容器内处于活动状态,但从未暴露给其主机...在这种情况下可能是您的服务器或计算机。
祝你好运!
Prometheus 是一个收集和处理指标的系统,而不是一个事件日志系统。
https://prometheus.io/docs/introduction/faq/#how-to-feed-logs-into-prometheus?
您可以设置 fluentd -> ES -> Grafana
以可视化日志。
nginx_exporter 仅检索 nginx 统计信息并导出。
我们开始使用这个导出器 https://github.com/martin-helmich/prometheus-nginxlog-exporter 持续读取 NGINX 日志文件(或任何类型的类似日志文件)并将指标导出到 Prometheus 的帮助工具。