prometheus的远程存储 influxdb V1版本

启动influxdb的docker服务

docker-compose.yml定义如下

version: '2'
services:
  influxdb:
    image: influxdb:1.3.5
    command: -config /etc/influxdb/influxdb.conf
    ports:
      - "8086:8086"
    environment:
      - INFLUXDB_DB=prometheus
      - INFLUXDB_ADMIN_ENABLED=true
      - INFLUXDB_ADMIN_USER=admin
      - INFLUXDB_ADMIN_PASSWORD=admin
      - INFLUXDB_USER=prom
      - INFLUXDB_USER_PASSWORD=prom

启动服务

$ docker-compose up -d
$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
795d0ead87a1        influxdb:1.3.5      "/entrypoint.sh -c..."   3 hours ago         Up 3 hours          0.0.0.0:8086->8086/tcp   localhost_influxdb_1

准备 remote_storage_adapter 远程存储适配器

需要编译remote_storage_adapter二进制

git clone https://github.com/prometheus/prometheus.git
cd prometheus/documentation/examples/remote_storage/remote_storage_adapter
go build

启动进程

export INFLUXDB_PW=prom && ./remote_storage_adapter --influxdb-url=http://10.20.2.117:8086 --influxdb.username=prom --influxdb.database=prometheus --influxdb.retention-policy=autogen

修改prometheus.yml

remote_write:
  - url: "http://localhost:9201/write"

remote_read:
  - url: "http://localhost:9201/read"

重新启动prometheus进程

进入influxdb 验证数据是否写入

docker exec -it 795d0ead87a1 influx
Connected to http://localhost:8086 version 1.3.5
InfluxDB shell version: 1.3.5
> auth
username: prom
password:

> use prometheus
> SHOW MEASUREMENTS
name: measurements
name
----
go_gc_duration_seconds
go_gc_duration_seconds_count
go_gc_duration_seconds_sum
go_goroutines
go_info
go_memstats_alloc_bytes
go_memstats_alloc_bytes_total
go_memstats_buck_hash_sys_bytes
go_memstats_frees_total
go_memstats_gc_cpu_fraction
go_memstats_gc_sys_bytes
go_memstats_heap_alloc_bytes
go_memstats_heap_idle_bytes

能看到 这些采集指标,证明就写入成功了

posted @ 2024-01-26 10:31  jasmine456  阅读(45)  评论(0编辑  收藏  举报