Merge branch 'promtail-nginx' of kazu634/itamae into master
This commit is contained in:
commit
7d4efdd8e7
|
@ -0,0 +1,12 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Grafana Promtail (nginx)
|
||||||
|
Documentation=https://github.com/grafana/loki
|
||||||
|
After=network-online.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
User=root
|
||||||
|
Restart=always
|
||||||
|
ExecStart=/usr/local/bin/promtail --config.file=/etc/promtail/nginx.yaml
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
|
@ -68,3 +68,26 @@ end
|
||||||
service 'nginx' do
|
service 'nginx' do
|
||||||
action [ :enable, :start ]
|
action [ :enable, :start ]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Deploy `promtail` config file:
|
||||||
|
HOSTNAME = run_command('uname -n').stdout.chomp
|
||||||
|
|
||||||
|
template '/etc/promtail/nginx.yaml' do
|
||||||
|
owner 'root'
|
||||||
|
group 'root'
|
||||||
|
mode '644'
|
||||||
|
|
||||||
|
variables(HOSTNAME: HOSTNAME, LOKIENDPOINT: node['promtail']['lokiendpoint'])
|
||||||
|
end
|
||||||
|
|
||||||
|
# Deploy the `systemd` configuration:
|
||||||
|
remote_file '/lib/systemd/system/promtail-nginx.service' do
|
||||||
|
owner 'root'
|
||||||
|
group 'root'
|
||||||
|
mode '644'
|
||||||
|
end
|
||||||
|
|
||||||
|
# Service setting:
|
||||||
|
service 'promtail-nginx' do
|
||||||
|
action [ :enable, :restart ]
|
||||||
|
end
|
||||||
|
|
|
@ -0,0 +1,79 @@
|
||||||
|
server:
|
||||||
|
disable: true
|
||||||
|
|
||||||
|
positions:
|
||||||
|
filename: /var/opt/promtail/promtail_nginx_position.yaml
|
||||||
|
|
||||||
|
clients:
|
||||||
|
- url: http://<%= @LOKIENDPOINT %>/loki/api/v1/push
|
||||||
|
|
||||||
|
|
||||||
|
scrape_configs:
|
||||||
|
- job_name: nginx-access
|
||||||
|
static_configs:
|
||||||
|
- targets:
|
||||||
|
- localhost
|
||||||
|
labels:
|
||||||
|
job: nginx
|
||||||
|
hostname: <%= @HOSTNAME %>
|
||||||
|
__path__: /var/log/nginx/*access.log
|
||||||
|
|
||||||
|
pipeline_stages:
|
||||||
|
- match:
|
||||||
|
selector: '{job="nginx"}'
|
||||||
|
stages:
|
||||||
|
- regex:
|
||||||
|
expression: "^time:(?P<timestamp>[^\t]+)\thost:(?P<host>[^\t]+)\tforwardedfor:(?P<forwardedfor>[^\t]+)\tmethod:(?P<method>[^\t]+)\tpath:(?P<path>[^\t]+)\tprotocol:(?P<protocol>[^\t]+)\tstatus:(?P<status>[^\t]+)\tsize:(?P<size>[^\t]+)\treferer:(?P<referer>[^\t]+)\tua:(?P<ua>[^\t]+)\ttaken_sec:(?P<taken_sec>[^\t]+)\tbackend:(?P<backend>[^\t]+)\tbackend_status:(?P<backend_status>[^\t]+)\tcache:(?P<cache>[^\t]+)\tbackend_runtime:(?P<backend_runtime>[^\t]+)\tvhost:(?P<vhost>[^\t]+)$"
|
||||||
|
|
||||||
|
- timestamp:
|
||||||
|
source: timestamp
|
||||||
|
format: 02/Jan/2006:15:04:05 -0700
|
||||||
|
|
||||||
|
- template:
|
||||||
|
source: level
|
||||||
|
template: '{{ .status }}'
|
||||||
|
|
||||||
|
- template:
|
||||||
|
source: level
|
||||||
|
template: '{{ regexReplaceAllLiteral "(2|3)[0-9]+" .Value "info" }}'
|
||||||
|
|
||||||
|
- template:
|
||||||
|
source: level
|
||||||
|
template: '{{ regexReplaceAllLiteral "4[0-9]+" .Value "warning" }}'
|
||||||
|
|
||||||
|
- template:
|
||||||
|
source: level
|
||||||
|
template: '{{ regexReplaceAllLiteral "5[0-9]+" .Value "error" }}'
|
||||||
|
|
||||||
|
- labels:
|
||||||
|
hostname:
|
||||||
|
level:
|
||||||
|
vhost:
|
||||||
|
|
||||||
|
- job_name: nginx-error
|
||||||
|
static_configs:
|
||||||
|
- targets:
|
||||||
|
- localhost
|
||||||
|
labels:
|
||||||
|
job: nginx
|
||||||
|
hostname: <%= @HOSTNAME %>
|
||||||
|
level: error
|
||||||
|
__path__: /var/log/nginx/*error.log
|
||||||
|
|
||||||
|
pipeline_stages:
|
||||||
|
- match:
|
||||||
|
selector: '{job="nginx"}'
|
||||||
|
stages:
|
||||||
|
- regex:
|
||||||
|
expression: '^(?P<timestamp>[0-9\/]+ [0-9:]+) \[(?P<level>[^ ]+)\] (?P<message>.+), host: "(?P<vhost>[^"]+)"(?P<rest>.*)$'
|
||||||
|
|
||||||
|
- timestamp:
|
||||||
|
source: timestamp
|
||||||
|
format: 2006/01/02 15:04:05
|
||||||
|
location: Asia/Tokyo
|
||||||
|
|
||||||
|
- labels:
|
||||||
|
vhost:
|
||||||
|
|
||||||
|
- output:
|
||||||
|
source: message
|
Loading…
Reference in New Issue