Repository navigation
Expand file tree
/
Copy pathfluentd-matomo-config.yaml
More file actions
73 lines (68 loc) · 2.12 KB
/
Copy pathfluentd-matomo-config.yaml
File metadata and controls
73 lines (68 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
apiVersion: v1
kind: ConfigMap
metadata:
name: fluentd-matomo-config
namespace: ogcapi
data:
fluent.conf: |
<source>
@type tail
path /var/log/nginx/access.log
pos_file /var/log/fluentd-pos/nginx.pos
tag nginx.access
<parse>
@type nginx
</parse>
</source>
# Drop traffic that should not be Matomo pageviews
<filter nginx.access>
@type grep
<exclude>
key code
pattern /^[45]\d\d$/
</exclude>
<exclude>
key path
pattern /(\/tiles\/|[?&]offset=)/
</exclude>
<exclude>
key agent
pattern /(meta-webindexer|OWSLib|python-requests|bot|crawler|spider)/i
</exclude>
</filter>
<filter nginx.access>
@type record_transformer
enable_ruby true
renew_record true
keep_keys path
<record>
qs ${"idsite=#{URI.encode_www_form_component(ENV['MATOMO_SITE_ID'].to_s)}&rec=1&apiv=1&action_name=Nginx%20Log&url=#{URI.encode_www_form_component('https://ogcapi.dgterritorio.gov.pt' + record['path'].to_s)}&cip=#{URI.encode_www_form_component(record['remote'].to_s)}&ua=#{URI.encode_www_form_component(record['agent'].to_s)}&cdt=#{URI.encode_www_form_component(Time.at(time.to_i).utc.strftime('%Y-%m-%d %H:%M:%S'))}&token_auth=#{URI.encode_www_form_component(ENV['MATOMO_TOKEN'].to_s)}"}
</record>
</filter>
<match nginx.access>
@type http
endpoint "#{ENV['MATOMO_URL'].to_s.chomp('/')}/matomo.php"
http_method post
content_type application/x-www-form-urlencoded
open_timeout 10
read_timeout 30
retryable_response_codes [429, 500, 502, 503, 504]
<format>
@type single_value
message_key qs
add_newline false
</format>
<buffer>
@type memory
chunk_limit_records 1
flush_mode immediate
flush_thread_count 4
total_limit_size 128MB
queued_chunks_limit_size 20000
overflow_action drop_oldest_chunk
retry_type exponential_backoff
retry_wait 2s
retry_max_interval 30s
retry_timeout 30m
</buffer>
</match>