哪吒监控
项目地址:https://github.com/naiba/nezha
安装宝塔
宝塔就不多介绍了,如果不懂请自行百度或谷歌
一键安装宝塔:
curl -sSO http://download.bt.cn/install/install_panel.sh && bash install_panel.sh
解析域名
准备两个域名,一个用于哪吒监控面板(可以套CDN,比如cf的),一个用于面板和被监控服务器之间的通信(不可以套用CDN)
举例如下:
监控面板用到的:nz.idcfq.com,解析到面板服务器 ;通信用到的:nzz.idcfq.com ,解析到被监控的小鸡,当然不打算用域名进行访问,直接用IP也行,按照项目教程很快也能完成。
创建Oauth2 应用,以供授权
注册github账号或者gitee账号,并记下用户名(username)备用,本教程选择GitHub:https://github.com/
在 https://github.com/settings/developers 创建应用
填入面板域名:
https://nz.idcfq.com https://nzz.idcfq.com/oauth2/callback
记录下Client ID和Client secrets,备用
安装哪吒监控面板
国外机
curl -L https://raw.githubusercontent.com/naiba/nezha/master/script/install.sh -o nezha.sh && chmod +x nezha.sh sudo ./nezha.sh
国内镜像加速
curl -L https://cdn.jsdelivr.net/gh/naiba/nezha@master/script/install.sh -o nezha.sh && chmod +x nezha.sh CN=true sudo ./nezha.sh
选择1,安装面板端,参数配置一下:GitHub用户名,Client ID和Client secrets,端口可以默认,也可以自己设置,标题随意支持中文。
反代哪吒监控
首先登陆宝塔面板并登录账号,不想登录的可以用下面的代码跳过宝塔强制登录,不过,建议登录一下宝塔账号。
echo "{\"uid\":1000,\"username\":\"admin\",\"serverid\":1}" > /www/server/panel/data/userInfo.json
给哪吒监控面板配置一下SSL证书,网站设置里随意添加一个向代理,然后修改这个反向代理的配置文件为下面的:
location / { proxy_pass http://127.0.0.1:8008; proxy_set_header Host $host; } location /ws { proxy_pass http://127.0.0.1:8008; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; proxy_set_header Host $host; } location /terminal { proxy_pass http://127.0.0.1:8008; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; proxy_set_header Host $host; }
添加被控端
下面就是在要被监控的服务器上安装被控端了
访问 nz.idcfq.com,授权github登录哪吒监控面板,管理后台,添加主机,添加好之后记录一下密钥备用。
国外机
curl -L https://raw.githubusercontent.com/naiba/nezha/master/script/install.sh -o nezha.sh && chmod +x nezha.sh sudo ./nezha.sh
国内镜像加速
curl -L https://cdn.jsdelivr.net/gh/naiba/nezha@master/script/install.sh -o nezha.sh && chmod +x nezha.sh CN=true sudo ./nezha.sh
选择8,安装被控端,按要求输入配置命令,请输入一个解析到面板所在IP的域名(不可套CDN) 输入的就是通信域名 nzz.idcfq.com ,配置面板端口和密钥。
配置完成后,再去哪吒面板就能看到刚刚添加的小鸡已经上线了
配置tgbot
哪吒面板,顶部导航栏,点报警,添加通知方式
https://api.telegram.org/botXXXXXX/sendMessage?chat_id=YYYYYY&text=#NEZHA#
参数获取说明:botXXXXXX 中的 XXXXXX 是在 telegram 中关注官方 @Botfather ,输入/newbot ,创建新的机器人(bot)时,会提供的 token(在提示 Use this token to access the HTTP API:后面一行)这里 ‘bot’ 三个字母不可少。创建 bot 后,需要先在 telegram 中与 BOT 进行对话(随便发个消息),然后才可用 API 发送消息。YYYYYY 是 telegram 用户的数字 ID。与机器人@userinfobot 对话可获得。
然后添加,报警规则,以下表示小鸡离线10s后就会报警通知到tgbot
[{"Type":"offline","Duration":10}]
详细的报警规则设置见下方
基本规则
type
cpu、memory、swap、disk
net_in_speed 入站网速、net_out_speed 出站网速、net_all_speed 双向网速、transfer_in 入站流量、transfer_out 出站流量、transfer_all 双向流量
offline 离线监控
load1、load5、load15 负载
process_count 进程数 目前取线程数占用资源太多,暂时不支持
tcp_conn_count、udp_conn_count 连接数
duration:持续秒数,秒数内采样记录 30% 以上触发阈值才会报警(防数据插针)
min/max
流量、网速类数值 为字节(1KB=1024B,1MB = 1024*1024B)
内存、硬盘、CPU 为占用百分比
离线监控无需设置
cover [{“type”:”offline”,”duration”:10, “cover”:0, “ignore”:{“5”: true}}]
0 监控所有,通过 ignore 忽略特定服务器
1 忽略所有,通过 ignore 监控特定服务器
ignore: {“1”: true, “2”:false} 特定服务器,搭配 cover 使用
特殊:任意周期流量报警
可以用作月流量报警
type
transfer_in_cycle 周期内的入站流量
transfer_out_cycle 周期内的出站流量
transfer_all_cycle 周期内双向流量和
cycle_start 统计周期开始日期(可以是你机器计费周期的开始日期),RFC3339 时间格式,例如北京时间为2022-01-11T08:00:00.00+08:00
cycle_interval 每隔多少个周期单位(例如,周期单位为天,该值为 7,则代表每隔 7 天统计一次)
cycle_unit 统计周期单位,默认hour,可选(hour, day, week, month, year)
min/max、cover、ignore 参考基本规则配置
示例: ID 为 3 的服务器(ignore 里面定义),以每月 15 号为统计周期,周期内统计的出站月流量 达到 1TB 时报警 [{“type”:”transfer_out_cycle”,”max”:1000000000000,”cycle_start”:”2022-01-11T08:00:00.00+08:00″,”cycle_interval”:1,”cycle_unit”:”month”,”cover”:1,”ignore”:{“3”:true}}]
自定义主题
这一款哪吒监控透明主题,比较好看,搜集自网络
使用方法:用哪吒的默认主题,复制下方主题代码,粘贴到自定义代码里面保存即可
/* 屏幕适配 */ @media only screen and (min-width: 1200px) { .ui.container { width: 80% !important; } } @media only screen and (max-width: 767px) { .ui.card>.content>.header:not(.ui), .ui.cards>.card>.content>.header:not(.ui) { margin-top: 0.4em !important; } } /* 整体图标 */ i.icon { color: #000; width: 1.2em !important; } /* 背景图片 */ body { content: " " !important; background: fixed !important; z-index: -1 !important; top: 0 !important; right: 0 !important; bottom: 0 !important; left: 0 !important; background-position: top !important; background-repeat: no-repeat !important; background-size: cover !important; background-image: url(https://cdn.ii.do/gh/idarku/img@main/1631097904108.webp) !important; font-family: Arial,Helvetica,sans-serif !important; } /* 导航栏 */ .ui.large.menu { border: 0 !important; border-radius: 0px !important; background-color: rgba(255, 255, 255, 55%) !important; } /* 首页按钮 */ .ui.menu .active.item { background-color: transparent !important; } /* 导航栏下拉框 */ .ui.dropdown .menu { border: 0 !important; border-radius: 0 !important; background-color: rgba(255, 255, 255, 80%) !important; } /* 登陆按钮 */ .nezha-primary-btn { background-color: transparent !important; color: #000 !important; } /* 大卡片 */ #app .ui.fluid.accordion { background-color: #fbfbfb26 !important; border-radius: 0.4rem !important; } /* 小卡片 */ .ui.four.cards>.card { border-radius: 0.6rem !important; background-color: #fafafaa3 !important; } .status.cards .wide.column { padding-top: 0 !important; padding-bottom: 0 !important; height: 3.3rem !important; } .status.cards .three.wide.column { padding-right: 0rem !important; } .status.cards .wide.column:nth-child(1) { margin-top: 2rem !important; } .status.cards .wide.column:nth-child(2) { margin-top: 2rem !important; } .status.cards .description { padding-bottom: 0 !important; } /* 小鸡名 */ .status.cards .flag { margin-right: 0.5rem !important; } /* 弹出卡片图标 */ .status.cards .header > .info.icon { margin-right: 0 !important; } .nezha-secondary-font { color: #21ba45 !important; } /* 进度条 */ .ui.progress { border-radius: 50rem !important; } .ui.progress .bar { min-width: 1.8em !important; border-radius: 15px !important; line-height: 1.65em !important; } .ui.fine.progress> .bar { background-color: #21ba45 !important; } .ui.progress> .bar { background-color: #000 !important; } .ui.progress.fine .bar { background-color: #21ba45 !important; } .ui.progress.warning .bar { background-color: #ff9800 !important; } .ui.progress.error .bar { background-color: #e41e10 !important; } .ui.progress.offline .bar { background-color: #000 !important; } /* 上传下载 */ .status.cards .outline.icon { margin-right: 1px !important; } i.arrow.alternate.circle.down.outline.icon { color: #21ba45 !important; } i.arrow.alternate.circle.up.outline.icon { color: red !important; } /* 弹出卡片小箭头 */ .ui.right.center.popup { margin: -3px 0 0 0.914286em !important; -webkit-transform-origin: left 50% !important; transform-origin: left 50% !important; } .ui.bottom.left.popup { margin-left: 1px !important; margin-top: 3px !important; } .ui.top.left.popup { margin-left: 0 !important; margin-bottom: 10px !important; } .ui.top.right.popup { margin-right: 0 !important; margin-bottom: 8px !important; } .ui.left.center.popup { margin: -3px .91428571em 0 0 !important; -webkit-transform-origin: right 50% !important; transform-origin: right 50% !important; } .ui.right.center.popup:before, .ui.left.center.popup:before { border: 0px solid #fafafaeb !important; background: #fafafaeb !important; } .ui.top.popup:before { border-color: #fafafaeb transparent transparent !important; } .ui.popup:before { border-color: #fafafaeb transparent transparent !important; } .ui.bottom.left.popup:before { border-radius: 0 !important; border: 1px solid transparent !important; border-color: #fafafaeb transparent transparent !important; background: #fafafaeb !important; -webkit-box-shadow: 0px 0px 0 0 #fafafaeb !important; box-shadow: 0px 0px 0 0 #fafafaeb !important; -webkit-tap-highlight-color: rgba(0,0,0,0) !important; } .ui.bottom.right.popup:before { border-radius: 0 !important; border: 1px solid transparent !important; border-color: #fafafaeb transparent transparent !important; background: #fafafaeb !important -webkit-box-shadow: 0px 0px 0 0 #fafafaeb !important; box-shadow: 0px 0px 0 0 #fafafaeb !important; -webkit-tap-highlight-color: rgba(0,0,0,0) !important; } .ui.top.left.popup:before { border-radius: 0 !important; border: 1px solid transparent !important; border-color: #fafafaeb transparent transparent !important; background: #fafafaeb !important; -webkit-box-shadow: 0px 0px 0 0 #fafafaeb !important; box-shadow: 0px 0px 0 0 #fafafaeb !important; -webkit-tap-highlight-color: rgba(0,0,0,0) !important; } .ui.top.right.popup:before { border-radius: 0 !important; border: 1px solid transparent !important; border-color: #fafafaeb transparent transparent !important; background: #fafafaeb !important; -webkit-box-shadow: 0px 0px 0 0 #fafafaeb !important; box-shadow: 0px 0px 0 0 #fafafaeb !important; -webkit-tap-highlight-color: rgba(0,0,0,0) !important; } .ui.left.center.popup:before { border-radius: 0 !important; border: 1px solid transparent !important; border-color: #fafafaeb transparent transparent !important; background: #fafafaeb !important; -webkit-box-shadow: 0px 0px 0 0 #fafafaeb !important; box-shadow: 0px 0px 0 0 #fafafaeb !important; -webkit-tap-highlight-color: rgba(0,0,0,0) !important; } /* 弹出卡片 */ .status.cards .ui.content.popup { min-width: 20rem !important; line-height: 2rem !important; border-radius: 5px !important; border: 1px solid transparent !important; background-color: #fafafaeb !important; font-family: Arial,Helvetica,sans-serif !important; } .ui.content { margin: 0 !important; padding: 1em !important; } /* 服务页 */ .ui.table { background: RGB(225,225,225,0.6) !important; } .ui.table thead th { background: transparent !important; } /* 服务页进度条 */ .service-status .good { background-color: #21ba45 !important; } .service-status .danger { background-color: red !important; } .service-status .warning { background-color: orange !important; } /* 版权 */ .ui.inverted.segment, .ui.primary.inverted.segment { color: #000 !important; font-weight: bold !important; background-color: #fafafaa3 !important; } window.onload = function(){ var avatar=document.querySelector(".item img") var footer=document.querySelector("div.is-size-7") footer.innerHTML="奶妈监控面板 and 我扒的CSS" footer.style.visibility="visible" avatar.src="https://ii.do/favicon.ico" avatar.style.visibility="visible" }