Prometheus 通过将数据远程写入InfluxDB 1.x存储
发布时间:2023-06-27 11:41:00
发布人:yyy
安装influxdb1.x
wget https://dl.influxdata.com/influxdb/releases/influxdb-1.8.0.x86_64.rpm
yum -y localinstall influxdb-1.8.0.x86_64.rpm
编辑配置文件
最终修改效果项如下所示
bind-address = "0.0.0.0:8088"
[meta]
dir = "/var/lib/influxdb/meta"
[data]
dir = "/var/lib/influxdb/data"
wal-dir = "/var/lib/influxdb/wal"
cache-max-memory-size = "8g"
series-id-set-cache-size = 100
[coordinator]
max-concurrent-queries = 0
query-timeout = "0s"
log-queries-after = "10s"
max-select-series = 0
max-select-buckets = 0
[retention]
[shard-precreation]
advance-period = "10m"
[monitor]
[http]
enabled = true
bind-address = ":8086"
log-enabled = false
max-row-limit = 10000
启动服务
systemctl start influxdb
systemctl enable influxdb
建库
curl -XPOST http://192.168.241.13:8086/query --data-urlencode "q=CREATE DATABASE prometheus"
或者
influx -precision rfc3339
create database prometheus;
show databases;
准备remote_storage_adapter
对于业务比较大的环境Local storage是绝对满足不了的,那么就要用remote storage了。
Prometheus的remote storage需要借助adapter实现,adapter会提供write url和read url给Prometheus,这样Prometheus获取到数据后就会先写到本地然后再调用write url写到远端。
下载一个可执行文件remote_storage_adapter。
GitHub地址:
https://github.com/prometheus/prometheus/blob/main/documentation/examples/remote_storage/remote_storage_adapter/README.md
需要安装一个go环境并进行build。我已经build好了,下载下面的地址可以直接用。
wget https://github.com/zyiqian/charts/blob/main/prometheus/remote_storage_adapter
chmod +x remote_storage_adapter
手工启动
nohup /usr/local/sbin/remote_storage_adapter
--influxdb-url=http://192.168.241.13:8086
--influxdb.database=prometheus
--influxdb.retention-policy=autogen >/var/log/remote_storage_adapter.log 2>&1 &
将remote_storage_adapter注册为系统服务
cat>/lib/systemd/system/remote_storage_adapter.service<<EOF
[Service]
Restart=on-failure
WorkingDirectory=/root/
ExecStart=/usr/local/sbin/remote_storage_adapter --influxdb-url=http://192.168.241.13:8086/ --influxdb.database="prometheus" --influxdb.retention-policy=autogen
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable remote_storage_adapter
systemctl start remote_storage_adapter
systemctl status remote_storage_adapter
配置prometheus远程写入
修改prometheus.yml中的配置remoteWrite和remoteRead
remote_write:
- url: "http://192.168.241.13:8086/api/v1/prom/write?db=prometheus"
remote_read:
- url: "http://192.168.241.13:8086/api/v1/prom/read?db=prometheus"
查看Influxdb
# influx
Connected to http://localhost:8086 version 1.8.0
influxdb shell version: 1.8.0
> show databases;
name: databases
name
----
prometheus
_internal
> use prometheus
Using database prometheus
> SHOW MEASUREMENTS;
name: measurements
name
----
ALERTS
ALERTS_FOR_STATE
aggregator_openapi_v2_regeneration_count
下一篇find命令用法及参数