Skip to content

Commit 1ec8fcf

Browse files
update
from sliver branch
1 parent a30a4a2 commit 1ec8fcf

File tree

186 files changed

+17734
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

186 files changed

+17734
-1
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
build/
22
lib/
3-
include/

include/Telemeter.hpp

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#ifndef SRC_TELEMETER_H
2+
#define SRC_TELEMETER_H
3+
4+
#pragma once
5+
6+
#include <stdint.h>
7+
#include <cstring>
8+
9+
enum class LoadLevel : uint8_t
10+
{
11+
untapped = 0, //no client dispatched on this mirror
12+
light = 1, //[0% - 50%]
13+
medium = 2, //[50% - 80%]
14+
heavy = 3, //[ >= 80%]
15+
};
16+
17+
18+
//POD type
19+
struct DetailLoadState
20+
{
21+
uint8_t mem_load, serve_load, net_load_, reserve_seg_;
22+
};
23+
24+
void copy(DetailLoadState* dest, const DetailLoadState* sour)
25+
{ memcpy(dest, sour, sizeof(DetailLoadState)); }
26+
27+
#ifdef SRC_CENTER_H
28+
//center的setting, POD type
29+
struct Setting
30+
{
31+
uint8_t mir_load_record_interval_; //记录mirror负载到缓存的间隔(按照心跳包的个数来计数), 从配置文件中读
32+
uint8_t mir_dblog_interval_; //将mirror负载缓存更新到数据库(数据文件)的间隔(缓存了这么多之后打一次log), 从配置文件中读
33+
uint8_t mir_max_disbeat_time_; //多少个心跳轮无心跳视为断线
34+
uint8_t cli_login_cache_time_; //清空一个cli登录缓冲的时间
35+
};
36+
//第一字段为60表示一分钟(60个心跳包)记录一次mir的负载情况,
37+
//第二字段为5表示5分钟(缓存5次)输出到遥测数据库一次
38+
39+
const constexpr uint _permanent_thread_num_ = 3; //center的常驻线程数量
40+
41+
#endif
42+
43+
#ifdef SRC_MIRROR_H
44+
//mirror的setting, POD type
45+
struct Setting
46+
{
47+
int center_ip_;
48+
//int backup_center_ip_;
49+
uint8_t mir_beat_interval_;
50+
uint8_t //数据库ip?
51+
};
52+
53+
#endif
54+
55+
#define RESERVE_SEGMENG_INIT_VALUE 0
56+
57+
namespace telemeter
58+
{
59+
const constexpr char* klog_file = "TelemeterLog.txt"; //临时的遥测日志文件
60+
61+
#ifdef SRC_CENTER_H
62+
//双缓冲配置表解决一写多读线程安全问题
63+
Setting _set_cache_one = {60, 5, 15, 60};
64+
Setting _set_cache_two = {60, 5, 15, 60};
65+
//主要使用这个指针获取当前配置, 每次读取数据到第二个指针中, 然后交换两个指针的值
66+
Setting* setting = &_set_cache_one;
67+
Setting* setting_copy = &_set_cache_two;
68+
#endif
69+
70+
#ifdef SRC_MIRROR_H
71+
#endif
72+
73+
74+
75+
76+
//获取本机负载情况的函数, 需要统计空闲内存占比, cpu负载, 空闲磁盘占比
77+
LoadLevel getLocalLoadLevel();
78+
79+
//int getLocalMemLoad();
80+
//int getLocalSevLoad();
81+
//int getLocalNetLoad();
82+
}
83+
84+
85+
86+
87+
88+
89+
90+
91+
#endif //SRC_TELEMETER_H

include/Type.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef SRC_TYPE_H
2+
#define SRC_TYPE_H
3+
4+
#pragma once
5+
6+
#include "boost/lockfree/queue.hpp"
7+
template<typename T>
8+
using lfqueue = boost::lockfree::queue;
9+
10+
11+
12+
#endif //SRC_TYPE_H

include/Udp.hpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#ifndef SRC_UDP_H
2+
#define SRC_UDP_H
3+
4+
#pragma once
5+
6+
//暂时以int表示ip, 有需要则封装成类
7+
using IP = int;
8+
9+
namespace port
10+
{
11+
const constexpr int kCLI_LOGIN_ = 20800;
12+
const constexpr int kCLI_BEAT_ = 20801;
13+
const constexpr int kMIR_BEAT_ = 20802;
14+
const constexpr int kINS_MSG_ = 20803;
15+
}
16+
17+
namespace udp
18+
{
19+
void loop();
20+
21+
void recv();
22+
void send();
23+
}
24+
25+
26+
#endif //SRC_UDP_H
27+
28+
29+
30+
/*
31+
class IP
32+
{
33+
private:
34+
union //IP地址共占4个字节
35+
{
36+
struct //这是一个由4个字节构成的匿名结构体
37+
{
38+
unsigned char seg0;
39+
unsigned char seg1;
40+
unsigned char seg2;
41+
unsigned char seg3;
42+
}; //4字节的IP地址可以看作4部分,每部分1字节
43+
unsigned int address; //4字节的IP地址可以看成一个4字节的整体
44+
};
45+
public:
46+
IP(int=0,int=0,int=0,int=0); //构造函数
47+
void showIP(); //用四段法显示IP地址
48+
bool sameSubnet(const IP &ip, const IP &mark); //判断是否处于同一子网
49+
char whatKind(); //返回属于哪一类网络
50+
};
51+
52+
原文链接:https://blog.csdn.net/chongshangyunxiao321/article/details/51055658
53+
*/

0 commit comments

Comments
 (0)