Prometheus 数据采集
官方仓库
https://github.com/prometheus
Prometheus 本体
https://github.com/prometheus/prometheus
探针
https://github.com/prometheus/node_exporter
通过可执行文件安装部署
下载地址
https://github.com/prometheus/node_exporter/releases/
示例
- 下载 + 安装
wget https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz
tar -zxvf node_exporter-1.3.1.linux-amd64.tar.gz
cd node_exporter-1.3.1.linux-amd64
sudo install -t /usr/local/bin node_exporter
- 添加服务配置文件
/etc/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
# 端口号自定
ExecStart=/usr/local/bin/node_exporter --web.listen-address=:63002
Restart=on-failure
[Install]
WantedBy=multi-user.target
- 加载并启动服务 + 开启自启
sudo systemctl daemon-reload
sudo systemctl enable node_exporter
sudo systemctl start node_exporter
通过 docker 部署
命令行
docker run -d -p 9100:9100 -v "/:/host:ro,rslave" quay.io/prometheus/node-exporter --path.rootfs /host
docker-compose / portainer
version: '3.3'
services:
hadoop2:
ports:
- '61000:9100'
volumes:
- '/:/host:ro,rslave'
image: quay.io/prometheus/node-exporter
command: --path.rootfs /host
grafana 监控面板
https://github.com/grafana/grafana
安全相关
https://blog.csdn.net/qq_31977125/article/details/108528488
https://zhuanlan.zhihu.com/p/144048025
basic 认证
htpasswd 生成 token
ubuntu
sudo apt-get install apache2-utils
centos
yum -y install httpd
# 如果提示 No package httpd available 则
yum --disableexcludes=all install -y httpd
生成
htpasswd -nBC 12 '' | tr -d ':\n'
node_exporter
启动参数添加 --web.config=./config.yml
示例:
admin 123456
basic_auth_users:
admin: $2y$12$mMnPuKlOQ97ff4NjDsQTMukAtRS/ILpjxjEQrCN0vefs0CBLe/hi6
prometheus
启动参数添加 --web.config=./config.yml
示例:
admin 123456
basic_auth_users:
admin: $2y$12$mMnPuKlOQ97ff4NjDsQTMukAtRS/ILpjxjEQrCN0vefs0CBLe/hi6
/etc/prometheus/prometheus.yml
global:
scrape_interval: 60s
evaluation_interval: 60s
scrape_configs:
- job_name: prometheus
static_configs:
- targets: ['127.0.0.1:63000']
labels:
instance: prometheus
- job_name: node_exporter
basic_auth:
username: admin
password: 123456
static_configs:
- targets:
- '127.0.0.1:63002'
grafana 监控面板
https://grafana.com/zh-cn/grafana/
官方提供的面板市场
https://grafana.com/grafana/dashboards
node_exporter 面板
https://grafana.com/grafana/dashboards/8919
kafka 面板
https://grafana.com/grafana/dashboards/21078
elasticsearch 面板
https://grafana.com/grafana/dashboards/2322
mysql 面板
https://grafana.com/grafana/dashboards/17320-1-mysqld-exporter-dashboard/
redis 面板
https://grafana.com/grafana/dashboards/17507-1-redis-exporter-dashboard/
通过 portainer 部署 所有程序
prometheus 核心程序
version: '3.3'
networks:
default:
driver: bridge
services:
prometheus:
network_mode: "host"
container_name: prometheus
volumes:
- '/opt/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml'
- '/opt/node_exporter/config.yml:/etc/prometheus/web-config.yml'
image: prom/prometheus
command: --web.enable-lifecycle --config.file=/etc/prometheus/prometheus.yml --web.config.file=/etc/prometheus/web-config.yml --web.listen-address=:63000
grafana:
user: "root"
ports:
- '63001:3000'
container_name: grafana
volumes:
- '/opt/grafana:/var/lib/grafana'
image: grafana/grafana
networks:
- default
node_exporter:
ports:
- '63002:9100'
volumes:
- '/:/host:ro,rslave'
- '/opt/node_exporter/config.yml:/config.yml'
image: quay.io/prometheus/node-exporter
command: --path.rootfs /host --web.config.file=/config.yml
networks:
- default
完整示例 (包含 prometheus 核心程序 和 kafka , es 等 exporter)
配置文件
/opt/prometheus/node_exporter/config.yml
# admin 123456
basic_auth_users:
admin: $2y$12$mMnPuKlOQ97ff4NjDsQTMukAtRS/ILpjxjEQrCN0vefs0CBLe/hi6
/opt/prometheus/prometheus/config.yml
# admin 123456
basic_auth_users:
admin: $2y$12$mMnPuKlOQ97ff4NjDsQTMukAtRS/ILpjxjEQrCN0vefs0CBLe/hi6
/opt/prometheus/prometheus/prometheus.yml
global:
scrape_interval: 60s
evaluation_interval: 60s
scrape_configs:
# prometheus 本体
- job_name: prometheus
static_configs:
- targets: ['127.0.0.1:63000']
labels:
instance: prometheus
# 主机 exporter
- job_name: node_exporter
basic_auth:
username: admin
password: 123456
static_configs:
- targets:
- '127.0.0.1:63002'
# es exporter
- job_name: elasticsearch_exporter
static_configs:
- targets:
- '127.0.0.1:63003'
# kafka exporter
- job_name: kafka_exporter
static_configs:
- targets:
- '127.0.0.1:63004'
- job_name: mysqld_exporter
static_configs:
- targets:
- '127.0.0.1:63005'
mysqld_exporter 配置
/opt/prometheus/mysqld_exporter/config.cnf
[client]
host = ip
port = 端口
user = 用户名
password = 密码
docker-compose / portainer 部署
version: '3.3'
x-common: &x-common
logging:
driver: json-file #仅在 json-file 驱动程序下,可以使用以下参数,限制日志得数量和大小。
options:
max-size: "200m" # 单个文件大小为200m
max-file: "3" # 最多1个文件
networks:
default:
driver: bridge
services:
prometheus:
<<: *x-common
network_mode: "host"
container_name: prometheus
volumes:
- '/opt/prometheus/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml'
- '/opt/prometheus/prometheus/config.yml:/etc/prometheus/web-config.yml'
image: prom/prometheus:v3.1.0
command: --web.enable-lifecycle --config.file=/etc/prometheus/prometheus.yml --web.config.file=/etc/prometheus/web-config.yml --web.listen-address=:63000
grafana:
<<: *x-common
user: "root"
ports:
- '63001:3000'
container_name: grafana
volumes:
- '/opt/prometheus/grafana:/var/lib/grafana'
image: grafana/grafana:11.4.0
networks:
- default
node_exporter:
<<: *x-common
ports:
- '63002:9100'
volumes:
- '/:/host:ro,rslave'
- '/opt/prometheus/node_exporter/config.yml:/config.yml'
image: quay.io/prometheus/node-exporter:v1.8.2
command: --path.rootfs /host --web.config.file=/config.yml
networks:
- default
elasticsearch_exporter:
<<: *x-common
image: quay.io/prometheuscommunity/elasticsearch-exporter:v1.8.0
command:
- '--es.uri=http://10.10.10.200:9200'
- '--es.all'
- '--es.indices'
restart: always
ports:
- "63003:9114"
networks:
- default
kafka-exporter:
<<: *x-common
image: danielqsj/kafka-exporter:v1.8.0
command: ["--kafka.server=10.10.10.200:9194", "--kafka.server=10.10.10.200:9294", "--kafka.server=10.10.10.200:9394"]
ports:
- 63004:9308
networks:
- default
mysqld-exporter:
ports:
- 63005:9104
networks:
- default
image: prom/mysqld-exporter:v0.16.0
volumes:
- /opt/prometheus/mysqld_exporter/config.cnf:/config.cnf
command: --config.my-cnf=/config.cnf
redis-exporter:
<<: *x-common
ports:
- 63006:9121
networks:
- default
image: oliver006/redis_exporter:v1.67.0
command: --redis.addr="redis://10.10.10.200:6379" --redis.password="12341234"
grafana
默认账号
admin / admin
推荐面板
https://grafana.com/grafana/dashboards
可到 grafana 官网挑选 或者直接 导入下面的 id 到 grafana 面板中
名称 | ID |
---|---|
node_exporter 面板 | 8919 |
kafka_exporter 面板 | 21078 |
elasticsearch_exporter 面板 | 2322 |