您的位置:首页 > 运维架构 > Docker

[docker]单台物理机-多台物理机集中-监控[ansible-cmdb/netdata/Serverstatus]

2017-10-28 15:33 483 查看

netdata-监控单台vm

适用于单台物理机资源监控.

github

docker run -d --cap-add SYS_PTRACE \
-v /proc:/host/proc:ro \
-v /sys:/host/sys:ro \
-p 19999:19999 titpetric/netdata


Serverstatus-监控多台vm(cs模式-psutil)

缺点: 服务端和客户端都需要配置. 不符合大面积使用场景,实用不同地方的物理机.

原理: 服务端开个端口—客户端利用基于pstuil脚本推送监控谁到服务端.然后生成html, 把这些html放到nginx的目录下,供用户查阅.

#### 1.服务端安装

git clone https://github.com/tenyue/ServerStatus.git cd ServerStatus/server
make

附:
yum -y install gcc+ gcc-c++


1.2.修改服务端配置文件

{"servers":
[
{
"username": "no132",            # 用户名和密码需要在客户端配置
"name": "node132.ma.com",       # 节点名:感觉像是主机名的一个标签别名吧
"type": "kvm",                  # 虚拟化类型,Openvs?KVM?Xen?
"host": "GenericServerHost123", # 主机名
"location": "Shenzhen",         # 在台机器在洛杉矶?纽约?
"password": "123456"
},
{
"username": "bs01",
"name": "Backupserver 1",
"type": "Virtual Server",
"host": "GenericVPSHost123",
"location": "Switzerland",
"password": "some-harder-to-guess-copy-paste-password"
}
]
}


1.3跑一个nginx,把服务端的网页程序放目录下,我跑了个docker

mkdir -p /data/nginx-html

docker run  -d \
--net=host \
--restart=always \
-v /etc/nginx/nginx.conf:/etc/nginx/nginx.conf:ro \
-v /etc/localtime:/etc/localtime:ro \
-v /data/nginx-html:/usr/share/nginx/html \
--name nginx \
nginx


cp -r ServerStatus/web/* /data/nginx-html


1.4启动服务端(91用于和客户端通信)

./sergate --config=/data/ServerStatus/server/config.json --web-dir=
9e6c
/data/nginx-html/ --port=91

nohup ./sergate --config=/data/ServerStatus/server/config.json --web-dir=/data/nginx-html/ --port=91 &> /dev/null &


### 2.安装客户端

yum -y install epel-release
yum -y install python-pip
yum clean all
yum -y install gcc
yum -y install python-devel
pip install psutil


还有win的客户端

配置客户端

wget https://raw.githubusercontent.com/tenyue/ServerStatus/master/clients/client-psutil.py vim client-psutil.py
...
8 SERVER = "127.0.0.1"
9 PORT = 91
10 USER = "no132"
11 PASSWORD = "123456"
12 INTERVAL = 1 # 更新间隔
...


启动客户端

python client-psutil.py

nohup python client-psutil.py &> /dev/null &


ansible-cmdb监控多台vm

好处: 更细致,可以看到每台vm上跑了什么服务. 和ansible丝滑般对接.

原理: 利用ansible搜集机器指标,生成html,放到nginx目录下供用户访问查阅.

安装参考

github
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: