如果它是实际的,我想编写我自己的配置。它基于tail telegraf插件。
- 将特殊日志格式添加到 http 部分
log_format codes_combined 'code=$status ts=$time_iso8601';
- 在服务器部分使用此格式
access_log /var/log/nginx/codes.log codes_combined;
- 编辑 /etc/telegraf/telegraf.conf:
[[inputs.tail]]
files = ["/var/log/nginx/codes.log"]
data_format = "logfmt"
- 重启 nginx 后,电报数据应该可以在 Graphana 中使用。我配置了一个新图表
SELECT count("code") as code_2xx FROM "tail" WHERE $timeFilter AND code >= 200 AND code < 300 AND code <> 204 GROUP BY time($__interval)
SELECT count("code") as code_3xx FROM "tail" WHERE $timeFilter AND code >= 300 AND code < 400 GROUP BY time($__interval)
SELECT count("code") as code_4xx FROM "tail" WHERE $timeFilter AND code >= 400 AND code < 500 GROUP BY time($__interval)
SELECT count("code") as code_5xx FROM "tail" WHERE $timeFilter AND code >= 500 GROUP BY time($__interval)
SELECT count("code") as code_204 FROM "tail" WHERE $timeFilter AND code = 204 GROUP BY time($__interval)
- 不要伪造检查/etc/logrotate.d/nginx。权限应该是这样的:
create 0644 www-data adm