Prometheus各类中间件的监控接入

目录

前言

一、zookeeper

1、zk monitor

2、zookeeper-exporter

二、elasticsearch

elasticsearch-exporter

三、MySQL

mysql-exporter

四、Redis

redis_exporter

五、Nacos

六、KAFKA

kafka_exporter

七、Doris/starrocks

八、MongoDB

mongodb_exporter

前言

注:

1、本文不详细介绍每一步安装部署方法,了解启动方法和部分参数介绍便可自己任意在服务器上部署程序配置系统服务或者在容器上部署;

2、文中提到下载的exporter基本均为压缩包,我们需要的事解压后的可执行文件,其下载解压等等中间过程就省略了。

一、zookeeper

1、zk monitor

注:zookeeper-3.6.0版本后已自带ZK Monitor,无需部署zookeeper-exporter,通过zoo.cfg中配置metrics相关端口即可开始使用,如:

# metrics
metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
metricsProvider.httpHost=0.0.0.0
metricsProvider.httpPort=7000
metricsProvider.exportJvmInfo=true
# prometheus接入http://ip:7000即可采集

2、zookeeper-exporter

下载地址:https://github.com/dabealu/zookeeper-exporter/

Usage of ./zookeeper-exporter:
  -listen string
    	address to listen on (default "0.0.0.0:9141")
  -location string
    	metrics location (default "/metrics")
  -timeout int
    	timeout for connection to zk servers, in seconds (default 30)
  -zk-hosts string
    	comma separated list of zk servers, e.g. '10.0.0.1:2181,10.0.0.2:2181,10.0.0.3:2181'
  -zk-tls-auth
    	zk tls client authentication
  -zk-tls-auth-cert string
    	cert for zk tls client authentication
  -zk-tls-auth-key string
    	key for zk tls client authentication

启动命令简述:

zookeeper-exporter -zk-hosts '10.0.0.1:port,10.0.0.2:port'

一个集群起一个zookeeper-exporter很合理

zookeeper-exporter默认的Web端口为:9141,即 prometheus配置文件中target 

- job_name: My-zookeeper
  static_configs:
  - targets:
    - 192.168.1.1:9141

后续prometheus配置添加没有特殊说明的基本同上 

二、elasticsearch

elasticsearch-exporter

下载地址:https://github.com/prometheus-community/elasticsearch_exporter

 较新的版本与旧版本的启动参数已经有了一些变化,需要根据自己实际elasticsearch_exporter --help查看或者github中的文档介绍

## 常用参数说明:
--es.uri             默认http://localhost:9200,连接到的Elasticsearch节点的地址(可通过ES的配置文件查看http.port来确认自己的端口)
--es.all                默认flase,如果为true,则查询群集中所有节点的统计信息,而不仅仅是查询我们连接到的节点。
--collector.clustersettings(旧版本的--es.cluster_settings)   默认flase,如果为true,在统计信息中查询集群设置
--es.indices            默认flase,如果为true,则查询统计信息以获取集群中的所有索引。
--es.indices_settings   默认flase,如果为true,则查询集群中所有索引的设置统计信息。
--es.shards             默认flase,如果为true,则查询集群中所有索引的统计信息,包括分片级统计信息(意味着es.indices = true)。
--collector.snapshots(旧版本的--es.snapshots) 默认flase,如果为true,则查询集群快照的统计信息。
--es.timeout 采集信息的超时时间,默认5s(集中较大,建议时间设置大一点)
--es.ssl-skip-verify 跳过连接ES的SSL认证
#执行示例
elasticsearch_exporter --es.all  --collector.clustersettings --es.indices_settings --es.shards --collector.snapshots  --es.timeout=15s --es.ssl-skip-verify --es.uri http://user:passwd@192.168.1.1:9200
#关于user passwd
当ES未设置访问密码时(即未配置x-pack认证) --es.uri http://192.168.1.1:9200
注:如果passwd中有特殊符号需进行URL转换(如@ #等)

elastic_exporter的默认Web端口为:9114, 注意zookeeper是9141

三、MySQL

mysql-exporter

下载地址:https://github.com/prometheus/mysqld_exporter

 要使用mysql_exporter,MySQL必须给一个exporter能查询相关信息权限的用户

CREATE USER 'exporter'@'localhost' IDENTIFIED BY 'your_password';  
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost';  
FLUSH PRIVILEGES;
#生产环境建议做好权限最小化,测试环境root可进行连接测试
#执行命令
mysqld_exporter --config.my-cnf=/etc/mysqld_exporter/mysqld_exporter.cnf

#mysqld_exporter.cnf文件内容示例
[client]
user=exporter
password=123456
port=3306

mysql_exporter默认Web端口为:9104

四、Redis

redis_exporter

以Redis集群为例,其只需要部署一个redis_exporter即可

下载地址:https://github.com/oliver006/redis_exporter

支持Redis:2.*-7.*版本

#执行代码
redis_exporter -redis.password-file=/etc/redis_exporter/redis_exporter.json
#其中redis_exporter.json是存放redis集群节点和密码的JSON文件
#如:
{
    "redis://192.168.1.1:6379":"123%qaz",
    "redis://192.168.1.2:6379":"123%qaz",
    "redis://192.168.1.1:6380":"456%qaz",
    "redis://192.168.1.2:6380":"456%qaz"
}

在prometheus添加redis的targets时需要注意按如下形式: 

  - job_name: 'My-Redis'
    static_configs:
      - targets:
        - redis://192.168.1.1:6379
        - redis://192.168.1.1:6380
        - redis://192.168.1.1:6379
        - redis://192.168.1.1:6380
    metrics_path: /scrape
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: '192.168.1.1:9121'

Redis_exporter默认Web端口为9121,当我们在192.168.1.1上部署完exporter后,熟悉的可能会直接看一下http://192.168.1.1:9121/metrics检查状态,会发现redis_up为0,此时是正常的

五、Nacos

1、Nacos会主动暴露metrics,无需额外部署采集器 

2、仅需确认Nacos的配置文件application.properties中如下配置已启用(未注释):

management.endpoints.web.exposure.include=*

#prometheus配置采集
- job_name: My-Nacos
  metrics_path: /nacos/actuator/prometheus
  static_configs:
  - targets:
    - 192.168.1.1:8848
    - 192.168.1.2:8848
#targets访问地址 http://192.168.1.1:8848/nacos/actuator/prometheus

六、KAFKA

kafka_exporter

下载地址:https://github.com/danielqsj/kafka_exporter

 kafka_exporter采集指标配置部署相对简单,一个集群仅需要一个ip:port即可,如:

#如192.168.1.1-3是一个kafka集群,则启动配置可为
kafka_exporter --kafka.server=192.168.1.1:9092 #仅写一个ip:port即可

七、Doris/starrocks

Doris也是自带相应功能,其指标可适配prometheus,其FE指标端口为8030,BE为8040,只需要在Doris部署环境上查看是否有数据就行

curl http://localhost:8030/metrics

#prometheus.yml添加配置如下
  - job_name: "My-Doris"
    metrics_path: '/metrics'
    static_configs:
      - targets:
        - 192.168.1.1:8030
        - 192.168.1.1:8030
        labels:
          group: fe
      - targets:
        - 192.168.1.1:8040
        - 192.168.1.1:8040
        labels:
          group: be

八、MongoDB

mongodb_exporter

下载地址:https://github.com/percona/mongodb_exporter

MongoDB作为数据库也是需要有相关权限的用户供mongodb_exporter访问,其需要权限为readAnyDatabase,集群需要额外权限clusterMonitor 

# mongodb admin 库执行
db.createUser({ user: 'exporter',pwd : 'exporter',roles:[{role: 'readAnyDatabase',db : admin},{role: 'clusterMonitor',db : admin},{role: 'read',db : local}]})
#启动
mongodb_exporter --mongodb.uri=mongodb://exporter:exporter@192.168.1.1:17001/admin --collect.database --collect.collection --collect.topmetrics  --collect.indexusage  --collect.connpoolstats --suppress.collectshardingstatus  
#
      --collect.database       Enable collection of Database metrics
      --collect.collection     Enable collection of Collection metrics
      --collect.topmetrics     Enable collection of table top metrics
      --collect.indexusage     Enable collection of per index usage stats
      --collect.connpoolstats  Collect MongoDB connpoolstats
      --suppress.collectshardingstatus  
                               Suppress the collection of Sharding Status
      --mongodb.uri=[mongodb://][user:pass@]host1[:port1][,host2[:port2],...][/database][?options]  
                               MongoDB URI, format
      --test                   Check MongoDB connection, print buildInfo() information and exit.
      --version                Show application version.
      --log.level="info"       Only log messages with the given severity or above. Valid levels: [debug, info, warn, error, fatal]

--mongodb.collstats-colls receives a list of databases and collections to monitor using collstats. Usage example:
--mongodb.collstats-colls=database1.collection1,database2.collection2
#有多个库时:
--mongodb.uri=mongodb://user:passwd@127.0.0.1:27017/admin,mongodb://user2:pass2@127.0.0.1:27018/admin

mongodb_exporter默认Web端口为9216

注:在实际生产使用中,应注意密码的管理,直接nohup通过进程可查看到密码,应该通过系统服务或者环境变量或者其他加密方式来减少密码的暴露

  • 14
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值