Collectd

Docker:Collectd 不在實例之間進行通信

  • August 7, 2017

我在 docker 容器中啟動了一個伺服器實例,與 Facette 前端連接,看起來很酷,facette 讀取 rrd 數據。

當我想從其他電腦接收數據時,問題就開始了。我在本地嘗試了從 docker 到本地機器的暴露埠。

version: '2.1'
services:
collectd:
   build: ./containers/collectd
   ports:
       - 28596:28596
       - 8125:8125
   volumes:
       - ./var/rrd/:/var/lib/collectd/rrd

frontend:
   build: ./containers/facette
   ports:
       - 12003:12003
   volumes:
       - ./var/rrd:/var/lib/collectd/rrd
       - ./var/facette:/var/lib/facette/

伺服器的 Dockerfile:

FROM alpine:latest
ENV ARCH=x86

RUN apk --update add perl-dev python3-dev wget alpine-sdk linux-headers rsyslog rrdtool rrdtool-dev rrdtool-utils

# Get and untar sources files
RUN wget https://collectd.org/files/collectd-5.7.1.tar.bz2
RUN tar jxvf collectd-5.7.1.tar.bz2 && rm collectd-5.7.1.tar.bz2

# Compile and purge source files
RUN cd collectd-5.7.1 && ./configure --with-rrdtool && make all install
RUN cd .. && rm -rf collectd-5.7.1

# Optionnal post installation tasks
RUN ln -s /opt/collectd/sbin/collectd /usr/sbin/collectd
RUN ln -s /opt/collectd/sbin/collectdmon /usr/sbin/collectdmon

RUN rm -rf /var/cache/apk/*
RUN apk del alpine-sdk linux-headers perl-dev python3-dev

#RUN apk add --update collectd rrdtool rsyslog collectd-dns collectd-curl collectd-sensors collectd-ping collectd-utils collectd-nginx collectd-iptables collectd-bind collectd-write_http collectd-rrdtool collectd-network collectd-disk collectd-libs
ADD ./etc/* /etc/ 
ADD ./entrypoint.sh /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]

伺服器的collectd.conf

Hostname "bakunin-tower"
FQDNLookup true
LoadPlugin syslog

<plugin syslog>
   LogLevel info
   File "/var/log/collectd.log"
   Timestamp true
</plugin>

LoadPlugin cpu
LoadPlugin disk
LoadPlugin interface
LoadPlugin load
LoadPlugin memory
LoadPlugin network
LoadPlugin nfs
LoadPlugin rrdtool
LoadPlugin swap

<plugin network>
 Listen "0.0.0.0" "28596"
</plugin>

<plugin rrdtool>
 DataDir "/var/lib/collectd/rrd"
</plugin>

#Include "/etc/collectd.d/*.conf"

客戶的 collectd.conf

Hostname "kropotkin"
FQDNLookup true
LoadPlugin syslog

LoadPlugin "logfile"
<Plugin "logfile">
   LogLevel "info"
   File "/var/log/collectd.log"
   Timestamp true
</Plugin>

<plugin syslog>
   LogLevel info
</plugin>

LoadPlugin cpu
LoadPlugin disk
LoadPlugin interface
LoadPlugin load
LoadPlugin memory
LoadPlugin network

<Plugin network>
 Server "127.0.0.1" "28596"
</Plugin>

在伺服器上,我在 rrd 目錄中只看到“bakunin-tower”,但我希望 kropotkin 也會出現。怎麼了?我的頭要爆炸了。

謝謝。

我挖了好幾天,沒有看到解決方案。然後我想到了一個想法——在 Docker 之外嘗試相同的配置怎麼樣?我試過了,它可以工作,然後我將我的 docker-compose.yml 配置更正為:

version: '2.1'
services:
   collectd:
       build: ./containers/collectd
       ports:
           - 25826:25826
           - 8125:8125
       volumes:
           - ./var/rrd/:/var/lib/collectd/rrd
       network_mode: host

   frontend:
       build: ./containers/facette
       ports:
           - 12003:12003
       volumes:
           - ./var/rrd:/var/lib/collectd/rrd
           - ./var/facette:/var/lib/facette/

引用自:https://serverfault.com/questions/867286