telegraf
监控mysql
参考:
https://cloud.tencent.com/developer/article/1758937
https://blog.csdn.net/an1090239782/article/details/102986488
一. 数据库开启远程连接权限
https://gegewu12.github.io/2023/05/16/mysql-mariadb%E9%85%8D%E7%BD%AE%E8%BF%9C%E7%A8%8B%E8%BF%9E%E6%8E%A5/
创建远程连接用户
1 2 3 4
| # 创建远程连接用户 GRANT SELECT, PROCESS, SUPER, REPLICATION CLIENT, RELOAD ON *.* TO 'exporter'@'%' IDENTIFIED BY 'exporterpw'; # 刷新 flush privileges;
|
注释bind=127.0.0.1
(vim /etc/mysql/mysql.conf.d/mysqld.cnf
)
二. 构建telegraf
容器
文件位于leancould
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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
| version: "3.0" services: telegraf-py: image: registry.cn-hangzhou.aliyuncs.com/zznn/mycentos:telegraf_oracle-py restart: always container_name: telegraf-py hostname: telegraf environment: TZ: Asia/Shanghai ports: - 9273:9273 volumes: - ./telegraf.conf:/opt/telegraf-1.20.4/etc/telegraf/telegraf.conf command: /opt/telegraf-1.20.4/usr/bin/telegraf --config /opt/telegraf-1.20.4/etc/telegraf/telegraf.conf --config-directory /opt/telegraf-1.20.4/etc/telegraf/telegraf.d networks: - tpng
mysql_exporter: image: prom/mysqld-exporter:v0.12.1 restart: unless-stopped container_name: mysql_exporter hostname: mysql_exporter environment: TZ: Asia/Shanghai DATA_SOURCE_NAME: "exporter:exporterpw@(10.0.0.131:3306)/" ports: - 9104:9104 networks: - tpng
prometheus: image: prom/prometheus:latest restart: always container_name: prometheus hostname: prometheus environment: TZ: Asia/Shanghai ports: - 9090:9090 user: root volumes: - ./prometheus.yml:/etc/prometheus/prometheus.yml - ./data/monitor/prometheus:/prometheus/data:rw command: - "--config.file=/etc/prometheus/prometheus.yml" - "--storage.tsdb.path=/prometheus" - "--storage.tsdb.retention.time=15d" networks: - tpng
grafana: image: grafana/grafana:7.0.4 container_name: grafana hostname: grafana restart: unless-stopped ports: - 3000:3000 user: root volumes: - ./grafana.ini:/etc/grafana/grafana.ini - ./data/monitor/grafana:/var/lib/grafana:rw environment: GF_SECURITY_ADMIN_PASSWORD: "admin" GF_USERS_ALLOW_SIGN_UP: "false" TZ: Asia/Shanghai GF_RENDERING_SERVER_URL: http://renderer:8081/render GF_RENDERING_CALLBACK_URL: http://grafana:3000/ GF_LOG_FILTERS: rendering:debug networks: - tpng
renderer: image: grafana/grafana-image-renderer:2.0.0 restart: always ports: - "8081:8081" environment: - GF_RENDERER_PLUGIN_TZ=Asia/Shanghai - GF_RENDERER_PLUGIN_IGNORE_HTTPS_ERRORS=true networks: - tpng
networks: tpng: driver: bridge
|
三. telegraf
配置文件
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
| [agent]
interval = "60s" flush_interval = "60s" round_interval = true metric_batch_size = 1000 metric_buffer_limit = 10000 collection_jitter = "0s" flush_jitter = "0s" precision = "" hostname = "10.0.0.131" omit_hostname = false
[[inputs.mysql]] interval = "5m" servers = ["exporter:exporterpw@(10.0.0.131:3306)/"] perf_events_statements_digest_text_limit = 120 perf_events_statements_limit = 250 perf_events_statements_time_limit = 86400 table_schema_databases = [""] gather_table_schema = false gather_process_list = true gather_info_schema_auto_inc = true gather_slave_status = true gather_binary_logs = false gather_table_io_waits = false gather_table_lock_waits = false gather_index_io_waits = false gather_event_waits = false gather_file_events_stats = false interval_slow = "30m"
[[outputs.prometheus_client]]
listen = ":9273" metric_version = 2 path="/metrics" string_as_label = true export_timestamp = true
|
关键配置项
四. 效果