使用collectd收集物理机和虚拟机的运行信息(参考的文章已经在文前注明)
2014-02-10 11:10
531 查看
参考:
http://linuxdrops.com/install-collectd-statistics-collecter-on-centos-rhel-ubuntu-debian/
目的: 编译在server 和client 端编译 并 安装 collectd, 收集client物理机及其上运行的虚拟机信息,发送到server段。
一:server端
1 /etc/hostname 中的名字需要和/etc/hosts中的127.0.1.1 后面的名字一致,否则会启动不了collectd或者
在/var/lib/collectd中生成不了rrd文件。
2 apt-get install build-essential librrd2-dev libsensors4-dev libsnmp-dev libgcrypt-dev chkconfig
automake flex bison pkg-config byacc autoconf libglib-* libtool rrdtool
3 # git clone https://github.com/collectd/collectd.git
# cd collectd
# ./build.sh
# ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --libdir=/usr/lib --mandir=/usr/share/man --enable-all-plugins
# make
# make install
4 # vi /etc/init.d/collectd
Append the following to it
#! /bin/bash
#
# collectd - start and stop the statistics collection daemon
# http://collectd.org/
#
# Copyright (C) 2005-2006 Florian Forster
# Copyright (C) 2006-2009 Sebastian Harl
#
### BEGIN INIT INFO
# Provides: collectd
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Should-Start: $network $named $syslog $time
# Should-Stop: $network $named $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start the statistics collection daemon
### END INIT INFO
set -e
PATH=/sbin:/bin:/usr/sbin:/usr/bin
DISABLE=0
DESC="statistics collection and monitoring daemon"
NAME=collectd
DAEMON=/usr/sbin/collectd
CONFIGFILE=/etc/collectd.conf
PIDFILE=/var/run/collectd.pid
USE_COLLECTDMON=1
COLLECTDMON_DAEMON=/usr/sbin/collectdmon
COLLECTDMON_PIDFILE=/var/run/collectdmon.pid
MAXWAIT=30
# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
if [ -r /etc/default/$NAME ]; then
. /etc/default/$NAME
fi
if test "$DISABLE" != 0 -a "$1" == "start"; then
echo "$NAME has been disabled - see /etc/default/$NAME."
exit 0
fi
if test ! -e "$CONFIGFILE" -a "$1" == "start"; then
echo "Not starting $NAME - no configuration ($CONFIGFILE) found."
exit 0
fi
if test "$ENABLE_COREFILES" == 1; then
ulimit -c unlimited
fi
if test "$USE_COLLECTDMON" == 1; then
_PIDFILE="$COLLECTDMON_PIDFILE"
else
_PIDFILE="$PIDFILE"
fi
check_config() {
if ! $DAEMON -t -C "$CONFIGFILE"; then
if test -n "$1"; then
echo "$1" >&2
fi
exit 1
fi
}
d_start() {
if test "$DISABLE" != 0; then
# we get here during restart
echo -n " - disabled by /etc/default/$NAME"
return 0
fi
if test ! -e "$CONFIGFILE"; then
# we get here during restart
echo -n " - no configuration ($CONFIGFILE) found."
return 0
fi
check_config
if test "$USE_COLLECTDMON" == 1; then
start-stop-daemon --start --quiet --oknodo --pidfile "$_PIDFILE" \
--exec $COLLECTDMON_DAEMON -- -P "$_PIDFILE" -- -C "$CONFIGFILE"
else
start-stop-daemon --start --quiet --oknodo --pidfile "$_PIDFILE" \
--exec $DAEMON -- -C "$CONFIGFILE" -P "$_PIDFILE"
fi
}
still_running_warning="
WARNING: $NAME might still be running.
In large setups it might take some time to write all pending data to
the disk. You can adjust the waiting time in /etc/default/collectd."
d_stop() {
PID=$( cat "$_PIDFILE" 2> /dev/null ) || true
start-stop-daemon --stop --quiet --oknodo --pidfile "$_PIDFILE"
sleep 1
if test -n "$PID" && kill -0 $PID 2> /dev/null; then
i=0
while kill -0 $PID 2> /dev/null; do
i=$(( $i + 2 ))
echo -n " ."
if test $i -gt $MAXWAIT; then
echo "$still_running_warning" >&2
return 1
fi
sleep 2
done
return 0
fi
}
d_status() {
PID=$( cat "$_PIDFILE" 2> /dev/null ) || true
if test -n "$PID" && kill -0 $PID 2> /dev/null; then
echo "collectd ($PID) is running."
exit 0
else
PID=$( pidof collectd ) || true
if test -n "$PID"; then
echo "collectd ($PID) is running."
exit 0
else
echo "collectd is stopped."
fi
fi
exit 1
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
d_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
d_stop
echo "."
;;
status)
d_status
;;
restart|force-reload)
echo -n "Restarting $DESC: $NAME"
check_config "Not restarting collectd."
d_stop
sleep 1
d_start
echo "."
;;
*)
echo "Usage: $0 {start|stop|restart|force-reload|status}" >&2
exit 1
;;
esac
exit 0
# vim: syntax=sh noexpandtab sw=4 ts=4 :
5 Change permissions and start collectd
# chmod 755 /etc/init.d/collectd
# chown root:root /etc/init.d/collectd
# chkconfig --add collectd
# /etc/init.d/collectd start
# chkconfig collectd on
6 Open the collectd configuration file and make sure all basic plugins get loaded.
You may see LoadPlugin directive followed by the parameter to monitor, it could have
a # or ## sign in front. A single # means that the plugin is not active but is
supported, just remove the # sign and it will start working. A double ## means that
the plugin is not supported, this may be due to a missing package, in such senario
just install the missing package and compile collectd again. You may refer the README
file provided in the collectd installer directory to find what packages are required
for a parameter to work.
# vi /etc/collectd.conf
Enable basic plugins
LoadPlugin network
LoadPlugin cpu
LoadPlugin memory
LoadPlugin rrdtool
LoadPlugin network
LoadPlugin syslog
or
LoadPlugin logfile
7
Also append the following to server side collectd.conf. This will make collectd listen on the port 25827.
Make sure you change the ip address below with the ip address of your collectd server
# Server
<Plugin "network">
Listen "192.168.209.161" "25827"
</Plugin>
Restart collectd
# /etc/init.d/collectd restart
8
Make sure collectd has started listening.
# netstat -tunlp | grep -i collectd
udp 0 0 192.168.209.161:25826 0.0.0.0:* 49475/collectd
client端:
client:
redo the step 1 to step 6 which is done on the server side, and then modify collectd.conf as following:
# Client
<Plugin "network">
Server "192.168.209.161" "25827"
</Plugin>
and then Restart collectd
# /etc/init.d/collectd restart
备注:
经过上述的安装并重起服务,client就会将自己监控到的数据发送到server 端,数据存储的路径为/var/lib/collectd/ , 在此目录下有以主机
名命名的文件夹,其中包含监控到的数据。
默认的获取数据的时间很长,可以通过修改collectd.conf 中的以下几个选项:
Interval 15
Timeout 2
ReadThreads 5
WriteThreads 5
增加获取数据的频率。
验证上述文件夹中的rrd文件是否获得了有效数据:
# cd /var/lib/collectd/bhwserver/load
# rrdtool fetch load.rrd AVERAGE
转换文件格式: rrd->xml
# rrdtool dump load.rrd >load.xml
监控libvirt虚拟机:
步骤:
1 在虚拟机运行的机器进入collectd目录:
# ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --libdir=/usr/lib --mandir=/usr/share/man --enable-all-plugins
检查libvirt plugin 是否已经注册好,如果出现libvirt . . . . . . . no (dependency error)
则通过/var/log/syslog可以查看错误的原因,基本上可以通过下列连接解决:
http://6.ptmc.org/348/
( The solution here is to install the libxml2-dev package in addition to libvirt-dev, since that is needed by collectd to parse
the XML VM configuration stanzas that libvirt provides. apt-get install libxml2-dev libvirt-dev )
2 修改collectd.conf文件如下:
<Plugin libvirt>
Connection "qemu:///system"
RefreshInterval 5
# Domain "name"
# IgnoreSelected false
# BlockDevice "name:device"
# HostnameFormat "name"
</Plugin>
3 check whether the libvirtd is running .
4 service collectd restart
5 there will be dir which is named instance-0000* in /var/lib/collectd/ .
http://linuxdrops.com/install-collectd-statistics-collecter-on-centos-rhel-ubuntu-debian/
目的: 编译在server 和client 端编译 并 安装 collectd, 收集client物理机及其上运行的虚拟机信息,发送到server段。
一:server端
1 /etc/hostname 中的名字需要和/etc/hosts中的127.0.1.1 后面的名字一致,否则会启动不了collectd或者
在/var/lib/collectd中生成不了rrd文件。
2 apt-get install build-essential librrd2-dev libsensors4-dev libsnmp-dev libgcrypt-dev chkconfig
automake flex bison pkg-config byacc autoconf libglib-* libtool rrdtool
3 # git clone https://github.com/collectd/collectd.git
# cd collectd
# ./build.sh
# ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --libdir=/usr/lib --mandir=/usr/share/man --enable-all-plugins
# make
# make install
4 # vi /etc/init.d/collectd
Append the following to it
#! /bin/bash
#
# collectd - start and stop the statistics collection daemon
# http://collectd.org/
#
# Copyright (C) 2005-2006 Florian Forster
# Copyright (C) 2006-2009 Sebastian Harl
#
### BEGIN INIT INFO
# Provides: collectd
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Should-Start: $network $named $syslog $time
# Should-Stop: $network $named $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start the statistics collection daemon
### END INIT INFO
set -e
PATH=/sbin:/bin:/usr/sbin:/usr/bin
DISABLE=0
DESC="statistics collection and monitoring daemon"
NAME=collectd
DAEMON=/usr/sbin/collectd
CONFIGFILE=/etc/collectd.conf
PIDFILE=/var/run/collectd.pid
USE_COLLECTDMON=1
COLLECTDMON_DAEMON=/usr/sbin/collectdmon
COLLECTDMON_PIDFILE=/var/run/collectdmon.pid
MAXWAIT=30
# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
if [ -r /etc/default/$NAME ]; then
. /etc/default/$NAME
fi
if test "$DISABLE" != 0 -a "$1" == "start"; then
echo "$NAME has been disabled - see /etc/default/$NAME."
exit 0
fi
if test ! -e "$CONFIGFILE" -a "$1" == "start"; then
echo "Not starting $NAME - no configuration ($CONFIGFILE) found."
exit 0
fi
if test "$ENABLE_COREFILES" == 1; then
ulimit -c unlimited
fi
if test "$USE_COLLECTDMON" == 1; then
_PIDFILE="$COLLECTDMON_PIDFILE"
else
_PIDFILE="$PIDFILE"
fi
check_config() {
if ! $DAEMON -t -C "$CONFIGFILE"; then
if test -n "$1"; then
echo "$1" >&2
fi
exit 1
fi
}
d_start() {
if test "$DISABLE" != 0; then
# we get here during restart
echo -n " - disabled by /etc/default/$NAME"
return 0
fi
if test ! -e "$CONFIGFILE"; then
# we get here during restart
echo -n " - no configuration ($CONFIGFILE) found."
return 0
fi
check_config
if test "$USE_COLLECTDMON" == 1; then
start-stop-daemon --start --quiet --oknodo --pidfile "$_PIDFILE" \
--exec $COLLECTDMON_DAEMON -- -P "$_PIDFILE" -- -C "$CONFIGFILE"
else
start-stop-daemon --start --quiet --oknodo --pidfile "$_PIDFILE" \
--exec $DAEMON -- -C "$CONFIGFILE" -P "$_PIDFILE"
fi
}
still_running_warning="
WARNING: $NAME might still be running.
In large setups it might take some time to write all pending data to
the disk. You can adjust the waiting time in /etc/default/collectd."
d_stop() {
PID=$( cat "$_PIDFILE" 2> /dev/null ) || true
start-stop-daemon --stop --quiet --oknodo --pidfile "$_PIDFILE"
sleep 1
if test -n "$PID" && kill -0 $PID 2> /dev/null; then
i=0
while kill -0 $PID 2> /dev/null; do
i=$(( $i + 2 ))
echo -n " ."
if test $i -gt $MAXWAIT; then
echo "$still_running_warning" >&2
return 1
fi
sleep 2
done
return 0
fi
}
d_status() {
PID=$( cat "$_PIDFILE" 2> /dev/null ) || true
if test -n "$PID" && kill -0 $PID 2> /dev/null; then
echo "collectd ($PID) is running."
exit 0
else
PID=$( pidof collectd ) || true
if test -n "$PID"; then
echo "collectd ($PID) is running."
exit 0
else
echo "collectd is stopped."
fi
fi
exit 1
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
d_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
d_stop
echo "."
;;
status)
d_status
;;
restart|force-reload)
echo -n "Restarting $DESC: $NAME"
check_config "Not restarting collectd."
d_stop
sleep 1
d_start
echo "."
;;
*)
echo "Usage: $0 {start|stop|restart|force-reload|status}" >&2
exit 1
;;
esac
exit 0
# vim: syntax=sh noexpandtab sw=4 ts=4 :
5 Change permissions and start collectd
# chmod 755 /etc/init.d/collectd
# chown root:root /etc/init.d/collectd
# chkconfig --add collectd
# /etc/init.d/collectd start
# chkconfig collectd on
6 Open the collectd configuration file and make sure all basic plugins get loaded.
You may see LoadPlugin directive followed by the parameter to monitor, it could have
a # or ## sign in front. A single # means that the plugin is not active but is
supported, just remove the # sign and it will start working. A double ## means that
the plugin is not supported, this may be due to a missing package, in such senario
just install the missing package and compile collectd again. You may refer the README
file provided in the collectd installer directory to find what packages are required
for a parameter to work.
# vi /etc/collectd.conf
Enable basic plugins
LoadPlugin network
LoadPlugin cpu
LoadPlugin memory
LoadPlugin rrdtool
LoadPlugin network
LoadPlugin syslog
or
LoadPlugin logfile
7
Also append the following to server side collectd.conf. This will make collectd listen on the port 25827.
Make sure you change the ip address below with the ip address of your collectd server
# Server
<Plugin "network">
Listen "192.168.209.161" "25827"
</Plugin>
Restart collectd
# /etc/init.d/collectd restart
8
Make sure collectd has started listening.
# netstat -tunlp | grep -i collectd
udp 0 0 192.168.209.161:25826 0.0.0.0:* 49475/collectd
client端:
client:
redo the step 1 to step 6 which is done on the server side, and then modify collectd.conf as following:
# Client
<Plugin "network">
Server "192.168.209.161" "25827"
</Plugin>
and then Restart collectd
# /etc/init.d/collectd restart
备注:
经过上述的安装并重起服务,client就会将自己监控到的数据发送到server 端,数据存储的路径为/var/lib/collectd/ , 在此目录下有以主机
名命名的文件夹,其中包含监控到的数据。
默认的获取数据的时间很长,可以通过修改collectd.conf 中的以下几个选项:
Interval 15
Timeout 2
ReadThreads 5
WriteThreads 5
增加获取数据的频率。
验证上述文件夹中的rrd文件是否获得了有效数据:
# cd /var/lib/collectd/bhwserver/load
# rrdtool fetch load.rrd AVERAGE
转换文件格式: rrd->xml
# rrdtool dump load.rrd >load.xml
监控libvirt虚拟机:
步骤:
1 在虚拟机运行的机器进入collectd目录:
# ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --libdir=/usr/lib --mandir=/usr/share/man --enable-all-plugins
检查libvirt plugin 是否已经注册好,如果出现libvirt . . . . . . . no (dependency error)
则通过/var/log/syslog可以查看错误的原因,基本上可以通过下列连接解决:
http://6.ptmc.org/348/
( The solution here is to install the libxml2-dev package in addition to libvirt-dev, since that is needed by collectd to parse
the XML VM configuration stanzas that libvirt provides. apt-get install libxml2-dev libvirt-dev )
2 修改collectd.conf文件如下:
<Plugin libvirt>
Connection "qemu:///system"
RefreshInterval 5
# Domain "name"
# IgnoreSelected false
# BlockDevice "name:device"
# HostnameFormat "name"
</Plugin>
3 check whether the libvirtd is running .
4 service collectd restart
5 there will be dir which is named instance-0000* in /var/lib/collectd/ .
相关文章推荐
- 使用BLOG收集和整理专业技术分享类文章
- 如何查看应用运行时虚拟机内存使用情况
- Oracle EBS无法启动,错误信息:您的安全设置已组织自签名的应用程序使用已过期的Java版本运行。
- 使用virt-p2v工具将物理机迁移到Openstack虚拟机中
- 在页面中直接设计TreeView的节点而不使用Web.Sitemap文件在运行时出错信息
- win7 2008 尚未在 Web 服务器上注册ASP.NET 4.0。为了使网站正确运行,可能需要手动将 Web 服务器配置为使用 ASP.NET 4.0,按 F1 可了解更多详细信息。
- 时代互联 域名注册查询接口api的使用 (w3Sockets)(这篇文章,关于是放到C:\WINDOWS或者是C:\WINDOWS\system32要亲自试试,附带在 server 2008 R2下无法运行的解决方法)
- HDFS设计思路,HDFS使用,查看集群状态,HDFS,HDFS上传文件,HDFS下载文件,yarn web管理界面信息查看,运行一个mapreduce程序,mapreduce的demo
- 《Advanced .NET Debugging》 读书笔记 Listing 3-3: 使用debugger调试一个已经在运行的程序
- 使用SSIS WMI Data Reader 通过WMI收集数据库维护信息
- 使用profile来得到程序运行信息
- 读取照片的Exif信息,这篇文章则是使用了ImageIO类来获取照片的信息
- 在使用 Intel E5 v2 系列处理器的 ESXi 5.x 上运行时,Windows 2008 R2 和 Solaris 10(64 位)虚拟机出现蓝屏或内核不稳定。 (2094336)
- 运行在VMware上的Linux虚拟机如何使用NAT模式连接物理机的外部网络
- 使用dbms_monitor包收集执行信息和trace
- 【翻译自mos文章】已经安装的Oracle database组件和自带的用户信息
- java 虚拟机系列文章5--垃圾收集器及GC参数
- DNS信息收集工具dig使用
- winform 运行中使用控制台动态输出调试及运行信息