I have an issue with Telegraf’s AMQP output plugin where it fails to connect to a RabbitMQ broker, resulting in the error:
[telegraf] Error running agent: connecting output outputs.amqp: error connecting to output "outputs.amqp": could not connect to any broker
I’ve attempted to connect using various URLs, but none works, including:
amqp://localhost:5672
amqp://rabbitmq:5672
amqp://guest:guest@localhost:5672
amqp://rabbitmq
(omitting the port)
Here is my docker-compose file:
version: '3.8'
services:
telegraf:
image: telegraf:latest
container_name: telegraf
privileged: true
environment:
- CLOUDVISION_BASE_URL=https://www.arista.io/cvpservice
- CLOUDVISION_API_KEY=api_key
- AGENT_INTERVAL=10m
- REQUEST_TIMEOUT=15s
- AMQP_HOST=localhost
- AMQP_PORT=5672
- AMQP_USERNAME=guest
- AMQP_PASSWORD=guest
depends_on:
- rabbitmq
volumes:
- ./telegraf/telegraf.conf:/etc/telegraf/telegraf.conf:ro
rabbitmq:
image: rabbitmq:3-management-alpine
container_name: rabbitmq
ports:
- "5672:5672"
- "15672:15672"
environment:
RABBITMQ_DEFAULT_USER: guest
RABBITMQ_DEFAULT_PASS: guest
volumes:
- ./rabbitmq/data:/var/lib/rabbitmq/mnesia
- ./rabbitmq/log:/var/log/rabbitmq/mnesia
Here is my telegraf.conf file:
[agent]
interval = "${AGENT_INTERVAL}"
round_interval = true
metric_batch_size = 10
metric_buffer_limit = 100
[[inputs.http]]
urls = [
"${CLOUDVISION_BASE_URL}/inventory/devices"
]
method = "GET"
token = "${CLOUDVISION_API_KEY}"
timeout = "${REQUEST_TIMEOUT}"
success_status_codes = [200]
use_system_proxy = true
name_override = "arista"
tagexclude = ["url", "host"]
data_format = "json_v2"
[[inputs.http.json_v2]]
[[inputs.http.json_v2.object]]
path = "@this"
[[outputs.amqp]]
brokers = ["amqp://${AMQP_HOST}:${AMQP_PORT}"]
exchange_type = "topic"
data_format = "json"
auth_method = "PLAIN"
username = "${AMQP_USER}"
password = "${AMQP_PASSWORD}"
Has anyone faced a similar issue? Also, I am able to connect to RabbitMQ with python script. I don’t know if it is important to mention that I use podman with podman-desktop.
Here is my python script:
import pika
def send_hello_world_message():
connection = pika.BlockingConnection(
pika.ConnectionParameters(
host='localhost', port=5672, credentials=pika.PlainCredentials('guest', 'guest')
)
)
channel = connection.channel()
channel.queue_declare(queue='hello')
channel.basic_publish(exchange='',
routing_key='hello',
body='Hello World!')
print(" [x] Sent 'Hello World!'")
connection.close()
send_hello_world_message()
Thank you!