- Centralized query execution
- Target DB group management
- Flexible metric definition
go build .
./query-exporter \
--threads=8 \
--bind="0.0.0.0:9104" \
--config-database="config-database.yml" \
--config-metrics="config-metrics.yml"
export LOG_LEVEL="debug"
./query-exporter \
--threads=8 \
--bind="0.0.0.0:9104" \
--config-database="config-database.yml" \
--config-metrics="config-metrics.yml"
prod:
prod01:
type: mysql
dsn: test:test123@tcp(127.0.0.1:3306)/information_schema
prod02:
type: mysql
dsn: test:test123@tcp(127.0.0.1:3306)/information_schema
dev:
dev01:
type: mysql
dsn: test:test123@tcp(127.0.0.1:3306)/information_schema
postgres:
pg01:
type: postgres
dsn: postgres://test:test12@localhost/postgres?sslmode=disable
- MySQL https://github.com/go-sql-driver/mysql
- Postgres https://github.com/lib/pq
- SQLite (not support) https://github.com/mattn/go-sqlite3
- MS-SQL (not support) https://github.com/denisenkom/go-mssqldb
metric01:
targets: ["prod"]
collects:
- query: "select user,
substring_index(host, ':', 1) host,
db,
command,
count(*) sessions,
min(time) min_time,
max(time) max_time
from information_schema.processlist
group by 1,2,3,4"
timeout: 1
metrics:
process_count:
type: gauge
description: Session count
labels: ["user","host", "db", "command"]
value: "sessions"
process_session_min_time:
type: gauge
description: Session count
labels: ["user","host", "db", "command"]
value: "min_time"
process_session_max_time:
type: gauge
description: Session count
labels: ["user","host", "db", "command"]
value: "max_time"
- query: "select count(*) cnt from information_schema.innodb_trx"
metrics:
innodb_trx_count:
type: gauge
description: innodb current trx count
labels: []
value: "cnt"
metric02:
targets: ["dev"]
collects:
- query: "select user,
substring_index(host, ':', 1) host,
db,
command,
count(*) sessions,
min(time) min_time,
max(time) min_time
from information_schema.processlist
group by 1,2,3,4"
timeout: 2
metrics:
process_count:
type: gauge
description: Session count
labels: ["user","host", "db", "command"]
value: "sessions"
process_session_min_time:
type: gauge
description: Session count
labels: ["user","host", "db", "command"]
value: "min_time"
process_session_max_time:
type: gauge
description: Session count
labels: ["user","host", "db", "command"]
value: "max_time"
metric03:
targets: ["postgres"]
collects:
- query: "select usename, count(*) sessions
from pg_stat_activity
group by 1"
timeout: 1
metrics:
session_count:
type: gauge
description: Session count
labels: ["usename"]
value: "sessions"
You can check with this url
curl 127.0.0.1:9104/metric01
curl 127.0.0.1:9104/metric02
curl 127.0.0.1:9104/metric03