Merge pull request 'loki-maintainance' (#13) from loki-maintainance into main
Reviewed-on: #13
This commit is contained in:
commit
0e8f4b35fb
|
@ -1,8 +1,21 @@
|
||||||
# -------------------------------------------
|
# -------------------------------------------
|
||||||
# Specifying the default settings:
|
# Specifying the default settings:
|
||||||
# -------------------------------------------
|
# -------------------------------------------
|
||||||
|
case run_command('grep VERSION_ID /etc/os-release | awk -F\" \'{print $2}\'').stdout.chomp
|
||||||
|
when "20.04", "22.04"
|
||||||
|
cmd = 'LANG=C ip a | grep "inet " | grep -v -E "(127|172)" | cut -d" " -f6 | perl -pe "s/\/.+//g"'
|
||||||
|
|
||||||
|
when "18.04"
|
||||||
|
cmd = 'LANG=C /sbin/ifconfig | grep "inet " | grep -v -E "(127|172)" | cut -d" " -f10'
|
||||||
|
|
||||||
|
else
|
||||||
|
cmd = 'LANG=C /sbin/ifconfig | grep "inet addr" | grep -v -E "(127|172)" | awk "{print $2;}" | cut -d: -f2 | cut -f 1 -d " " | tail -1'
|
||||||
|
end
|
||||||
|
ipaddr = run_command(cmd).stdout.chomp
|
||||||
|
|
||||||
node.reverse_merge!({
|
node.reverse_merge!({
|
||||||
'loki' => {
|
'loki' => {
|
||||||
|
'ipaddr' => ipaddr,
|
||||||
'url' => 'https://github.com/grafana/loki/releases/download/',
|
'url' => 'https://github.com/grafana/loki/releases/download/',
|
||||||
'zip' => 'loki-linux-amd64.zip',
|
'zip' => 'loki-linux-amd64.zip',
|
||||||
'storage' => '/opt/loki/',
|
'storage' => '/opt/loki/',
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
[Unit]
|
|
||||||
Description=Grafana Promtail
|
|
||||||
Documentation=https://github.com/grafana/loki
|
|
||||||
After=network-online.target
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
User=root
|
|
||||||
Restart=always
|
|
||||||
ExecStart=/usr/local/bin/promtail --config.file=/etc/promtail/loki.yaml
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
data_dir = "/var/lib/vector/"
|
||||||
|
|
||||||
|
[sources.loki]
|
||||||
|
type = "file"
|
||||||
|
include = [ "/var/log/loki.log" ]
|
||||||
|
read_from = "beginning"
|
||||||
|
|
||||||
|
[transforms.loki_transform]
|
||||||
|
type = "remap"
|
||||||
|
inputs = ["loki"]
|
||||||
|
source = '''
|
||||||
|
. |= parse_syslog!(.message)
|
||||||
|
|
||||||
|
. |= parse_key_value!(.message)
|
||||||
|
|
||||||
|
del(.message)
|
||||||
|
del(.host)
|
||||||
|
|
||||||
|
.message = .msg
|
||||||
|
del(.msg)
|
||||||
|
'''
|
||||||
|
|
||||||
|
[sinks.loki_output]
|
||||||
|
type = "file"
|
||||||
|
inputs = [ "loki_transform" ]
|
||||||
|
compression = "none"
|
||||||
|
path = "/tmp/loki-%Y-%m-%d.log"
|
||||||
|
|
||||||
|
[sinks.loki_output.encoding]
|
||||||
|
codec = "json"
|
||||||
|
|
||||||
|
[sinks.loki_output.buffer]
|
||||||
|
max_size = 268435488
|
||||||
|
type = "disk"
|
||||||
|
|
||||||
|
[sinks.loki_loki]
|
||||||
|
type = "loki"
|
||||||
|
inputs = [ "loki_transform" ]
|
||||||
|
endpoint = "http://loki.service.consul:3100"
|
||||||
|
compression = "snappy"
|
||||||
|
out_of_order_action = "accept"
|
||||||
|
|
||||||
|
[sinks.loki_loki.labels]
|
||||||
|
level = "{{ level }}"
|
||||||
|
hostname = "{{ hostname }}"
|
||||||
|
job = "loki"
|
||||||
|
filename = "/var/log/loki.log"
|
||||||
|
|
||||||
|
[sinks.loki_loki.encoding]
|
||||||
|
codec = "json"
|
||||||
|
|
||||||
|
[sinks.loki_loki.buffer]
|
||||||
|
max_size = 268435488
|
||||||
|
type = "disk"
|
|
@ -0,0 +1,16 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Vector
|
||||||
|
Documentation=https://vector.dev
|
||||||
|
After=network-online.target
|
||||||
|
Requires=network-online.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStart=/usr/bin/vector --config /etc/vector/loki.toml
|
||||||
|
ExecReload=/bin/kill -HUP $MAINPID
|
||||||
|
Restart=always
|
||||||
|
StandardOutput=journal
|
||||||
|
StandardError=journal
|
||||||
|
SyslogIdentifier=vector
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
|
@ -13,7 +13,7 @@ template '/etc/loki/loki-config.yml' do
|
||||||
group 'root'
|
group 'root'
|
||||||
mode '644'
|
mode '644'
|
||||||
|
|
||||||
variables(ipaddr: node['consul']['ipaddr'])
|
variables(ipaddr: node['loki']['ipaddr'])
|
||||||
|
|
||||||
notifies :restart, 'service[loki]'
|
notifies :restart, 'service[loki]'
|
||||||
end
|
end
|
||||||
|
@ -36,7 +36,7 @@ template '/etc/consul.d/service-loki.json' do
|
||||||
group 'consul'
|
group 'consul'
|
||||||
mode '644'
|
mode '644'
|
||||||
|
|
||||||
variables(ipaddr: node['consul']['ipaddr'])
|
variables(ipaddr: node['loki']['ipaddr'])
|
||||||
|
|
||||||
notifies :reload, 'service[consul]'
|
notifies :reload, 'service[consul]'
|
||||||
end
|
end
|
||||||
|
@ -45,31 +45,6 @@ service 'consul' do
|
||||||
action :nothing
|
action :nothing
|
||||||
end
|
end
|
||||||
|
|
||||||
# Depoy `promtail` configuration for `loki`:
|
|
||||||
HOSTNAME = run_command('uname -n').stdout.chomp
|
|
||||||
|
|
||||||
template '/etc/promtail/loki.yaml' do
|
|
||||||
owner 'root'
|
|
||||||
group 'root'
|
|
||||||
mode '644'
|
|
||||||
|
|
||||||
variables(HOSTNAME: HOSTNAME, LOKIENDPOINT: node['promtail']['lokiendpoint'])
|
|
||||||
|
|
||||||
notifies :restart, 'service[promtail-loki]'
|
|
||||||
end
|
|
||||||
|
|
||||||
# Deploy `systemd` configuration for `promtail-loki`:
|
|
||||||
remote_file '/etc/systemd/system/promtail-loki.service' do
|
|
||||||
owner 'root'
|
|
||||||
group 'root'
|
|
||||||
mode '644'
|
|
||||||
end
|
|
||||||
|
|
||||||
# Service setting:
|
|
||||||
service 'promtail-loki' do
|
|
||||||
action [ :enable, :restart ]
|
|
||||||
end
|
|
||||||
|
|
||||||
remote_file '/etc/rsyslog.d/30-loki.conf' do
|
remote_file '/etc/rsyslog.d/30-loki.conf' do
|
||||||
owner 'root'
|
owner 'root'
|
||||||
group 'root'
|
group 'root'
|
||||||
|
@ -89,6 +64,25 @@ remote_file '/etc/logrotate.d/loki' do
|
||||||
mode '644'
|
mode '644'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Deploy the config file for `vector`:
|
||||||
|
remote_file '/etc/vector/loki.toml' do
|
||||||
|
owner 'root'
|
||||||
|
group 'root'
|
||||||
|
mode '644'
|
||||||
|
end
|
||||||
|
|
||||||
|
# Deploy the `systemd` configuration:
|
||||||
|
remote_file '/lib/systemd/system/vector-loki.service' do
|
||||||
|
owner 'root'
|
||||||
|
group 'root'
|
||||||
|
mode '644'
|
||||||
|
end
|
||||||
|
|
||||||
|
# Service setting:
|
||||||
|
service 'vector-loki' do
|
||||||
|
action [ :enable, :restart ]
|
||||||
|
end
|
||||||
|
|
||||||
# Firewall settings here:
|
# Firewall settings here:
|
||||||
%w( 3100/tcp ).each do |p|
|
%w( 3100/tcp ).each do |p|
|
||||||
execute "ufw allow #{p}" do
|
execute "ufw allow #{p}" do
|
||||||
|
|
|
@ -1,43 +0,0 @@
|
||||||
server:
|
|
||||||
disable: true
|
|
||||||
|
|
||||||
positions:
|
|
||||||
filename: /var/opt/promtail/promtail_loki_position.yaml
|
|
||||||
|
|
||||||
clients:
|
|
||||||
- url: http://<%= @LOKIENDPOINT %>/loki/api/v1/push
|
|
||||||
|
|
||||||
scrape_configs:
|
|
||||||
- job_name: loki
|
|
||||||
static_configs:
|
|
||||||
- targets:
|
|
||||||
- localhost
|
|
||||||
labels:
|
|
||||||
job: loki
|
|
||||||
hostname: <%= @HOSTNAME %>
|
|
||||||
__path__: /var/log/loki.log
|
|
||||||
|
|
||||||
pipeline_stages:
|
|
||||||
- match:
|
|
||||||
selector: '{job="loki"}'
|
|
||||||
stages:
|
|
||||||
- drop:
|
|
||||||
expression: 'entry out of order'
|
|
||||||
|
|
||||||
- regex:
|
|
||||||
expression: '^[^ ]+ +[0-9]+ [0-9]+:[0-9]+:[0-9]+ [^ ]+ loki[^ ]+ .*level=(?P<level>[^ ]+) ts=(?P<timestamp>[^ ]+) (?P<message>.+)$'
|
|
||||||
|
|
||||||
- timestamp:
|
|
||||||
source: timestamp
|
|
||||||
format: 2006-01-02T15:04:05.999999999Z
|
|
||||||
location: Etc/GMT
|
|
||||||
|
|
||||||
- template:
|
|
||||||
source: level
|
|
||||||
template: '{{ regexReplaceAllLiteral "warn" .Value "warning" }}'
|
|
||||||
|
|
||||||
- labels:
|
|
||||||
level:
|
|
||||||
|
|
||||||
- output:
|
|
||||||
source: message
|
|
Loading…
Reference in New Issue