Prometheus 将数据远程写入 InfluxDB 存储

Prometheus 将数据远程写入 InfluxDB 存储

  • InfluxDB 1.x 提供了直接写入数据的 http 接口,Prometheus 可以直接写入,但是 InfluxDB 2.x 删除了这个接口。

  • InfluxDB 2.x 引入了新的组件 Telegraf,必须借助 Telegraf 才可以将 Prometheus 的数据写入到 InfluxDB 2.x 中。

InfluxDB 2.0 使用 Prometheus 架构图

InfluxDB 2.0 不使用 Prometheus 架构图

InfluxDB 2.0 与 Telegraf 如何结合配置

参考: https://blog.csdn.net/catoop/article/details/127533069

实操 InfluxDB 1.x 版本

version: '3'

services:
  influxdb:
    image: 'influxdb:1.8'
    container_name: influxdb
    network_mode: host
    volumes:
      - './influxdb:/var/lib/influxdb'
    #ports:
    #  - '8086:8086'

  mysql:
    image: mysql:8.0
    restart: always
    container_name: mysql
    network_mode: host
    environment:
      TZ: Asia/Shanghai
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: grafana
      MYSQL_USER: grafana
      MYSQL_PASSWORD: grafana
      MYSQL_ROOT_HOST: '%'
      MYSQL_DEFAULT_AUTHENTICATION_PLUGIN: mysql_native_password  # 设置使用 MySQL 5.7 的加密算法
    volumes:
      - ./mysql:/var/lib/mysql
    #ports:
    #  - "3306:3306

  prometheus:
    image: prom/prometheus
    container_name: prometheus
    network_mode: host
    environment:
      TZ: Asia/Shanghai
    #ports:
    #  - "9090:9090"
    volumes:
      #- ./prometheus/k8s.token:/etc/prometheus/k8s.token 
      - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'

  grafana:
    image: grafana/grafana
    #image: grafana/grafana:8.5.27
    container_name: grafana
    network_mode: host
    volumes:
      - ./grafana/grafana.ini:/etc/grafana/grafana.ini
    depends_on:
      - mysql
    #ports:
    #  - "53000:3000"
[root@worker1 aaa]# cat prometheus/prometheus.yml 
global:
  scrape_interval: 15s

remote_write:
  - url: "http://<influxdb>:8086/api/v1/prom/write?db=prometheus"

remote_read:
  - url: "http://<influxdb>:8086/api/v1/prom/read?db=prometheus"

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']

  - job_name: 'test'
    static_configs:
      - targets: ['8.8.8.8:9100']
[root@worker1 aaa]# cat grafana/grafana.ini
......略
[database]
type = mysql
host = you_mysql_adderss:3306
name = grafana
user = grafana
password = grafana

[paths]
data = mysql

http://xxxx:3000

admin/admin

测试: 启动,收集一点数据,再卸载容器,再启动容器,查看刚刚收集的数据是否存在,存在就说明持久化成功

Last updated