How to connect telegraf to influxdb on docker

Hi guys, I’m fairly new to influxdb and telegraf. I have influxdb setup on docker and running. I’ve even installed and started a telegraf container (both influx and telegraf and communicating with each other in the same container e.g --net=network_name) but telegraf seems to not be communicating. Is there a way to check if both telegraf and influxdb are connected together on docker (how do i check it on the UI and through the command line?)

Is there a way to set up telegraf’s config file in docker via the command line and have it auto configured with influx so that I dont have to change anything in the config file specifically(I’m trying not to use the UI for this specific step) - if this step is doable through docker-compose.yml please do share how.
Btw I’m using Ubuntu 18.4

Thanks
Any help will be appreciated?

I’m not using docker for much yet, including influxdb, but this blog post may contain what you’re after

Below is an example docker-compose.yml (using Compose file format version 3) which defines three services, influxdb , influxdb_cli , and telegraf :

version: '3'
services:
  influxdb:
    image: quay.io/influxdb/influxdb:v2.0.3
    volumes:
      # Mount for influxdb data directory and configuration
      - influxdbv2:/.influxdbv2
    ports:
      - "8086:8086"
# Use the influx cli to set up an influxdb instance. 
  influxdb_cli:
    links:
      - influxdb
    image: quay.io/influxdb/influxdb:v2.0.3
# Use these same configurations parameters in your telegraf configuration, mytelegraf.conf.
    entrypoint: influx setup --bucket mybucket -t mytoken -o myorg --username=myusername --password=passwordpasswordpassword --host=http://influxdb:8086 -f
      # Wait for the influxd service in the influxdb container has fully bootstrapped before trying to setup an influxdb instance with the influxdb_cli service. 
    restart: on-failure:10
    depends_on:
      - influxdb
  telegraf:
    image: telegraf
    links:
      - influxdb
    volumes:
      # Mount for telegraf config
      - ./telegraf/mytelegraf.conf:/etc/telegraf/telegraf.conf
    depends_on:
      - influxdb_cli
volumes:
  influxdbv2:

Copy

To deploy these services, run docker-compose up -d (like docker run , the -d argument starts the containers in headless “detached”

Source:

1 Like