prometheus remote write to influx-DB
2022-06-15
本博客所有文章采用的授权方式为 自由转载-非商用-非衍生-保持署名 ,转载请务必注明出处,谢谢。
remote write to influx-db
prepare influx-db
influx-db v2 should use telegraph
influx-db v1.8 原生支持prometheus remote write协议
sudo docker run -p 8086:8086 \
--name influxdb \
-v influxdb:/opt/pulsar/influxdb \
influxdb:1.8
influx-db 创建测试数据库
wsg@ansible-control:~$ sudo docker exec -it influxdb bash
root@f46e6bcea141:/# ls
bin dev etc init-influxdb.sh lib64 mnt proc run srv tmp var
boot entrypoint.sh home lib media opt root sbin sys usr
root@f46e6bcea141:/# influx
Connected to http://localhost:8086 version 1.8.10
InfluxDB shell version: 1.8.10
> show databases;
name: databases
name
----
_internal
> show users;
user admin
---- -----
> create database prom;
> show databases;
name: databases
name
----
_internal
prom
>
config
prometheus config
修改prometheus.yml
---
global:
scrape_interval: 15s # By default, scrape targets every 15 seconds.
evaluation_interval: 15s # By default, scrape targets every 15 seconds.
# scrape_timeout is set to the global default (10s).
external_labels:
cluster: 'cluster-rack'
monitor: "prometheus"
mylabel: "hello-world"
app_id: 001461
# Load and evaluate rules in these files every 'evaluation_interval' seconds.
# rule_files:
remote_write:
- url: "http://10.2.0.10:8086/api/v1/prom/write?db=prom"
write_relabel_configs:
- source_labels: [job]
regex: '(.*)'
replacement: 'cluster1-${1}'
target_label: unit_id
action: replace
- url: "http://10.2.0.10:8087/api/v1/prom/write?db=prometheus"
可以remote write到多个influx db中
补充: 华泰需要新增一个 ip的label,调整的配置如下
remote_write:
- url: "http://10.2.0.10:8086/api/v1/prom/write?db=prom"
write_relabel_configs:
- source_labels: [job]
regex: '(.*)'
replacement: 'cluster1-${1}'
target_label: unit_id
action: replace
- source_labels: [instance]
#regex: '(.*)'
regex: '(.*):(.*)'
replacement: '${1}'
target_label: ip
action: replace
- url: "http://10.2.0.10:8087/api/v1/prom/write?db=prometheus"
instance的取值格式如下(以:号间隔)
grafana config
add datasource
查询influx db中的数据
检查指标的 lable信息
#