单主机运行3个Nginx,Telegraf多实例监控配置求助
单主机多Nginx实例的Telegraf监控配置方案
以下是适配3个Nginx实例的完整Telegraf配置,已添加标签区分不同实例,避免数据混淆:
# nginx-metrics and logs # 第一个Nginx实例监控 [[inputs.nginx]] urls = ["https://example.com/nginx_status"] response_timeout = "5s" tags = ["instance=example1"] [[inputs.tail]] name_override = "nginxlog" files = ["/var/www/example/logs/http-access.log"] from_beginning = false pipe = false data_format = "grok" grok_patterns = ["%{COMBINED_LOG_FORMAT}"] tags = ["instance=example1"] [[inputs.exec]] commands = [ "sh /etc/telegraf/nginx_stats.sh" ] timeout = "5s" name_override = "nginx_response_code" data_format = "json" tag_keys = ["resp_code"] tags = ["instance=example1"] # 第二个Nginx实例监控 [[inputs.nginx]] urls = ["https://example2.com/nginx_status"] # 替换为第二个Nginx的status端点 response_timeout = "5s" tags = ["instance=example2"] [[inputs.tail]] name_override = "nginxlog" files = ["/var/www/example2/logs/http-access.log"] from_beginning = false pipe = false data_format = "grok" grok_patterns = ["%{COMBINED_LOG_FORMAT}"] tags = ["instance=example2"] [[inputs.exec]] commands = [ "sh /etc/telegraf/nginx_stats2.sh" ] timeout = "5s" name_override = "nginx_response_code" data_format = "json" tag_keys = ["resp_code"] tags = ["instance=example2"] # 第三个Nginx实例监控 [[inputs.nginx]] urls = ["https://example3.com/nginx_status"] # 替换为第三个Nginx的status端点 response_timeout = "5s" tags = ["instance=example3"] [[inputs.tail]] name_override = "nginxlog" files = ["/var/www/example3/logs/http-access.log"] from_beginning = false pipe = false data_format = "grok" grok_patterns = ["%{COMBINED_LOG_FORMAT}"] tags = ["instance=example3"] [[inputs.exec]] commands = [ "sh /etc/telegraf/nginx_stats3.sh" ] timeout = "5s" name_override = "nginx_response_code" data_format = "json" tag_keys = ["resp_code"] tags = ["instance=example3"] [[outputs.prometheus_client]] listen = "0.0.0.0:9125"
关键配置说明
- 实例区分:每个输入块添加
tags = ["instance=xxx"]字段,确保Prometheus中能识别不同Nginx实例的监控数据 - 端点验证:确认每个Nginx的
nginx_status端点可正常访问,若为HTTP协议则替换对应URL - 脚本匹配:保证
nginx_stats*.sh脚本分别统计对应Nginx的响应码数据,输出格式需为标准JSON - 配置生效:修改配置后重启Telegraf服务:
sudo systemctl restart telegraf
内容的提问来源于stack exchange,提问作者user3796291
相关产品推荐
相关产品推荐

