15#include <unordered_map>
22#include "PayloadLayer.h"
23#include "PacketUtils.h"
24#include "SystemUtils.h"
29#include <clickhouse/client.h>
38#define MAX_QUEUE_LENGTH 20000
48#define WRITE_STAT_LINE(description, counter, measurement) \
53 <<measurement<< std::endl;
55using namespace clickhouse;
66 std::ofstream file(filename);
67 if (!file.is_open()) {
68 std::cerr <<
"Failed to open file: " << filename << std::endl;
149 col_tv_sec = std::make_shared<ColumnUInt32>();
153 col_ttl =std::make_shared<ColumnUInt8>();
154 col_tos =std::make_shared<ColumnUInt8>();
155 col_id =std::make_shared<ColumnUInt16>();
164 col_flag =std::make_shared<ColumnUInt16>();
270 block.AppendColumn(
"ttl",
col_ttl );
271 block.AppendColumn(
"tos",
col_tos );
272 block.AppendColumn(
"id",
col_id );
281 block.AppendColumn(
"flag",
col_flag );
289 block_src_ip.AppendColumn(
"srcIp",
col_src_ip);
293 Block block_protocol;
302 catch(
const std::exception& e)
304 std::cerr <<
"Insert failue.retrying... error msg:" <<e.what() <<
'\n';
310 catch(
const std::exception& e) {
311 std::cerr<<
"insert block failed!"<<std::endl;
318 client.Insert(
"_src_ip_hash_table", block_src_ip);
320 catch(
const std::exception& e)
322 std::cerr <<
"Insert failue.retrying... error msg:" <<e.what() <<
'\n';
326 client.Insert(
"_src_ip_hash_table", block_src_ip);
328 catch(
const std::exception& e)
330 std::cerr <<
"Insert failue and drop .error msg:" <<e.what() <<
'\n';
337 client.Insert(
"_protocol_hash_table", block_protocol);
339 catch(
const std::exception& e)
341 std::cerr <<
"Insert failue.retrying... error msg:" <<e.what() <<
'\n';
345 client.Insert(
"_protocol_hash_table", block_protocol);
347 catch(
const std::exception& e)
349 std::cerr <<
"Insert failue and drop .error msg:" <<e.what() <<
'\n';
HTTP统计信息收集器
Definition HttpStatsCollector.h:174
HttpGeneralStats & getGeneralStats()
获取HTTP通用统计信息
Definition HttpStatsCollector.h:290
HttpResponseStats & getResponseStats()
获取HTTP响应统计信息
Definition HttpStatsCollector.h:302
HttpRequestStats & getRequestStats()
获取HTTP请求统计信息
Definition HttpStatsCollector.h:296
std::shared_ptr< ColumnUInt16 > col_flag
标志位列
Definition packet_handler.h:131
std::shared_ptr< ColumnUInt32 > col_hash_val
哈希值列
Definition packet_handler.h:114
packet_handler(std::string tb_prefix="")
构造函数
Definition packet_handler.h:145
std::shared_ptr< ColumnString > col_src_ip
源IP地址列
Definition packet_handler.h:118
std::shared_ptr< ColumnUInt32 > col_seq_num
序列号列
Definition packet_handler.h:130
std::shared_ptr< ColumnUInt16 > col_offset
片偏移列
Definition packet_handler.h:123
int queue_len
当前队列长度
Definition packet_handler.h:109
std::shared_ptr< ColumnUInt16 > col_dst_port
目标端口列
Definition packet_handler.h:128
void send2db()
发送数据到数据库
Definition packet_handler.h:260
std::shared_ptr< ColumnUInt16 > col_window
窗口大小列
Definition packet_handler.h:132
void flush()
清空所有数据列
Definition packet_handler.h:229
std::shared_ptr< ColumnUInt16 > col_len_load
负载长度列
Definition packet_handler.h:126
std::shared_ptr< ColumnUInt8 > col_tos
TOS列
Definition packet_handler.h:121
std::shared_ptr< ColumnUInt16 > col_src_port
源端口列
Definition packet_handler.h:127
std::shared_ptr< ColumnUInt32 > col_tv_sec
时间戳秒数列(类型待确认)
Definition packet_handler.h:116
std::shared_ptr< ColumnUInt8 > col_protocol
传输层协议列
Definition packet_handler.h:125
std::shared_ptr< ColumnString > col_dst_ip
目标IP地址列
Definition packet_handler.h:119
std::shared_ptr< ColumnUInt32 > col_ack_num
确认号列
Definition packet_handler.h:129
HttpStatsCollector collector
HTTP统计收集器
Definition packet_handler.h:136
std::shared_ptr< ColumnInt32 > col_packet_len
包长度列(类型待确认)
Definition packet_handler.h:115
std::shared_ptr< ColumnUInt8 > col_ttl
TTL列
Definition packet_handler.h:120
~packet_handler()
析构函数
Definition packet_handler.h:176
std::shared_ptr< ColumnUInt8 > col_icmp_code
ICMP代码列
Definition packet_handler.h:135
std::shared_ptr< ColumnUInt32 > col_tv_nsec
时间戳纳秒数列
Definition packet_handler.h:117
std::shared_ptr< ColumnUInt16 > col_len_udp
UDP长度列
Definition packet_handler.h:133
Client client
ClickHouse客户端
Definition packet_handler.h:111
std::shared_ptr< ColumnUInt8 > col_icmp_type
ICMP类型列
Definition packet_handler.h:134
std::shared_ptr< ColumnUInt8 > col_protocol_ip
IP协议列
Definition packet_handler.h:124
std::string table_prefix
数据库表前缀
Definition packet_handler.h:110
void handle_packet(pcpp::Packet *packet)
处理函数
Definition packet_handler.h:186
std::shared_ptr< ColumnUInt16 > col_id
IP标识列
Definition packet_handler.h:122
包统一属性基类,表征了IPv4的IP到传输层大多数有用的属性
Definition unifiedPacketAttr.h:46
uint16_t len_load
负载长度
Definition unifiedPacketAttr.h:67
uint8_t protocol
传输层协议类型:TCP=0, UDP=1, ICMP=2
Definition unifiedPacketAttr.h:66
uint8_t icmp_type
ICMP类型
Definition unifiedPacketAttr.h:81
uint32_t ack_num
确认号(UDP无此字段)
Definition unifiedPacketAttr.h:70
uint16_t src_port
源端口(ICMP无此字段)
Definition unifiedPacketAttr.h:68
uint8_t protocol_ip
IP协议类型字段
Definition unifiedPacketAttr.h:63
uint8_t icmp_code
ICMP代码
Definition unifiedPacketAttr.h:82
uint32_t tv_sec
时间戳(秒)
Definition unifiedPacketAttr.h:51
uint16_t dst_port
目的端口(ICMP无此字段)
Definition unifiedPacketAttr.h:69
uint32_t packet_len
包长度
Definition unifiedPacketAttr.h:50
uint8_t tos
服务类型(Type of Service)
Definition unifiedPacketAttr.h:58
uint8_t ttl
生存时间(Time To Live)
Definition unifiedPacketAttr.h:57
uint16_t len_udp
UDP长度字段
Definition unifiedPacketAttr.h:78
uint16_t flag
TCP标志位
Definition unifiedPacketAttr.h:74
std::string dst_ip
目的IP地址
Definition unifiedPacketAttr.h:54
uint16_t window
TCP窗口大小
Definition unifiedPacketAttr.h:75
std::string src_ip
源IP地址
Definition unifiedPacketAttr.h:53
uint32_t tv_nsec
时间戳(纳秒)
Definition unifiedPacketAttr.h:52
uint32_t seq_num
序列号(UDP无此字段)
Definition unifiedPacketAttr.h:71
uint16_t id
IP标识字段
Definition unifiedPacketAttr.h:59
uint32_t hash_val
五元组计算的流ID
Definition unifiedPacketAttr.h:49
uint16_t offset
片偏移字段
Definition unifiedPacketAttr.h:60
void StatsSummary2File(HttpStatsCollector &collector, std::string filename)
将HTTP统计摘要写入文件
Definition packet_handler.h:64
#define MAX_QUEUE_LENGTH
最大队列长度(调整以获得最佳速度)
Definition packet_handler.h:38
#define WRITE_STAT_LINE(description, counter, measurement)
写入统计行的宏定义
Definition packet_handler.h:48
int numOfHttpPackets
HTTP包的总数
Definition HttpStatsCollector.h:56
double averageAmountOfDataPerFlow
每个流的平均HTTP流量
Definition HttpStatsCollector.h:60
double averageNumOfHttpTransactionsPerFlow
每个流的平均HTTP事务数
Definition HttpStatsCollector.h:55
double sampleTime
统计收集总时间
Definition HttpStatsCollector.h:62
Rate httpFlowRate
HTTP流的速率
Definition HttpStatsCollector.h:51
int amountOfHttpTraffic
HTTP流量总字节数
Definition HttpStatsCollector.h:59
int numOfHttpTransactions
HTTP事务的总数
Definition HttpStatsCollector.h:53
int numOfHttpFlows
HTTP流的总数
Definition HttpStatsCollector.h:50
int numOfHttpPipeliningFlows
包含至少一个HTTP管道化事务的HTTP流总数
Definition HttpStatsCollector.h:52
Rate httpTransactionsRate
HTTP事务的速率
Definition HttpStatsCollector.h:54
Rate httpTrafficRate
HTTP流量速率
Definition HttpStatsCollector.h:61
Rate httpPacketRate
HTTP包的速率
Definition HttpStatsCollector.h:57
double averageNumOfPacketsPerFlow
每个流的平均HTTP包数
Definition HttpStatsCollector.h:58
Rate messageRate
该类型HTTP消息的速率
Definition HttpStatsCollector.h:94
int numOfMessages
该类型HTTP消息的总数(请求/响应)
Definition HttpStatsCollector.h:93
double averageMessageHeaderSize
平均消息头大小
Definition HttpStatsCollector.h:96
int totalMessageHeaderSize
消息头的总大小(字节)
Definition HttpStatsCollector.h:95
int numOfMessagesWithContentLength
包含"content-length"字段的响应总数
Definition HttpStatsCollector.h:148
double averageContentLengthSize
平均正文大小
Definition HttpStatsCollector.h:150
int totalContentLengthSize
从包含"content-length"字段的响应中提取的总正文大小
Definition HttpStatsCollector.h:149
double totalRate
总体速率
Definition HttpStatsCollector.h:30