Socket Listener cannot assign address

Hello,

In reality I want to log data from a industrial camera, that publishes data over a tcp-socket, into influxdb. For testing I build a docker container (“dmc”) that simulates the cam…

Now I have docker-compose with three containers:

  1. DMC-“Camera”-Container, that waits for a socket connection on port 9006 to send data
  2. InfluxDB to save the data
  3. Telegraf-Container, that should connect to the dmc container and save data to the influxDB

Here is the docker compose…

services:
  influxdb:
    image: influxdb:2.7.6
    container_name: "influxDB"
    restart: unless-stopped
    ports:
      - "18086:8086"
    expose:
      - 8086
    environment:
      [xxx]
    networks:
      - backend

  telegraf_dmc:
    image: telegraf:1.31.0
    container_name: telegraf_dmc
    environment:
      INFLUX_TOKEN:[...]
    entrypoint: telegraf --config http://influxdb:8086/api/v2/telegrafs/[...]
    depends_on:
      - influxdb
    expose:
      - "9006"
    restart: unless-stopped
    networks:
      - backend

  dmc:
    image: socketmock:dev
    container_name: dmc
    expose:
      - "9006"
    ports:
      - "9006:9006"
    networks:
      - backend

networks:
  backend:

The telegraf config looks like:

[agent]
  [...]

[[outputs.influxdb_v2]]
  urls = ["http://influxdb:8086"]
  token = "$INFLUX_TOKEN"
  organization = [...]
  bucket = "dmc"

[[inputs.socket_listener]]
  service_address = "tcp://dmc:9006"

The result is:

[telegraf] Error running agent: starting input inputs.socket_listener: listen tcp 172.21.0.2:9006: bind: cannot assign requested address

So it resolves the dns correctly (dmc → 172.21.0.2)
When I use my own socket subscriber everything works also fine…
and the influxdb-connection works (with oder inputs) also fine.

Thanks for help…

Hi,

bind: cannot assign requested address

This error usually means that something is already established on this port or you don’t have permissions.

Keep in mind that the socket listener is a listener and not a subscriber. It opens up a connection on a port and waits for messages to get passed to it.

Hi,

thanks for the clarification! Then I totally misunderstood the plugin. Is there a socket client plugin that can subscribe to a web socket server to meet my requirements like described above?

You could use your existing python script and have it pass metrics to telegraf using the execd plugin. For more info see: