1
resposta

request_time nginx telegraf

Boa tarde a todos pessoal gostaria de monitorar o request_time no nginx mais não estou conseguindo

codigo Nginx Config

include       /etc/nginx/mime.types;                                           
    default_type  application/octet-stream;                                        

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '      
                      '$status $body_bytes_sent "$http_referer" '                  
                      '"$http_user_agent" "$http_x_forwarded_for" '
                      'rt=$request_time uct="$upstream_connect_time" uht="$upstream_header_time" urt="$upstream_response_time"';              

    access_log  /var/log/nginx/access.log  main; 

    sendfile        on;                                  

telegraf.conf

# # Stream and parse log file(s).
 [[inputs.logparser]]
#   ## Log files to parse.
#   ## These accept standard unix glob matching rules, but with the addition of
#   ## ** as a "super asterisk". ie:
#   ##   /var/log/**.log     -> recursively find all .log files in /var/log
#   ##   /var/log/*/*.log    -> find all .log files with a parent dir in /var/log
#   ##   /var/log/apache.log -> only tail the apache log file
    files = ["/var/log/nginx/access.log"]
#
#   ## Read files that currently exist from the beginning. Files that are created
#   ## while telegraf is running (and that match the "files" globs) will always
#   ## be read from the beginning.
   from_beginning = true
#
#   ## Method used to watch for file updates.  Can be either "inotify" or "poll".
#   # watch_method = "inotify"
#
#   ## Parse logstash-style "grok" patterns:
   [inputs.logparser.grok]
#     ## This is a list of patterns to check the given log file(s) for.
#     ## Note that adding patterns here increases processing time. The most
#     ## efficient configuration is to have one pattern per logparser.
#     ## Other common built-in patterns are:
#     ##   %{COMMON_LOG_FORMAT}   (plain apache & nginx access logs)
#     ##   %{COMBINED_LOG_FORMAT} (access logs + referrer & agent)
     patterns = ["%{COMBINED_LOG_FORMAT}"]
#
#     ## Name of the outputted measurement name.
     measurement = "nginx_access_log"
#
#     ## Full path(s) to custom pattern files.
#     custom_pattern_files = []
#
#     ## Custom patterns can also be defined here. Put one pattern per line.
      #custom_patterns = ''' '''
#

acces.log

10.0.0.109 - - [08/Apr/2020:15:58:23 +0000] "GET /home? HTTP/1.1" 200 14274 "http://10.0.0.108/home?" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36" "-" rt=0.249 uct="0.000" uht="0.248" urt="0.248"

resultado no influxdb. Observer que no influx não grava os indicadores rt=0.249 uct="0.000" uht="0.248" urt="0.248"

1586361503001000000 Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36                      -    10.0.0.109    mobclin 1.1          -     /var/log/nginx/access.log http://10.0.0.108/home?                                                                                                               /home?                                                                                                             14274      200       GET

no grafana eu enxergo todos os indicadores menos o indicados rt/uct/urt. O que eu realmente preciso e monitorar o Request_time do nginx

desde já eu agradeço ajuda de todos.

1 resposta

Olá William, tudo bem? Você deve utilizar um Custom patterns para poder incluir esses dados adicionais que você deseja (rt/uct/urt). A seção [inputs.logparser.grok] precisa de algo como:

[inputs.logparser.grok]
     patterns = ["%{CUSTOM_LOG_FORMAT}"]
     custom_patterns = '''
        CUSTOM_LOG_FORMAT %{CLIENT:client_ip} %{NOTSPACE:ident} %{NOTSPACE:auth} \[%{HTTPDATE:ts:ts-httpd}\]"(?:%{WORD:verb:tag} %{NOTSPACE:request}(?: HTTP/%{NUMBER:http_version:float})?|%{DATA})" %{NUMBER:resp_code:tag} (?:%{NUMBER:resp_bytes:int}|-)%{QS:referrer} %{QS:agent}%{QS:request_time} %{QS:upstream_connect_time}%{QS:geoip_city} %{QS:country_code}
      '''

Porém o mais interessante é que tem esse artigo: Total Nginx monitoring, with application performance and a bit more, using Telegraf/InfluxDB/Grafana que fala exatamente como monitorar essas métricas, bem como um monitoramento total do Nginx.

Espero ter ajudado!