til
til copied to clipboard
Giảm số lượng metric trong exporter và Prometheus
Nếu nhà giàu, thì chẳng có gì phải suy nghĩ, thừa còn hơn thiếu, nên thường sẽ expose tất cả metric mà exporter đó support.
Tuy nhiên nếu có bài toán optimize cho lượng traffic/data khổng lồ, thì cũng có 1 bài toán ngược lại khó ko kém là làm sao xài được trên một system siêu bé (bởi ta phải optimize về chi phí, chứ ko phải lúc nào cũng đủ tiền quăng 1 cục server bự được)
node_exporter
Với node_exporter
thì xài 2 command line flags sau:
-
--web.disable-exporter-metrics
-> Tắt hết mấy metricgo_*
vàhttp_*
, được tí nào hay tí đó -
--collector.disable-defaults
-> Tắt tất cả các collector và chỉ bật cái nào cần (cơ bản là CPU, Meminfo, Filesystem, Disk ...)
Đại khái như sau:
{{ ansible_managed | comment }}
ARGS="--web.listen-address={{ private_ip | default('127.0.0.1') }}:9101 \
--web.config=/etc/node_exporter/web-config.yml \
--web.disable-exporter-metrics \
--collector.disable-defaults \
--collector.filesystem.ignored-mount-points='^/(sys|proc|dev)($|/)' \
{% if groups.gh_prod_mysql %}
--collector.diskstats \
{% endif %}
--collector.filesystem \
--collector.loadavg \
--collector.meminfo \
--collector.mountstats \
--collector.netstat \
--collector.ntp \
--collector.cpu"
Kết quả giảm từ 1568
- 432
, cũng đc khá nhiều, chi tiết check README của node_exporter
mysqld_exporter
Nghía thử metric cũng hơi hoảng hồn
> curl -sSL 1.2.3.4:9104/metrics | wc -l
28496
Dẫu biết cũng chẳng đáng là bao so với các anh đại gia nhưng nhà có sổ hộ nghèo thì đúng là ăn tàn phá hại. Nghía qua docs của mysqld_exporter
thì ko thấy có mấy command line flags để tắt metric như node_exporter
, có vẻn vẹn mấy dòng https://github.com/prometheus/mysqld_exporter#filtering-enabled-collectors, đại khái cấu hình ở phía scrape_config
Prometheus
params:
collect[]:
- foo
- bar
Đúng là đánh đố nhau, lò mò một hồi ra cái PR này https://github.com/prometheus/mysqld_exporter/pull/235/files, chả hiểu sao mấy anh lại xoá đoạn này trong README
scrape_configs:
- job_name: 'mysql global status'
scrape_interval: 15s
static_configs:
- targets:
- '192.168.1.2:9104'
params:
collect[]:
- global_status
- job_name: 'mysql performance'
scrape_interval: 1m
static_configs:
- targets:
- '192.168.1.2:9104'
params:
collect[]:
- perf_schema.tableiowaits
- perf_schema.indexiowaits
- perf_schema.tablelocks
Chỗ này có 2 điểm cần chú ý:
- Vẫn xài
params: collect[]
để filter đầu prometheus các metric cần giữ - Tách các nhóm metric và
scrape_interval
với các giá trị khác nhau, ví dụglobal_status
thì 15s lấy 1 lần nhưngperf_schema
thì ko cần lấy nhiều thế, 1 phút 1 lần là đc.
Ngoài ra, lướt issue có anh này còn đề nghị bỏ hết mấy cái #HELP
và #TYPE
ra khỏi response để tiết kiệm băng thông https://github.com/prometheus/node_exporter/issues/2066, nhưng anh SuperQ bảo http compress sẵn rồi không cần, nhưng nghĩ cũng thú, vì nhiều ông cloud provider còn tính bw của user cơ, tất nhiên public nhưng thiếu gì kiểu chế cháo khác.
Túm
Với 565 con servers bằng hạt dẻ (bé nhất trong các loại bé) (multi tenant services)
node_exporter
- Cũ:
1568 * 565 = 885_920
trên interval 15s - Mới:
432 * 565 = 244_080
Giảm đc 73% số metrics.
mysqld_exporter
thì vài con (m/s/d) thôi, chưa test, chưa biết