标签:down curl 内容 pac oca pre ogr mil 文件路径
本文以tomcat 的access log 为例
步骤简单
wget https://github.com/google/mtail/releases/download/v3.0.0-rc35/mtail_v3.0.0-rc35_linux_amd64
mv mtail_v3.0.0-rc35_linux_amd64 mtail
chmod 0755 mtail
cp -a mtail /usr/local/bin/
mtail --version
mkdir -p /etc/mtail
cd /etc/mtail/
touch /etc/mtail/line_count.mtail ##要求必须以此格式结尾
拷贝下面的内容到新建的文件/etc/mtail/line_count.mtail
# Parser for the common apache log format as follow.
# LogFormat "%h %l %u %t \"%r\" %>s %b %D \"%{Referer}i\" \"%{User-agent}i\"
counter apache_http_requests_total by request_method, http_version, status_code
counter apache_http_bytes_total by request_method, http_version, status_code
gauge apache_http_response_time by remote_host, request_method, request_uri, status_code
gauge apache_http_response_size by remote_host, request_method, request_uri, status_code
histogram apache_http_request_time_millseconds_bucket buckets 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000, 15000 by status_code
/^/ +
/(?P<remote_host>[0-9A-Za-z\.:-]+) / + # %h
/(?P<remote_logname>[0-9A-Za-z-]+) / + # %l
/(?P<remote_username>[0-9A-Za-z-]+) / + # %u
/\[(?P<timestamp>\d{2}\/\w{3}\/\d{4}:\d{2}:\d{2}:\d{2} (\+|-)\d{4})\] / + # %u
/"(?P<request_method>[A-Z]+) (?P<request_uri>\S+) (?P<http_version>HTTP\/[0-9\.]+)" / + # \"%r\"
/(?P<status_code>\d{3}) / + # %>s
/((?P<response_size>\d+)|-) / + # %b
/(?P<response_time>\d+) / + # %D
/"(?P<referer>\S+)" / + # \"%{Referer}i\"
/"(?P<user_agent>[[:print:]]+)"/ + # \"%{User-agent}i\"
/$/ {
strptime($timestamp, "02/Jan/2006:15:04:05 -0700") # for tests
apache_http_requests_total[$request_method][$http_version][$status_code]++
$response_size > 0 {
apache_http_bytes_total[$request_method][$http_version][$status_code] += $response_size
apache_http_response_size[$remote_host][$request_method][$request_uri][$status_code] += $response_size
}
apache_http_response_time[$remote_host][$request_method][$request_uri][$status_code] = $response_time
#apache_http_request_time_seconds_bucket[$remote_host][$request_method][$request_uri][$status_code] = $response_time / 1000
apache_http_request_time_millseconds_bucket[$status_code] = $response_time
}
getfilename() !~ /localhost_access_log.?txt/ {
stop
}
pattern="%h %l %u %t "%r" %s %b %D "%{Referer}i" "%{User-Agent}i"" />
采集到的日志如图
此步不用说了吧 都会的
mtail --progs /etc/mtail --logs ‘/opt/testtomcat/logs/localhost_access_log.*.txt‘ --logtostderr -v
--logs 表示你要采集的文件
--progs 表示你的mtail配置文件路径
默认端口3903
curl -s http://127.0.0.1:3903|less
需要访问一下你的tomcat 才有新的日志被采集
不然没有数据
访问效果
搜索一下apache 就能看到你想要的指标了
mtail 需要访问才有采集动作
还有几个坑的问题参考我的博客mtail 调式吧
标签:down curl 内容 pac oca pre ogr mil 文件路径
原文地址:https://www.cnblogs.com/muzhifei/p/13109763.html