62、Prometheus-远端存储-Influxdb部署
1、基础知识
1.1、官方文档
https://docs.influxdata.com/influxdb/v1.8/supported_protocols/prometh
1.2、需求
需把要prometheus数据存到其他远程服务器上
2、Influxdb部署
2.1、配置yum源
cat <<EOF | sudo tee /etc/yum.repos.d/influxdb.repo [influxdb] name = InfluxDB Repository - RHEL \$releasever baseurl = https://repos.influxdata.com/rhel/\$releasever/\$basearch/stable enabled = 1 gpgcheck = 0 EOF
2.2、安装Influxdb
yum install influxdb -y
2.3、启动Influxdb服务
2.3.1、启动
systemctl start influxdb
systemctl enable influxdb
2.3.2、查询运行状态
]# netstat -tunlp | grep influxd tcp 0 0 127.0.0.1:8088 0.0.0.0:* LISTEN 29082/influxd tcp6 0 0 :::8086 :::* LISTEN 29082/influxd
2.4、创建 prometheus 数据库
]# influx Connected to http://localhost:8086 version 1.8.10 InfluxDB shell version: 1.8.10 > create database prometheus; > show databases; name: databases name ---- _internal prometheus
2.5、修改prometheus启动脚本
2.5.1、创建存放的数据的目录
mkdir -p /usr/local/prometheus/data
2.5.2、修改prometheus.service
]# cat /usr/lib/systemd/system/prometheus.service [Unit] Description=prometheus server project After=network.target [Service] Type=simple ExecStart=/data/server/prometheus/bin/prometheus \ --config.file=/data/server/prometheus/etc/prometheus.yml \ --storage.tsdb.path=/usr/local/prometheus/data # 修改这里的数据目录 Restart=on-failure [Install] WantedBy=multi-user.target
# 修改服务脚本,需要重新加载一下
systemctl daemon-reload
2.6、配置 prometheus.yaml【添加远程读写】
2.6.1、配置
]# vi /data/server/prometheus/etc/prometheus.yml scrape_configs: - job_name: "prometheus" static_configs: - targets: ["localhost:9090"] remote_write: - url: "http://192.168.10.34:8086/api/v1/prom/write?db=prometheus" remote_read: - url: "http://192.168.10.34:8086/api/v1/prom/read?db=prometheus"
2.6.2、检查语法
]# promtool check config /data/server/prometheus/etc/prometheus.yml Checking /data/server/prometheus/etc/prometheus.yml SUCCESS: 1 rule files found SUCCESS: /data/server/prometheus/etc/prometheus.yml is valid prometheus config file syntax Checking /data/server/prometheus/rules/metrics_request_rules.yaml SUCCESS: 2 rules found
2.6.3、重启prometheus服务
systemctl restart prometheus
2.7、登陆Influxdb查询
2.7.1、登陆数据库
]# influx Connected to http://localhost:8086 version 1.8.10 InfluxDB shell version: 1.8.10 > use prometheus Using database prometheus
2.7.2、查询监控项
> show measurements
...
promhttp_metric_handler_requests_total
scrape_duration_seconds
scrape_samples_post_metric_relabeling
scrape_samples_scraped
scrape_series_added
up
2.7.3、查询监控的数据
> select * from prometheus_http_requests_total limit 5; name: prometheus_http_requests_total time __name__ code handler instance job value ---- -------- ---- ------- -------- --- ----- 1681271646440000000 prometheus_http_requests_total 200 /metrics localhost:9090 prometheus 1 1681271661440000000 prometheus_http_requests_total 200 /metrics localhost:9090 prometheus 2 1681271676440000000 prometheus_http_requests_total 200 /metrics localhost:9090 prometheus 3 1681271691440000000 prometheus_http_requests_total 200 /metrics localhost:9090 prometheus 4 1681271706440000000 prometheus_http_requests_total 200 /metrics localhost:9090 prometheus 5
2.8、数据库已经变更成功
]# ll /usr/local/prometheus/data/ 总用量 20 drwxr-xr-x 2 root root 6 4月 12 11:53 chunks_head -rw-r--r-- 1 root root 0 4月 12 11:53 lock -rw-r--r-- 1 root root 20001 4月 12 11:57 queries.active drwxr-xr-x 2 root root 22 4月 12 11:53 wal