24.1 简介
负责接收各agent对某modid、cmdid下节点的调用状态的上报。
目前
agent我们还没有实现,就可以把agent当成一个普通客户端就可以。
agent会把代理的host节点的状态上报给Reporter,Reporter负责存储在Mysql数据库中。
业务:
Reporter服务模型采用了single thread TCP服务器 + 线程池处理请求
- 主线程Reporter负责接收agent请求,并根据请求中携带的
modid和cmdid,拼接后进行murmurHash(一致性hash),分配到某个线程的MQ上 - Thread 1~N们负责处理请求:把MQ上的请求中的数据同步更新到MySQL数据表
由于agent上报给Reporter的信息是携带时间的,且仅作为前台展示方便查看服务的过载情况,故通信仅有请求没有响应
于是Reporter服务只要可以高效读取请求即可,后端写数据库的实时性能要求不高。
架构图如下:
24.2 数据库创建
- 表
ServerCallStatus: | 字段 | 数据类型 | 是否可以为空 | 主键 | 默认 | 附加 | 说明 | | —- | —- | —- | —- | —- | —- | —- | | modid | int(11) | No | 是 | NULL | | 模块ID | | modid | int(11) | No | 是 | NULL | | 指令ID | | ip | int(11) | No | 是 | NULL | | 服务器IP地址 | | port | int(11) | No | 是 | NULL | | 服务器端口 | | caller | int(11) | No | 是 | NULL | | 调用者 | | succ_cnt | int(11) | No | | NULL | | 成功次数 | | err_cnt | int(11) | No | | NULL | | 失败次数 | | ts | bigint(20) | No | | NULL | | 记录时间 | | overload | char(1) | No | | NULL | | 是否过载 |
Lars/base/sql/lars_dns.sql
DROP TABLE IF EXISTS `ServerCallStatus`;CREATE TABLE `ServerCallStatus` (`modid` int(11) NOT NULL,`cmdid` int(11) NOT NULL,`ip` int(11) NOT NULL,`port` int(11) NOT NULL,`caller` int(11) NOT NULL,`succ_cnt` int(11) NOT NULL,`err_cnt` int(11) NOT NULL,`ts` bigint(20) NOT NULL,`overload` char(1) NOT NULL,PRIMARY KEY (`modid`,`cmdid`,`ip`,`port`,`caller`),KEY `mlb_index` (`modid`,`cmdid`,`ip`,`port`,`caller`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
24.3 Proto协议定义
Lars/base/proto/lars.proto
syntax = "proto3";package lars;/* Lars系统的消息ID */enum MessageId {ID_UNKNOW = 0; //proto3 enum第一个属性必须是0,用来占位ID_GetRouteRequest = 1; //向DNS请求Route对应的关系的消息IDID_GetRouteResponse = 2; //DNS回复的Route信息的消息IDID_ReportStatusRequest = 3; //上报host调用状态信息请求消息ID}//一个管理的主机的信息message HostInfo {int32 ip = 1;int32 port = 2;}//请求lars-dns route信息的消息内容message GetRouteRequest {int32 modid = 1;int32 cmdid = 2;}//lars-dns 回复的route信息消息内容message GetRouteResponse {int32 modid = 1;int32 cmdid = 2;repeated HostInfo host = 3;}message HostCallResult {int32 ip = 1; //主机ipint32 port = 2; //主机端口uint32 succ = 3; //调度成功uint32 err = 4; //调度失败bool overload = 5; //是否过载}//上报 负载均衡 调度数据 给 lars_reporter 的消息内容message ReportStatusReq {int32 modid = 1;int32 cmdid = 2;int32 caller = 3;repeated HostCallResult results = 4;uint32 ts = 5;}
