mirror of
https://github.com//cppla/ServerStatus
synced 2025-12-15 02:02:04 +08:00
Compare commits
36 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d5a047c781 | ||
|
|
10872059c5 | ||
|
|
44656e565f | ||
|
|
78c7da7361 | ||
|
|
b5edeea057 | ||
|
|
c2259f347d | ||
|
|
bb5f03047d | ||
|
|
6ab6e16d0f | ||
|
|
615cec88c2 | ||
|
|
94896bac80 | ||
|
|
a788b5da90 | ||
|
|
de0bc9dd74 | ||
|
|
ec16fc1fac | ||
|
|
cbd803b686 | ||
|
|
3eddb27d51 | ||
|
|
522809483e | ||
|
|
9d706f4da8 | ||
|
|
a0fe8ee33c | ||
|
|
c5eed8e4fa | ||
|
|
32d302580e | ||
|
|
b03d090a5c | ||
|
|
6151806141 | ||
|
|
2703993272 | ||
|
|
022e5edb28 | ||
|
|
135eb180c8 | ||
|
|
2ead43a0d8 | ||
|
|
baae11de3b | ||
|
|
2e62ffa593 | ||
|
|
f70705d872 | ||
|
|
7316dbdddb | ||
|
|
a1689acbf0 | ||
|
|
e2a59a5465 | ||
|
|
962d564c80 | ||
|
|
77973a5309 | ||
|
|
a9128b137d | ||
|
|
0a2a007e24 |
@@ -3,7 +3,7 @@ FROM debian:buster as builder
|
||||
|
||||
MAINTAINER cppla https://cpp.la
|
||||
|
||||
RUN apt-get update -y && apt-get -y install gcc g++ make
|
||||
RUN apt-get update -y && apt-get -y install gcc g++ make libcurl4-openssl-dev
|
||||
|
||||
COPY . .
|
||||
|
||||
@@ -20,6 +20,10 @@ RUN mkdir -p /ServerStatus/server/
|
||||
COPY --from=builder server /ServerStatus/server/
|
||||
COPY --from=builder web /usr/share/nginx/html/
|
||||
|
||||
# china time
|
||||
ENV TZ=Asia/Shanghai
|
||||
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||||
|
||||
EXPOSE 80 35601
|
||||
|
||||
CMD nohup sh -c '/etc/init.d/nginx start && /ServerStatus/server/sergate --config=/ServerStatus/server/config.json --web-dir=/usr/share/nginx/html'
|
||||
CMD nohup sh -c '/etc/init.d/nginx start && /ServerStatus/server/sergate --config=/ServerStatus/server/config.json --web-dir=/usr/share/nginx/html'
|
||||
|
||||
100
README.md
100
README.md
@@ -3,14 +3,14 @@
|
||||
* ServerStatus中文版是一个酷炫高逼格的云探针、云监控、服务器云监控、多服务器探针~。
|
||||
* 在线演示:https://tz.cloudcpp.com
|
||||
|
||||
[](https://github.com/cppla/ServerStatus)
|
||||
[](https://github.com/cppla/ServerStatus)
|
||||
[](https://github.com/cppla/ServerStatus)
|
||||
[](https://github.com/cppla/ServerStatus)
|
||||
[](https://github.com/cppla/ServerStatus)
|
||||
[](https://github.com/cppla/ServerStatus)
|
||||
|
||||

|
||||

|
||||
|
||||
`curl -sSL https://get.docker.com/ | sh && apt -y install docker-compose`
|
||||
`Watchdog🐶已经加入,触发式告警。 interval只是为了防止频繁收到报警信息造成骚扰,并不是探测间隔。`
|
||||
|
||||
# 目录介绍:
|
||||
|
||||
@@ -26,15 +26,12 @@
|
||||
【服务端】:
|
||||
```bash
|
||||
|
||||
`OneTouch`:
|
||||
`Docker`:
|
||||
|
||||
wget --no-check-certificate -qO ~/serverstatus-config.json https://raw.githubusercontent.com/cppla/ServerStatus/master/server/config.json && mkdir ~/serverstatus-monthtraffic
|
||||
docker run -d --restart=always --name=serverstatus -v ~/serverstatus-config.json:/ServerStatus/server/config.json -v ~/serverstatus-monthtraffic:/usr/share/nginx/html/json -p 80:80 -p 35601:35601 cppla/serverstatus:latest
|
||||
|
||||
`ServerStatus`: docker-compose up -d
|
||||
|
||||
`ServerStatus with tgbot`: TG_CHAT_ID=你的电报ID TG_BOT_TOKEN=你的电报密钥 docker-compose -f docker-compose-telegram.yml up -d
|
||||
|
||||
`Docker-compose`: docker-compose up -d
|
||||
```
|
||||
|
||||
【客户端】:
|
||||
@@ -47,25 +44,32 @@ wget --no-check-certificate -qO client-linux.py 'https://raw.githubusercontent.c
|
||||
|
||||
# 手动安装教程:
|
||||
|
||||
【克隆代码】:
|
||||
```
|
||||
git clone https://github.com/cppla/ServerStatus.git
|
||||
```
|
||||
|
||||
【服务端配置】:
|
||||
**【服务端配置】**
|
||||
|
||||
一、生成服务端程序
|
||||
#### 一、生成服务端程序
|
||||
```
|
||||
cd ServerStatus/server
|
||||
make
|
||||
`Debian/Ubuntu`: apt-get -y install gcc g++ make libcurl4-openssl-dev
|
||||
`Centos/Redhat`: yum -y install gcc gcc-c++ make libcurl-devel
|
||||
|
||||
cd ServerStatus/server && make
|
||||
./sergate
|
||||
```
|
||||
如果没错误提示,OK,ctrl+c关闭;如果有错误提示,检查35601端口是否被占用
|
||||
|
||||
二、修改配置文件
|
||||
修改config.json文件,注意username, password的值需要和客户端对应一致
|
||||
#### 二、修改配置文件
|
||||
```diff
|
||||
! watchdog rule 可以为任何已知字段的表达式。
|
||||
! watchdog interval 最小通知间隔。
|
||||
! watchdog callback 可自定义为Get方法的URL,告警内容将拼接其后并发起回调。
|
||||
|
||||
! watchdog callback Telegram:https://api.telegram.org/bot你自己的密钥/sendMessage?parse_mode=HTML&disable_web_page_preview=true&chat_id=你自己的标识&text=
|
||||
! watchdog callback Server酱: https://sctapi.ftqq.com/你自己的密钥.send?title=ServerStatus&desp=
|
||||
! watchdog callback PushDeer: https://api2.pushdeer.com/message/push?pushkey=你自己的密钥&text=
|
||||
```
|
||||
{"servers":
|
||||
|
||||
```
|
||||
{
|
||||
"servers":
|
||||
[
|
||||
{
|
||||
"username": "s01",
|
||||
@@ -76,52 +80,56 @@ make
|
||||
"password": "USER_DEFAULT_PASSWORD",
|
||||
"monthstart": 1
|
||||
},
|
||||
],
|
||||
"watchdog":
|
||||
[
|
||||
{
|
||||
"name": "服务器负载高监控",
|
||||
"rule": "cpu>90&load_5>3",
|
||||
"interval": 600,
|
||||
"callback": "https://yourSMSurl"
|
||||
},
|
||||
{
|
||||
"name": "你可以组合任何已知字段的表达式",
|
||||
"rule": "(hdd_used/hdd_total)*100>95",
|
||||
"interval": 1800,
|
||||
"callback": "https://yourSMSurl"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
三、拷贝ServerStatus/status到你的网站目录
|
||||
#### 三、拷贝ServerStatus/status到你的网站目录
|
||||
例如:
|
||||
```
|
||||
sudo cp -r ServerStatus/web/* /home/wwwroot/default
|
||||
```
|
||||
|
||||
四、运行服务端:
|
||||
#### 四、运行服务端:
|
||||
web-dir参数为上一步设置的网站根目录,务必修改成自己网站的路径
|
||||
```
|
||||
./sergate --config=config.json --web-dir=/home/wwwroot/default
|
||||
```
|
||||
|
||||
【客户端配置】:
|
||||
**【客户端配置】**
|
||||
|
||||
客户端有两个版本,client-linux为普通linux,client-psutil为跨平台版,普通版不成功,换成跨平台版即可。
|
||||
|
||||
一、client-linux版配置:
|
||||
#### 一、client-linux版配置:
|
||||
1、vim client-linux.py, 修改SERVER地址,username帐号, password密码
|
||||
2、python3 client-linux.py 运行即可。
|
||||
|
||||
二、client-psutil版配置:
|
||||
1、安装psutil跨平台依赖库
|
||||
#### 二、client-psutil版配置:
|
||||
1、安装psutil跨平台依赖库
|
||||
```
|
||||
`Debian/Ubuntu`: apt -y install python3-pip && pip3 install psutil
|
||||
`Centos/Redhat`: yum -y install python3-pip gcc python3-devel && pip3 install psutil
|
||||
`Windows`: https://pypi.org/project/psutil/
|
||||
```
|
||||
2、vim client-psutil.py, 修改SERVER地址,username帐号, password密码
|
||||
3、python3 client-psutil.py 运行即可。
|
||||
```
|
||||
### for Centos:
|
||||
sudo yum -y install epel-release
|
||||
sudo yum -y install python3-pip
|
||||
sudo yum clean all
|
||||
sudo yum -y install gcc
|
||||
sudo yum -y install python3-devel
|
||||
sudo pip3 install psutil
|
||||
3、python3 client-psutil.py 运行即可。
|
||||
|
||||
### for Ubuntu/Debian:
|
||||
sudo apt -y install python3-pip
|
||||
sudo pip3 install psutil
|
||||
|
||||
### for Windows:
|
||||
地址:https://pypi.org/project/psutil/
|
||||
下载psutil for windows, 安装即可
|
||||
```
|
||||
|
||||
打开云探针页面,就可以正常的监控。接下来把服务器和客户端脚本自行加入开机启动,或者进程守护,或以后台方式运行即可!例如: nohup python3 client-linux.py &
|
||||
服务器和客户端自行加入开机启动,或进程守护,或后台方式运行。 例如: nohup python3 client-linux.py &
|
||||
|
||||
`extra scene (run web/ssview.py)`
|
||||

|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
# coding: utf-8
|
||||
# Update by : https://github.com/cppla/ServerStatus, Update date: 20220323
|
||||
# 版本:1.0.3, 支持Python版本:2.7 to 3.9
|
||||
# Update by : https://github.com/cppla/ServerStatus, Update date: 20220530
|
||||
# 版本:1.0.3, 支持Python版本:2.7 to 3.10
|
||||
# 支持操作系统: Linux, OSX, FreeBSD, OpenBSD and NetBSD, both 32-bit and 64-bit architectures
|
||||
# 说明: 默认情况下修改server和user就可以了。丢包率监测方向可以自定义,例如:CU = "www.facebook.com"。
|
||||
|
||||
@@ -310,7 +310,7 @@ def get_realtime_data():
|
||||
target=_disk_io,
|
||||
)
|
||||
for ti in [t1, t2, t3, t4, t5]:
|
||||
ti.setDaemon(True)
|
||||
ti.daemon = True
|
||||
ti.start()
|
||||
|
||||
def byte_str(object):
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#!/usr/bin/env python3
|
||||
# coding: utf-8
|
||||
# Update by : https://github.com/cppla/ServerStatus, Update date: 20220323
|
||||
# Update by : https://github.com/cppla/ServerStatus, Update date: 20220530
|
||||
# 依赖于psutil跨平台库
|
||||
# 版本:1.0.3, 支持Python版本:2.7 to 3.9
|
||||
# 版本:1.0.3, 支持Python版本:2.7 to 3.10
|
||||
# 支持操作系统: Linux, Windows, OSX, Sun Solaris, FreeBSD, OpenBSD and NetBSD, both 32-bit and 64-bit architectures
|
||||
# 说明: 默认情况下修改server和user就可以了。丢包率监测方向可以自定义,例如:CU = "www.facebook.com"。
|
||||
|
||||
@@ -280,7 +280,7 @@ def get_realtime_data():
|
||||
target=_disk_io,
|
||||
)
|
||||
for ti in [t1, t2, t3, t4, t5]:
|
||||
ti.setDaemon(True)
|
||||
ti.daemon = True
|
||||
ti.start()
|
||||
|
||||
def byte_str(object):
|
||||
|
||||
@@ -6,7 +6,7 @@ CFLAGS = -Wall -O2
|
||||
|
||||
#CXX = clang++
|
||||
CXX = g++
|
||||
CXXFLAGS = -Wall -O2
|
||||
CXXFLAGS = -Wall -O2 -std=c++11
|
||||
|
||||
ODIR = obj
|
||||
SDIR = src
|
||||
@@ -26,7 +26,7 @@ $(ODIR)/%.o: $(SDIR)/%.cpp
|
||||
$(CXX) -c $(INC) $(CXXFLAGS) $< -o $@
|
||||
|
||||
$(OUT): $(OBJS)
|
||||
$(CXX) $(LIBS) $^ -o $(OUT)
|
||||
$(CXX) $(LIBS) $^ -o $(OUT) -lcurl
|
||||
|
||||
.PHONY: clean
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{"servers":
|
||||
[
|
||||
{
|
||||
"servers": [
|
||||
{
|
||||
"username": "s01",
|
||||
"name": "node1",
|
||||
@@ -37,5 +37,31 @@
|
||||
"password": "USER_DEFAULT_PASSWORD",
|
||||
"monthstart": 1
|
||||
}
|
||||
],
|
||||
"watchdog": [
|
||||
{
|
||||
"name": "cpu high warning",
|
||||
"rule": "cpu>98",
|
||||
"interval": 600,
|
||||
"callback": "https://yourSMSurl"
|
||||
},
|
||||
{
|
||||
"name": "memory high warning",
|
||||
"rule": "(memory_used/memory_total)*100>90",
|
||||
"interval": 600,
|
||||
"callback": "https://yourSMSurl"
|
||||
},
|
||||
{
|
||||
"name": "offline warning",
|
||||
"rule": "online4=0&online6=0",
|
||||
"interval": 300,
|
||||
"callback": "https://yourSMSurl"
|
||||
},
|
||||
{
|
||||
"name": "you can parse an expression combining any known field",
|
||||
"rule": "load_5>10",
|
||||
"interval": 1800,
|
||||
"callback": "https://yourSMSurl"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
40746
server/src/exprtk.hpp
Normal file
40746
server/src/exprtk.hpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -7,6 +7,8 @@
|
||||
#include <json.h>
|
||||
#include "server.h"
|
||||
#include "main.h"
|
||||
#include "exprtk.hpp"
|
||||
#include "curl/curl.h"
|
||||
|
||||
#if defined(CONF_FAMILY_UNIX)
|
||||
#include <signal.h>
|
||||
@@ -96,6 +98,13 @@ void CMain::OnDelClient(int ClientNetID)
|
||||
{
|
||||
int ClientID = ClientNetToClient(ClientNetID);
|
||||
dbg_msg("main", "OnDelClient(ncid=%d, cid=%d)", ClientNetID, ClientID);
|
||||
//copy offline message for watchdog
|
||||
WatchdogMessage(ClientNetID,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0,0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0,0, 0, 0,
|
||||
0, 0, 0, 0);
|
||||
if(ClientID >= 0 && ClientID < NET_MAX_CLIENTS)
|
||||
{
|
||||
Client(ClientID)->m_Connected = false;
|
||||
@@ -191,6 +200,19 @@ int CMain::HandleMessage(int ClientNetID, char *pMessage)
|
||||
if(rStart["custom"].type == json_string)
|
||||
str_copy(pClient->m_Stats.m_aCustom, rStart["custom"].u.string.ptr, sizeof(pClient->m_Stats.m_aCustom));
|
||||
|
||||
//copy message for watchdog to analysis
|
||||
WatchdogMessage(ClientNetID,
|
||||
pClient->m_Stats.m_Load_1, pClient->m_Stats.m_Load_5, pClient->m_Stats.m_Load_15,
|
||||
pClient->m_Stats.m_ping_10010, pClient->m_Stats.m_ping_189, pClient->m_Stats.m_ping_10086,
|
||||
pClient->m_Stats.m_time_10010, pClient->m_Stats.m_time_189, pClient->m_Stats.m_time_10086,
|
||||
pClient->m_Stats.m_tcpCount, pClient->m_Stats.m_udpCount, pClient->m_Stats.m_processCount,
|
||||
pClient->m_Stats.m_threadCount, pClient->m_Stats.m_NetworkRx, pClient->m_Stats.m_NetworkTx,
|
||||
pClient->m_Stats.m_NetworkIN, pClient->m_Stats.m_NetworkOUT,pClient->m_Stats.m_MemTotal,
|
||||
pClient->m_Stats.m_MemUsed, pClient->m_Stats.m_SwapTotal, pClient->m_Stats.m_SwapUsed,
|
||||
pClient->m_Stats.m_HDDTotal, pClient->m_Stats.m_HDDUsed, pClient->m_Stats.m_IORead,
|
||||
pClient->m_Stats.m_IOWrite, pClient->m_Stats.m_CPU, pClient->m_Stats.m_Online4,
|
||||
pClient->m_Stats.m_Online6);
|
||||
|
||||
if(m_Config.m_Verbose)
|
||||
{
|
||||
if(rStart["online4"].type)
|
||||
@@ -234,6 +256,111 @@ int CMain::HandleMessage(int ClientNetID, char *pMessage)
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void CMain::WatchdogMessage(int ClientNetID, double load_1, double load_5, double load_15, double ping_10010, double ping_189, double ping_10086,
|
||||
double time_10010, double time_189, double time_10086, double tcp, double udp, double process, double thread,
|
||||
double network_rx, double network_tx, double network_in, double network_out, double memory_total, double memory_used,
|
||||
double swap_total, double swap_used, double hdd_total, double hdd_used, double io_read, double io_write, double cpu,
|
||||
double online4, double online6)
|
||||
{
|
||||
int ID = 0;
|
||||
while (strcmp(Watchdog(ID)->m_aName, "NULL"))
|
||||
{
|
||||
typedef exprtk::symbol_table<double> symbol_table_t;
|
||||
typedef exprtk::expression<double> expression_t;
|
||||
typedef exprtk::parser<double> parser_t;
|
||||
const std::string expression_string = Watchdog(ID)->m_aRule;
|
||||
|
||||
symbol_table_t symbol_table;
|
||||
symbol_table.add_variable("load_1",load_1);
|
||||
symbol_table.add_variable("load_5",load_5);
|
||||
symbol_table.add_variable("load_15",load_15);
|
||||
symbol_table.add_variable("ping_10010",ping_10010);
|
||||
symbol_table.add_variable("ping_189",ping_189);
|
||||
symbol_table.add_variable("ping_10086",ping_10086);
|
||||
symbol_table.add_variable("time_10010",time_10010);
|
||||
symbol_table.add_variable("time_189",time_189);
|
||||
symbol_table.add_variable("time_10086",time_10086);
|
||||
symbol_table.add_variable("tcp",tcp);
|
||||
symbol_table.add_variable("udp",udp);
|
||||
symbol_table.add_variable("process",process);
|
||||
symbol_table.add_variable("thread",thread);
|
||||
symbol_table.add_variable("network_rx",network_rx);
|
||||
symbol_table.add_variable("network_tx",network_tx);
|
||||
symbol_table.add_variable("network_in",network_in);
|
||||
symbol_table.add_variable("network_out",network_out);
|
||||
symbol_table.add_variable("memory_total",memory_total);
|
||||
symbol_table.add_variable("memory_used",memory_used);
|
||||
symbol_table.add_variable("swap_total",swap_total);
|
||||
symbol_table.add_variable("swap_used",swap_used);
|
||||
symbol_table.add_variable("hdd_total",hdd_total);
|
||||
symbol_table.add_variable("hdd_used",hdd_used);
|
||||
symbol_table.add_variable("io_read",io_read);
|
||||
symbol_table.add_variable("io_write",io_write);
|
||||
symbol_table.add_variable("cpu",cpu);
|
||||
symbol_table.add_variable("online4",online4);
|
||||
symbol_table.add_variable("online6",online6);
|
||||
symbol_table.add_constants();
|
||||
|
||||
expression_t expression;
|
||||
expression.register_symbol_table(symbol_table);
|
||||
|
||||
parser_t parser;
|
||||
parser.compile(expression_string,expression);
|
||||
|
||||
if (expression.value() > 0)
|
||||
{
|
||||
int ClientID = ClientNetToClient(ClientNetID);
|
||||
time_t currentStamp = (long long)time(/*ago*/0);
|
||||
if ((currentStamp-Client(ClientID)->m_AlarmLastTime) > Watchdog(ID)->m_aInterval)
|
||||
{
|
||||
//todo 这里需要换成线程
|
||||
Client(ClientID)->m_AlarmLastTime = currentStamp;
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
//standard time
|
||||
char standardTime[32]= { 0 };
|
||||
strftime(standardTime, sizeof(standardTime), "%Y-%m-%d %H:%M:%S",localtime(¤tStamp));
|
||||
|
||||
//url encode
|
||||
char encodeBuffer[2048] = { 0 };
|
||||
sprintf(encodeBuffer, " \n\n【告警名称】 %s \n\n【告警规则】 %s \n\n【告警时间】 %s \n\n ---------------- \n\n【用户名】 %s \n\n【节点名】 %s \n\n【虚拟化】 %s \n\n【主机名】 %s \n\n【位 置】 %s",
|
||||
Watchdog(ID)->m_aName,
|
||||
Watchdog(ID)->m_aRule,
|
||||
standardTime,
|
||||
Client(ClientID)->m_aUsername,
|
||||
Client(ClientID)->m_aName,
|
||||
Client(ClientID)->m_aType,
|
||||
Client(ClientID)->m_aHost,
|
||||
Client(ClientID)->m_aLocation);
|
||||
char *encodeUrl = curl_easy_escape(curl, encodeBuffer, strlen(encodeBuffer));
|
||||
|
||||
//standard url
|
||||
char urlBuffer[2048] = { 0 };
|
||||
sprintf(urlBuffer, "%s%s",Watchdog(ID)->m_aCallback, encodeUrl);
|
||||
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_URL, urlBuffer);
|
||||
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 3L);
|
||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 6L);
|
||||
res = curl_easy_perform(curl);
|
||||
if(res != CURLE_OK)
|
||||
fprintf(stderr, "watchdog failed: %s\n", curl_easy_strerror(res));
|
||||
if(encodeUrl)
|
||||
curl_free(encodeUrl);
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
curl_global_cleanup();
|
||||
}
|
||||
}
|
||||
ID++;
|
||||
}
|
||||
}
|
||||
|
||||
void CMain::JSONUpdateThread(void *pUser)
|
||||
{
|
||||
CJSONUpdateThreadData *m_pJSONUpdateThreadData = (CJSONUpdateThreadData *)pUser;
|
||||
@@ -411,6 +538,28 @@ int CMain::ReadConfig()
|
||||
}
|
||||
}
|
||||
|
||||
// watch dog
|
||||
// support by: https://cpp.la
|
||||
ID = 0;
|
||||
const json_value &jStart = (*pJsonData)["watchdog"];
|
||||
if(jStart.type == json_array)
|
||||
{
|
||||
for(unsigned i = 0; i < jStart.u.array.length; i++)
|
||||
{
|
||||
if(ID < 0 || ID >= NET_MAX_CLIENTS)
|
||||
continue;
|
||||
|
||||
str_copy(Watchdog(ID)->m_aName, jStart[i]["name"].u.string.ptr, sizeof(Watchdog(ID)->m_aName));
|
||||
str_copy(Watchdog(ID)->m_aRule, jStart[i]["rule"].u.string.ptr, sizeof(Watchdog(ID)->m_aRule));
|
||||
Watchdog(ID)->m_aInterval = jStart[i]["interval"].u.integer;
|
||||
str_copy(Watchdog(ID)->m_aCallback, jStart[i]["callback"].u.string.ptr, sizeof(Watchdog(ID)->m_aCallback));
|
||||
|
||||
ID++;
|
||||
}
|
||||
str_copy(Watchdog(ID)->m_aName, "NULL", sizeof(Watchdog(ID)->m_aName));
|
||||
} else
|
||||
str_copy(Watchdog(ID)->m_aName, "NULL", sizeof(Watchdog(ID)->m_aName));
|
||||
|
||||
// if file exists, read last network traffic record,reset m_LastNetworkIN and m_LastNetworkOUT
|
||||
// support by: https://cpp.la
|
||||
IOHANDLE nFile = io_open(m_Config.m_aJSONFile, IOFLAG_READ);
|
||||
@@ -566,3 +715,4 @@ int main(int argc, const char *argv[])
|
||||
|
||||
return RetVal;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,10 +38,11 @@ class CMain
|
||||
char m_aPassword[128];
|
||||
int m_aMonthStart; //track month network traffic. by: https://cpp.la
|
||||
|
||||
int64_t m_LastNetworkIN;
|
||||
int64_t m_LastNetworkOUT;
|
||||
int64 m_TimeConnected;
|
||||
int64 m_LastUpdate;
|
||||
int64_t m_LastNetworkIN; //restore month traffic info.
|
||||
int64_t m_LastNetworkOUT; //restore month traffic info.
|
||||
int64_t m_TimeConnected;
|
||||
int64_t m_LastUpdate;
|
||||
int64_t m_AlarmLastTime; //record last alarm time.
|
||||
|
||||
struct CStats
|
||||
{
|
||||
@@ -82,6 +83,13 @@ class CMain
|
||||
} m_Stats;
|
||||
} m_aClients[NET_MAX_CLIENTS];
|
||||
|
||||
struct CWatchDog{
|
||||
char m_aName[128];
|
||||
char m_aRule[128];
|
||||
int m_aInterval;
|
||||
char m_aCallback[1024];
|
||||
} m_aCWatchDogs[NET_MAX_CLIENTS];
|
||||
|
||||
struct CJSONUpdateThreadData
|
||||
{
|
||||
CClient *pClients;
|
||||
@@ -99,6 +107,14 @@ public:
|
||||
int ReadConfig();
|
||||
int Run();
|
||||
|
||||
CWatchDog *Watchdog(int ruleID) { return &m_aCWatchDogs[ruleID]; }
|
||||
void WatchdogMessage(int ClientNetID,
|
||||
double load_1, double load_5, double load_15, double ping_10010, double ping_189, double ping_10086,
|
||||
double time_10010, double time_189, double time_10086, double tcp, double udp, double process, double thread,
|
||||
double network_rx, double network_tx, double network_in, double network_out,double memory_total,
|
||||
double memory_used,double swap_total, double swap_used, double hdd_total,
|
||||
double hdd_used, double io_read, double io_write, double cpu,double online4, double online6);
|
||||
|
||||
CClient *Client(int ClientID) { return &m_aClients[ClientID]; }
|
||||
CClient *ClientNet(int ClientNetID);
|
||||
const CConfig *Config() const { return &m_Config; }
|
||||
|
||||
@@ -22,7 +22,7 @@ tr.odd.expandRow > :hover { background: #212e36 !important; }
|
||||
#cpu, #ram, #hdd { min-width: 45px; max-width: 90px; }
|
||||
#ping { max-width: 95px; }
|
||||
|
||||
@media only screen and (max-width: 1080px) {
|
||||
@media only screen and (max-width: 1200px) {
|
||||
#type, tr td:nth-child(4) { display:none; visibility:hidden; }
|
||||
#location, tr td:nth-child(5) { display:none; visibility:hidden; }
|
||||
#uptime, tr td:nth-child(6) { display:none; visibility:hidden; }
|
||||
|
||||
@@ -19,7 +19,7 @@ tr.odd.expandRow > :hover { background: #FFF !important; }
|
||||
#cpu, #ram, #hdd { min-width: 45px; max-width: 90px; }
|
||||
#ping { max-width: 95px; }
|
||||
|
||||
@media only screen and (max-width: 1080px) {
|
||||
@media only screen and (max-width: 1200px) {
|
||||
#type, tr td:nth-child(4) { display:none; visibility:hidden; }
|
||||
#location, tr td:nth-child(5) { display:none; visibility:hidden; }
|
||||
#uptime, tr td:nth-child(6) { display:none; visibility:hidden; }
|
||||
|
||||
Reference in New Issue
Block a user