文章目录
自定义资源接入
Prometheus使用各种Exporter来监控资源。Exporter可以看成是监控的agent端,它负责收集对应资源的指标,并提供接口给到Prometheus读取
虚机数据抓取
配置安装node-exporter
docker run -d -p 9100:9100 \
-v "/proc:/host/proc" \
-v "/sys:/host/sys" \
-v "/:/rootfs" \
-v "/etc/localtime:/etc/localtime" \
docker.m.daocloud.io/prom/node-exporter \
--path.procfs /host/proc \
--path.sysfs /host/sys \
--collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)"
验证数据收集
curl localhost:9100/metrics
配置prometheus-config.yaml
- job_name: 'other-ECS'
static_configs:
- targets: ['11.0.1.91:9100']
labels:
hostname: 'test-node-exporter'
热加载
$ curl -XPOST http://prometheus.kubernets.cn/-/reload
process-exporter进程监控
创建挂载目录
$ mkdir -p /opt/process-exporter/config
配置安装process-exporter
$ docker run -itd --rm -p 9256:9256 --privileged -v /proc:/host/proc -v /opt/process-exporter/config:/config docker.m.daocloud.io/ncabatoff/process-exporter --procfs /host/proc -config.path config/process-exporter.yml
配置文件
匹配 sd-api 的进程
(ps -ef | grep sd-api)
通过process-exporter的网页去查看监控的数据
, 包含:namedprocess_namegroup_num_procs{groupname=“map[:sd-api]”} 即代表启动正确
$ cat /opt/process-exporter/config/process-exporter.yml
process_names:
- name: "{{.Matches}}"
cmdline:
- 'sd-api'
测试验证
展示当前主机层面的
sd-api
这个进程有2
个
$ curl localhost:9256/metrics |grep namedprocess_namegroup_num_procs
# HELP namedprocess_namegroup_num_procs number of processes in this group
# TYPE namedprocess_namegroup_num_procs gauge
namedprocess_namegroup_num_procs{groupname="map[:sd-api]"} 2
主机层面命令测试
$ ps aux | grep -v grep | grep sd-api
修改prometheus文件
新增job
- job_name: 'process-exporter'
static_configs:
- targets: ['11.0.1.91:9256']
热加载
$ curl -XPOST http://prometheus.kubernets.cn/-/reload
自定义中间件监控
创建mysql监听用户并授权,注意服务ip不要填错
CREATE USER 'exporter'@'%' IDENTIFIED BY '123asdZXC';
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'%';
flush privileges;
启动容器
$ docker run -d --restart=always --name mysqld-exporter -p 9104:9104 -e DATA_SOURCE_NAME="exporter:123asdZXC@(11.0.1.52:3306)/" docker.m.daocloud.io/prom/mysqld-exporter
测试验证
curl localhost:9104/metrics
修改prometheus文件
新增Job
- job_name: 'mysql-exporter'
static_configs:
- targets: ['11.0.1.91:9104']
热加载
$ curl -XPOST http://prometheus.kubernets.cn/-/reload
e: ‘mysql-exporter’
static_configs:
- targets: [‘11.0.1.91:9104’]
`热加载`
```bash
$ curl -XPOST http://prometheus.kubernets.cn/-/reload