syntax = "proto3";
option go_package = "./pb";

package pb;

import "models/model_server_daily_stat.proto";
import "models/rpc_messages.proto";

// 服务统计相关服务
service ServerDailyStatService {
	// 上传统计
	rpc uploadServerDailyStats (UploadServerDailyStatsRequest) returns (RPCSuccess);

	// 按小时读取统计数据
	rpc findLatestServerHourlyStats (FindLatestServerHourlyStatsRequest) returns (FindLatestServerHourlyStatsResponse);

	// 按分钟读取统计数据
	rpc findLatestServerMinutelyStats (FindLatestServerMinutelyStatsRequest) returns (FindLatestServerMinutelyStatsResponse);

	// 按日读取统计数据
	rpc findLatestServerDailyStats (FindLatestServerDailyStatsRequest) returns (FindLatestServerDailyStatsResponse);
}

// 上传统计
message UploadServerDailyStatsRequest {
	repeated ServerDailyStat stats = 1;
	repeated DomainStat domainStats = 2;

	message DomainStat {
		int64 serverId = 1;
		string domain = 2;
		int64 bytes = 3;
		int64 cachedBytes = 4;
		int64 countRequests = 5;
		int64 countCachedRequests = 6;
		int64 countAttackRequests = 8;
		int64 attackBytes = 9;
		int64 createdAt = 7;
	}
}

// 按小时读取统计数据
message FindLatestServerHourlyStatsRequest {
	int64 serverId = 1;
	int32 hours = 2;
}

message FindLatestServerHourlyStatsResponse {
	repeated HourlyStat stats = 1;

	message HourlyStat {
		string hour = 1;
		int64 bytes = 2;
		int64 cachedBytes = 3;
		int64 countRequests = 4;
		int64 countCachedRequests = 5;
	}
}

// 按分钟读取统计数据
message FindLatestServerMinutelyStatsRequest {
	int64 serverId = 1;
	int32 minutes = 2;
}

message FindLatestServerMinutelyStatsResponse {
	repeated MinutelyStat stats = 1;

	message MinutelyStat {
		string minute = 1;
		int64 bytes = 2;
		int64 cachedBytes = 3;
		int64 countRequests = 4;
		int64 countCachedRequests = 5;
	}
}

// 按日读取统计数据
message FindLatestServerDailyStatsRequest {
	int64 serverId = 1;
	int32 days = 2;
}

message FindLatestServerDailyStatsResponse {
	repeated DailyStat stats = 1;

	message DailyStat {
		string day = 1;
		int64 bytes = 2;
		int64 cachedBytes = 3;
		int64 countRequests = 4;
		int64 countCachedRequests = 5;
	}
}