大网数据广告活动
服务器运维问答

how do i start collectd inside docker?

· 52CE 我爱测

I am trying to start collectd inside docker and i have tried everything from running command to start collectd in dockerfile to using a script to running service collectd start to using supervisord but still not working my superv…

问题原文

原帖链接 · uberrebu · CC BY-SA 3.0

I am trying to start collectd inside docker and i have tried everything from running command to start collectd in dockerfile to using a script to running service collectd start to using supervisord but still not working

my supervisord.conf file is

[unix_http_server]
file=/tmp/supervisor.sock   ; (the path to the socket file)

[supervisord]
logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB        ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10           ; (num of main logfile rotation backups;default 10)
loglevel=info                ; (log level;default info; others: debug,warn,trace)
pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=false               ; (start in foreground if true;default false)
minfds=1024                  ; (min. avail startup file descriptors;default 1024)
minprocs=200                 ; (min. avail process descriptors;default 200)
user=root            ;

; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL  for a unix socket

[program:collectd]
command=/usr/sbin/collectd -C /etc/collectd/collectd.conf -f
autostart=true
autorestart=true
priority=5
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

I also tried running it inside my Dockerfile

RUN service collectd start

By Dockerfile is using Ubuntu 16.04 and i installed collectd with apt-get install collectd which beautifully installs collectd version 5.5.1 for me(which is what i want)

Anyways when i run container and do ps aux i see

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.6  0.0  18180  2000 ?        Ss   20:27   0:00 bash
root        11  0.0  0.0  34364  1544 ?        R+   20:27   0:00 ps aux

so basically collectd is still not running

and inside container i start it with service collectd start and the it works fine

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0  18180  2008 ?        Ss   20:27   0:00 bash
root        27  0.0  0.0   4300   320 ?        Ss   20:27   0:00 /usr/sbin/collectdmon -P /var/run/collectd.pid -- -C /etc/collectd
root        30  0.0  0.0 799820  2368 ?        Sl   20:27   0:00 collectd -C /etc/collectd/collectd.conf -f
root        42  0.0  0.0  34364  1544 ?        R+   20:30   0:00 ps aux

So basically how do i get to run collectd automatically when docker image is ran?

P.S Even if i dont have to use supervisrod, fine i just want a way to have collectd running when i run the container

Thanks

UPDATE: Also a single collectd command ran inside the container also starts collectd

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0  18180  2020 ?        Ss   21:09   0:00 bash
root        36  0.0  0.0 799820  1680 ?        Ssl  21:10   0:00 collectd
root        47  0.0  0.0  34364  1544 ?        R+   21:10   0:00 ps aux

已采纳解答

原帖链接 · Navern · CC BY-SA 3.0

You don't need supervisor for container with collectd.

For example you have created image with name "my_collectd:latest", then you need to run following command:

docker run -d --name my_test my_collectd:latest collectd -f

This will create container in daemon mode with name "my_test". It should run collectd -f command inside.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-07-15)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。