项目作者: qinchende

项目描述 :
服务器监控工具[n-sentinel]的客户端,部署在每一台需要监控的服务器上,收集服务器的当前状态信息。
高级语言: JavaScript
项目地址: git://github.com/qinchende/n-sentinel-client.git
创建时间: 2020-11-30T04:57:39Z
项目社区:https://github.com/qinchende/n-sentinel-client

开源协议:MIT License

下载


n-sentinel-client

这是服务器监控工具 [n-sentinel] 的客户端;目前用Node.js实现。

Client:n-sentinel-client

Server:n-sentinel-server

ManagerPages:n-sentinel-view

Requirements

Node.js v8 LTS or later.

请先确保你的服务器上安装了Node.js的可执行程序。

  1. whereis node
  2. node: /usr/local/bin/node
  3. # 如果你的路径不是这个,修改一下n_sentinel_alive.sh中的node路径

Quick start

下载源代码

在服务器 /opt 目录下下载源代码:

git clone https://github.com/qinchende/n-sentinel-client.git

或通过FTP工具把项目上传到服务器/opt目录下面

修改监听IP

  1. // vi app.js
  2. // 将host改成自己服务器的IP地址,将来server要通过host:port访问这个HTTP Server.
  3. // 为了 安全考虑,最好监听内网网卡。
  4. let Env = {
  5. host: '10.10.10.11',
  6. port: 49119,
  7. secret: 'n*sentinel*XYz'
  8. };

注意上面的secret字段需要修改一个随机的字符序列,clientserver段一致即可。

配置任务计划自动监控重启

  1. # cat n_sentinel_alive.sh
  2. # 在上面这个文件中有一句脚本,将其加入cronteb
  3. # */1 * * * * sh /opt/n-sentinel-client/n_sentinel_alive.sh >> /opt/n-sentinel-client/alive.log 2>&1 &
  4. # 使用命令:crontab -e ,加好之后保存退出即可。

这样服务器每一分钟都会检查node进程,如果没有了,就会自动重启。稍等片刻,在项目根目录你能看到两个日志文件:

  1. # cat alive.log
  2. [20201130_163401] CHECK ----------------
  3. [RE] n-sentinel-client done
  4. [20201130_163501] CHECK ----------------
  5. [S] n-sentinel-client exist
  6. # cat log.log
  7. Hi, I am the master process.
  8. Worker express listening on 10.10.10.11:49119 # 看到这个证明你client启动成功

到这里服务器上的收集程序就部署好了,他会一直等着server调用收集他的状态。