# httpNotify **Repository Path**: mengyun8/httpNotify ## Basic Information - **Project Name**: httpNotify - **Description**: notify http response to analysis CDN cache - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-06-04 - **Last Updated**: 2025-06-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # HTTP 流量分析工具 这是一个用于分析 HTTP 流量的工具,可以实时监控和统计网络接口的流量,并分析热门的 HTTP 资源。 ## 功能特性 ### 1. HTTP 资源分析 - 实时统计 HTTP 资源的访问情况 - 识别热门资源(基于访问频率和流量大小) - 支持资源访问量占比和流量占比分析 - 自动清理过期的统计数据 ### 2. 网络接口流量统计 - 实时监控指定网卡的流量 - 统计入站和出站字节数 - 统计入站和出站数据包数 - 实时计算带宽使用情况(入站/出站) - 支持多网卡同时监控 - 支持统计数据的重置 ## 安装 ### 前置要求 - Go 1.16 或更高版本 - Linux 操作系统(用于网卡监控) ### 安装步骤 1. 克隆仓库: ```bash git clone https://github.com/yourusername/httpNotify.git cd httpNotify ``` 2. 安装依赖: ```bash go mod download ``` 3. 编译: ```bash go build -o httpNotify ``` ## 使用方法 ### 基本使用 1. 启动分析器: ```bash ./httpNotify -interface eth0 -threshold 100 -window 3600 ``` 参数说明: - `-interface`: 要监控的网络接口名称 - `-threshold`: 热门资源阈值(访问次数) - `-window`: 统计时间窗口(秒) ### API 使用示例 ```go // 创建分析器实例 analyzer := NewHotResourceAnalyzer(100, time.Hour) // 分析数据包 analyzer.AnalyzePacket(packetData) // 更新网卡统计 analyzer.UpdateInterfaceStats("eth0", bytesIn, bytesOut, packetsIn, packetsOut) // 获取热门资源 hotResources := analyzer.GetHotResources() for _, resource := range hotResources { fmt.Printf("URL: %s, 访问次数: %d, 访问占比: %.2f%%\n", resource.URL, resource.Count, resource.VisitRatio) } // 获取网卡统计 stats := analyzer.GetInterfaceStats("eth0") if stats != nil { fmt.Printf("网卡 %s 统计:\n", stats.InterfaceName) fmt.Printf("入站流量: %d 字节\n", stats.BytesIn) fmt.Printf("出站流量: %d 字节\n", stats.BytesOut) fmt.Printf("入站数据包: %d\n", stats.PacketsIn) fmt.Printf("出站数据包: %d\n", stats.PacketsOut) fmt.Printf("入站带宽: %.2f MB/s\n", stats.BandwidthIn/1024/1024) fmt.Printf("出站带宽: %.2f MB/s\n", stats.BandwidthOut/1024/1024) } ``` ## 配置说明 ### 热门资源分析配置 - `threshold`: 访问次数阈值,超过此值被视为热门资源 - `window`: 统计时间窗口,超过此时间的数据会被清理 ### 网卡监控配置 - 支持同时监控多个网卡 - 可以随时添加或移除监控的网卡 - 支持统计数据的重置 - 实时计算带宽使用情况 ## 性能考虑 - 使用互斥锁保护并发访问 - 使用原子操作更新计数器 - 定期清理过期数据 - 支持高并发场景 - 带宽计算采用增量方式,减少资源占用 ## 注意事项 1. 需要 root 权限才能监控网卡流量 2. 建议定期清理统计数据,避免内存占用过大 3. 在生产环境中使用时,建议配置适当的日志级别 4. 网卡监控可能会影响系统性能,请根据实际情况调整监控频率 5. 带宽统计的准确性依赖于数据包捕获的频率,建议根据实际需求调整采样间隔 ## 贡献指南 欢迎提交 Issue 和 Pull Request 来帮助改进这个项目。 ## 许可证 MIT License