ServerStatus服务器探针


ServerStatus中文版是一个酷炫高逼格的云探针、云监控、服务器云监控、多服务器探针~。

目录文件夹

autodeploy 自动部署
clients 客户端
server 服务端
web 网站

安装

下载

yum –y install git
cd /home
git clone https://github.com/cppla/ServerStatus.git

生成服务端

cd ServerStatus/server
make
./sergate

默认监听端口35601,如没有错误Ctrl+C关闭

修改配置文件

vi config.json

配置文件内容

{"servers":
    [
        {
            "username": "s01", ##这里相当于客户端和服务端通信账号
            "name": "Mainserver 1",  ## 客户端名字
            "type": "Dedicated Server",##客户端所用虚拟化技术
            "host": "GenericServerHost123",##客户端IP,不会在前台显示
            "location": "Austria",## 客户端所在物理位置,写哪儿都行,看心情,尽量写正确的,毕竟是给自己看
            "password": "USER_DEFAULT_PASSWORD"##客户端和服务端通讯密码
        }
    ]
}

然后将ServerStatus目录中web文件夹内文件复制到你的站点目录中

cp -r ServerStatus/web/* /www/wwwroot/default

运行服务端

web-dir后面的参数为上一步设置的网站根目录,务必修改成自己网站的路径

./sergate --config=config.json --web-dir=/www/wwwroot/default

到此,访问站点就可以看到探针页面了,但没有数据(客户端)

Ctrl+C退出放入后台运行

nohup ./sergate --config=config.json --web-dir=/www/wwwroot/default > /dev/null 2>&1 &

docker安装服务端

看懂了上面的服务端配置详情,那么推荐使用docker来配置服务端程序,简单又轻松

version: '3'
services:
  serverstatus:
    container_name: serverstatus
    image: cppla/serverstatus:latest
    restart: unless-stopped
    ports:
      - "80:80"
      - "35601:35601"
    volumes:
      - ./config.json:/ServerStatus/server/config.json

只需在同目录下配置好config.json服务端与客户端通信文件,再启动容器就可以了。

客户端

客户端目录为ServerStatus/clients,客户端有两个版本,client-linux为普通linux,client-psutil为跨平台版,普通版不成功,换成跨平台版即可。

  • client-linux版配置
vi client-linux.py

主要修改以下数据,与服务端对接

SERVER = "127.0.0.1" ##服务端IP

IP PORT = 35601 ##默认监听端口

USER = "your user" ##服务端username参数

PASSWORD = "your password"## 服务端password参数

完成后执行

python client-linux.py

现在重新访问站点就会有监控数据了
Ctrl+c退出
后台运行

nohup python client-linux.py > /dev/null 2>&1 &
  • client-psutil版配置(推荐)

安装psutil跨平台依赖库

Centos:

yum -y install python3-pip gcc python3-devel && pip3 install psutil

Ubuntu/Debian:

apt -y install python3-pip && pip3 install psutil

Windows:

打开网址:https://pypi.python.org/pypi?:action=display&name=psutil#downloads
下载psutil for windows程序包
安装即可

跨平台依赖库安装完成后修改配置文件

vi client-psutil.py

主要修改以下数据,与服务端对接

SERVER = "127.0.0.1" ##服务端IP

IP PORT = 35601 ##默认监听端口

USER = "your user" ##服务端username参数

PASSWORD = "your password"## 服务端password参数

完成后执行

python client-psutil.py

现在重新访问站点就会有监控数据了
Ctrl+c退出
后台运行

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

新的小鸡快速完成客户端配置

仅在debian10 Ubuntu20LTS测试

  • 刷新依赖,配置跨平台依赖库
apt update
//debian
apt -y install python3-pip && pip3 install psutil
//ubuntu
apt-get install python3-dev
python3 -m pip install psutil
  • 下载跨平台文件,编辑配置信息,尝试启动
mkdir -p /home/ServerStatus/clients && cd $_ && wget https://ghproxy.com/https://raw.githubusercontent.com/cppla/ServerStatus/master/clients/client-psutil.py
nano client-psutil.py
python3 client-psutil.py
  • 写入systemctl自启
cd /usr/lib/systemd/system && nano tzc.service

输入以下粘贴以下内容到ssh

[Unit]
Description=tzc
After=network.target

[Service]
ExecStart=nohup /usr/bin/python3 -u /home/ServerStatus/clients/client-psutil.py &
StandardOutput=file:/home/ServerStatus/clients/Output.log
StandardError=file:/home/ServerStatus/clients/Error.log
Restart=always

[Install]
WantedBy=multi-user.target

刷新systemctl配置并尝试启动,查看探针页面

systemctl daemon-reload
systemctl start tzc

没问题,写入自启

systemctl enable tzc.service

流量统计

新版本已支持,可以不用修改
ServerStatus默认统计开机总流量,重启服务器会重新统计流量,可以修改为Vnstat来统计月总流量,重启不丢失流量数据。
本段内容过于复杂,移步Centos7下vnstat详细配置

默认端口

如需更换默认监听端口35601为其它端口(23333),只需在服务端启动命令后面添加--port=23333

./sergate --config=config.json --web-dir=/www/wwwroot/default —-port=23333

开机自启

vi /etc/rc.d/rc.local

文尾另起一行插入
服务端自启

/home/ServerStatus/server/sergate --config=/home/ServerStatus/server/config.json --web-dir=/www/wwwroot/tz.zmkkb.com --port=23333 > /home/ServerStatus/server/server.log 2>&1 &

客户端自启

nohup /usr/bin/python2 -u /home/ServerStatus/clients/client-linux.py > /home/ServerStatus/clients/clients.log 2>&1 &

Centos7给予rc.local权限

chmod +x /etc/rc.d/rc.local

本文参考链接
ServerStatus中文版
91yunServerStatus

声明:吃蛋的小子|版权所有,违者必究|如未注明,均为原创|本网站采用BY-NC-SA协议进行授权

转载:转载请注明原文链接 - ServerStatus服务器探针


我,俺床,咱手机。