ServerPapers 开源轻量级服务器监控工具

起因

之前用过一些服务器监控工具,但是有些配置复杂不够方便。也有些配置简单,但没有我想要显示的一些信息。所以我就花了三天时间自己写了一个开源的轻量级服务器监控工具。

项目

介绍

ServerPapers是一个基于Nodejs的轻量级服务器监控工具,主要利用了Socket.IO来向用户推送服务器的信息。

项目分为服务端和客户端,客户端将被监听的设备信息发送给服务端,服务端基于Express用于接收信息并在Web页面呈现出来。

其实这里还有一个Vite+Vue3的前端项目,来展示监听设备信息的Web页面。该项目单独测试完成后打包并集成到了服务端中。

如果用户想要自定义Web页面,可以修改这个Vite项目的源码或者自己另外写一个,然后将生成的html等文件导入到服务端的views目录中,而无需更改服务端代码。

服务端

ServerPapers服务端Github地址:CairBin/ServerPapers: ServerPapers is a lightweight server monitoring system. (github.com)

服务端主要用到的框架有 express 、Socket.IO,主页面会重定向至views/index.html

下面来讲解如何部署服务端

  • 首先通过git获取项目
git clone https://github.com/CairBin/ServerPapers.git
  • 如果出现网络问题也可以使用国内镜像
git clone https://gitcode.net/qq_42759112/ServerPapers.git
  • 项目部署需要用到pm2,请先全局安装该工具,其用法请参考官方文档。(如果是Linux环境的话全局使用pm2可能要建立软连接)
npm install -g pm2
  • 进入项目目录并安装依赖
cd ServerPapers && npm install
  • 修改项目配置文件config.js,该文件规定了项目启动的端口号,加密算法,以及客户端结点名称和验证口令等。
export default{
    host:{
        address:'localhost',
        port:8244
    },
    encryption:{
        algorithm:'aes-256-gcm',    //目前只支持aes-256-gcm
    },
    clients:[    //可以有多个客户端,请确保user和pwd与对应客户端配置一直
        {    
            name:'Test',    //结点名称唯一,重复会出问题
            user:'test',
            pwd:'123456'
        }
    ]
}
  • 利用pm2配置文件启动项目(默认重启,配置参考ecosystem.config.cjs配置文件)
pm2 start ecosystem.config.cjs
  • 如果想要停止项目可以运行以下命令
pm2 stop ecosystem.config.cjs
#或者
pm2 stop PaperServer

客户端

客户端Github地址 CairBin/ServerPapers-Client: This is the client of ServerPapers, used to send device status data to the server. (github.com)

客户端通过osUtils,systeminformation等第三方包获取设备硬件信息

客户端部署方法与服务端类似

  • 获取项目
git clone https://github.com/CairBin/ServerPapers-Client.git
#或者使用国内镜像
git clone https://gitcode.net/qq_42759112/ServerPapers-Client.git
  • 安装pm2
npm install -g pm2
  • 进入项目目录安装依赖
cd ServerPapers-Client && npm install
  • 配置config.js
export default{
    "serverUrl":"http://127.0.0.1:8244", //服务端URL
    "loginInfo":{
        "user":"test",
        "pwd":"123456"
    },
    "encryInfo":{
        "algorithm":"aes-256-gcm" //请与服务端一致
    }
}
  • 启动项目,注意客户端pm2配置文件中的autorestart字段默认false,也就是说不会自启重启,如有需要请手动修改
pm2 start ecosystem.config.cjs
  • 关闭项目
pm2 stop ecosystem.config.cjs
#或
pm2 stop ServerPapers-Client

Web

web页面使用Vite脚手架构建,用到的技术有

  • ElementPlus
  • Vue3
  • Socket.IO-Client
  • Vite
  • Axios (已经封装但未调用)

项目地址 CairBin/ServerPapers-Web: This is the web interface of ServerPapers, used to visualize server status information. (github.com)

项目演示

最后修改:2023 年 05 月 04 日
如果觉得我的文章对你有用,请随意赞赏