Skip to content

Commit 7f3367a

Browse files
committed
add promtail snippet to README
Signed-off-by: Vitaly Zhuravlev <[email protected]>
1 parent 1cd457c commit 7f3367a

File tree

1 file changed

+37
-7
lines changed

1 file changed

+37
-7
lines changed

mysqld-mixin/README.md

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ for Grafana:
3636
$ make build
3737
```
3838

39-
### Loki Logs configuration
40-
41-
For proper logs correlation, you need to make sure that `job` and `instance` labels values match for both mysql_exporter metrics and logs, collected by promtail or grafana agent.
39+
## Loki Logs configuration
4240

4341
To enable logs support in MySQLd mixin, enable them in config.libsonnet first:
4442

@@ -56,7 +54,39 @@ then run
5654
$ make build
5755
```
5856

59-
This would generate mysql logs dashboard, as well as modified mysql overview dashboard.
60-
61-
For more advanced uses of mixins, see
62-
https://github.com/monitoring-mixins/docs.
57+
This would generate MySQL logs dashboard, as well as modified MySQL overview dashboard.
58+
59+
For proper logs correlation, you need to make sure that `job` and `instance` labels values match for both mysql_exporter metrics and logs, collected by [Promtail](https://grafana.com/docs/loki/latest/clients/promtail/) or [Grafana Agent](https://grafana.com/docs/grafana-cloud/agent/).
60+
61+
To scrape MySQL logs the following promtail config snippet can be used for `job=integrations/mysql` and `instance=mysql-01`:
62+
63+
```yaml
64+
scrape_configs:
65+
- job_name: integrations/mysql
66+
static_configs:
67+
- labels:
68+
instance: mysql-01 # must match instance used in mysqld_exporter
69+
job: integrations/mysql # must match job used in mysqld_exporter
70+
__path__: /var/log/mysql/*.log
71+
pipeline_stages:
72+
-
73+
# logs of mysql in sample-apps https://dev.mysql.com/doc/refman/8.0/en/error-log-format.html
74+
# format time thread [label] [err_code] [subsystem] msg
75+
# The [err_code] and [subsystem] fields were added in MySQL 8.0
76+
# https://regex101.com/r/jwEke3/2
77+
regex:
78+
expression: '(?P<timestamp>.+) (?P<thread>[\d]+) \[(?P<label>.+?)\]( \[(?P<err_code>.+?)\] \[(?P<subsystem>.+?)\])? (?P<msg>.+)'
79+
- labels:
80+
label:
81+
err_code:
82+
subsystem:
83+
# (optional) uncomment parse timestamp, but make sure you set the proper location to parse timezone
84+
#- timestamp:
85+
# source: timestamp
86+
# fallback_formats: ["2006-01-02 15:04:05"]
87+
# format: "2006-01-02T15:04:05.000000Z"
88+
# location: Etc/UTC
89+
- drop:
90+
expression: "^ *$"
91+
drop_counter_reason: "drop empty lines"
92+
```

0 commit comments

Comments
 (0)