各中间件的exporter监控对接到prometheus
各中间件exporter对接到prometheus的方式
监控原理:使用prometheus监控各类中间件,则需要部署对应中间件的exporter,再将exporter暴露的指标地址告知prometheus即可
首先我们需要知道如何将暴露的地址告知prometheus,主要有如下集中方式:
- 修改prometheus配置文件的方式
- 修改静态文件的方式
- 使用httpd方式
- 使用注册中心的方式
这里只提到修改prometheus配置文件的方式和静态文件的方式(其他方式可以阅读prometheus的官网)
修改prometheus配置文件如下内容:
1 | scrape_configs: |
而这些静态配置文件的格式如下:这里以node_exporter.json为例
1 | [ |
以上将部署的exporter服务告知prometheus的配置方式,配置好后,重启prometheus即可。
部署各类中间件的exporter
Mysql-exporter
- 部署启动 首先填写mysql相关的配置,保存在 my.cnf文件中 然后,启动mysql-exporter,并通过config.my-cnf指定上面的配置文件
1
2
3
4
5[client]
host=127.0.0.1
port=3306
user=exporter
password=1234561
2
3
4
5# 默认参数启动
./mysqld_exporter --config.my-cnf=/usr/local/prometheus/mysqld_exporter-0.12.1.linux-amd64/my.cnf
# 详细的参数
./mysqld_exporter --web.listen-address=0.0.0.0:9104 --config.my-cnf=/usr/local/prometheus/mysqld_exporter-0.12.1.linux-amd64/my.cnf --collect.slave_status --collect.slave_hosts --log.level=error --collect.info_schema.processlist --collect.info_schema.innodb_metrics --collect.info_schema.innodb_tablespaces --collect.info_schema.innodb_cmp --collect.info_schema.innodb_cmpmem
redis-exporter
部署启动
1 | ./redis_exporter -redis.addr 127.0.0.1:6379 -redis.password 123456 -web.listen-address 0.0.0.0:9121 |
nginx-prometheus-exporter
前提条件
使用nginx-prometheus-exporter监控nginx时,该nginx必须要开启stub_status功能
开启 NGINX stub_status 功能
- 开源 Nginx 提供一个简单页面用于展示状态数据,该页面由 tub_status 模块提供。执行以下命令检查 Nginx 是否已经开启了该模块:
1
nginx -V 2>&1 | grep -o with-http_stub_status_module
- 如果在终端中输出
with-http_stub_status_module
,则说明 Nginx 已启用 tub_status 模块。 - 如果未输出任何结果,则可以使用
-with-http_stub_status_module
参数从源码重新配置编译一个 Nginx。示例如下:1
2
3
4
5./configure \
… \
--with-http_stub_status_module
make
sudo make install
- 如果在终端中输出
- 确认 stub_status 模块启用之后,修改 Nginx 的配置文件指定 status 页面的 URL。示例如下:
1
2
3
4
5
6
7
8
9server {
location /nginx_status {
stub_status;
access_log off;
allow 127.0.0.1;
deny all;
}
} - 检查并重新加载 nginx 的配置使其生效。
1
2nginx -t
nginx -s reload - 完成上述步之后,可以通过配置的 URL 查看 Nginx 的指标:
1
2
3
4Active connections: 45
server accepts handled requests
1056958 1156958 4491319
Reading: 0 Writing: 25 Waiting : 7
部署启动
1 | nginx-prometheus-exporter -nginx.scrape-uri=http://<nginx>:8080/stub_status |
zookeeper-exporter
启动
1 | ./zookeeper_exporter -zookeeper 127.0.0.1:2181 -bind-addr :9143 |
elasticsearch-exporter
1 | ## 参数说明: |
部署启动
1 | # es集群1:10.xxx.xxx.10:9200 |
kafka-exporter
部署启动
1 | ./kafka_exporter --web.listen-address=9308 --kafka.server=kafka:9092 [--kafka.server=another-server ...] |
Grafana Dashboard ID: 7589, name: Kafka Exporter Overview.
postgresql-exporter
部署启动
1 | ./postgres_exporter <flags> |
Flags
help
Show context-sensitive help (also try –help-long and –help-man).web.listen-address
Address to listen on for web interface and telemetry. Default is:9187
.web.telemetry-path
Path under which to expose metrics. Default is/metrics
.disable-default-metrics
Use only metrics supplied fromqueries.yaml
via-extend.query-path
.disable-settings-metrics
Use the flag if you don’t want to scrapepg_settings
.auto-discover-databases
Whether to discover the databases on a server dynamically.extend.query-path
Path to a YAML file containing custom queries to run. Check out[queries.yaml](https://github.com/prometheus-community/postgres_exporter/blob/master/queries.yaml)
for examples of the format.dumpmaps
Do not run - print the internal representation of the metric maps. Useful when debugging a custom queries file.constantLabels
Labels to set in all metrics. A list oflabel=value
pairs, separated by commas.version
Show application version.exclude-databases
A list of databases to remove when autoDiscoverDatabases is enabled.include-databases
A list of databases to only include when autoDiscoverDatabases is enabled.log.level
Set logging level: one ofdebug
,info
,warn
,error
.log.format
Set the log format: one oflogfmt
,json
.web.config.file
Configuration file to use TLS and/or basic authentication. The format of the file is described in the exporter-toolkit repository.
Environment Variables
The following environment variables configure the exporter:
DATA_SOURCE_NAME
the default legacy format. Accepts URI form and key=value form arguments. The URI may contain the username and password to connect with.DATA_SOURCE_URI
an alternative toDATA_SOURCE_NAME
which exclusively accepts the hostname without a username and password component. For example,my_pg_hostname
ormy_pg_hostname?sslmode=disable
.DATA_SOURCE_URI_FILE
The same as above but reads the URI from a file.DATA_SOURCE_USER
When usingDATA_SOURCE_URI
, this environment variable is used to specify the username.DATA_SOURCE_USER_FILE
The same, but reads the username from a file.DATA_SOURCE_PASS
When usingDATA_SOURCE_URI
, this environment variable is used to specify the password to connect with.DATA_SOURCE_PASS_FILE
The same as above but reads the password from a file.PG_EXPORTER_WEB_LISTEN_ADDRESS
Address to listen on for web interface and telemetry. Default is:9187
.PG_EXPORTER_WEB_TELEMETRY_PATH
Path under which to expose metrics. Default is/metrics
.PG_EXPORTER_DISABLE_DEFAULT_METRICS
Use only metrics supplied fromqueries.yaml
. Value can betrue
orfalse
. Default isfalse
.PG_EXPORTER_DISABLE_SETTINGS_METRICS
Use the flag if you don’t want to scrapepg_settings
. Value can betrue
orfalse
. Default isfalse
.PG_EXPORTER_AUTO_DISCOVER_DATABASES
Whether to discover the databases on a server dynamically. Value can betrue
orfalse
. Default isfalse
.PG_EXPORTER_EXTEND_QUERY_PATH
Path to a YAML file containing custom queries to run. Check out[queries.yaml](https://github.com/prometheus-community/postgres_exporter/blob/master/queries.yaml)
for examples of the format.PG_EXPORTER_CONSTANT_LABELS
Labels to set in all metrics. A list oflabel=value
pairs, separated by commas.PG_EXPORTER_EXCLUDE_DATABASES
A comma-separated list of databases to remove when autoDiscoverDatabases is enabled. Default is empty string.PG_EXPORTER_INCLUDE_DATABASES
A comma-separated list of databases to only include when autoDiscoverDatabases is enabled. Default is empty string, means allow all.PG_EXPORTER_METRIC_PREFIX
A prefix to use for each of the default metrics exported by postgres-exporter. Default ispg
bind-exporter
部署启动
1 | ./bind_exporter \ |
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 牛蛙JUN!