Documentation
¶
Overview ¶
Package statistics 测试报告生成
Package statistics HTML报告生成 ¶
Package statistics AI评分系统 ¶
Package statistics 统计数据
Index ¶
- Variables
- func AddTimeRecord(record TimeRecord)
- func FinalizeReport(successNum, failureNum uint64, ...)
- func GenerateHTMLReport(filepath string) error
- func GenerateMarkdownReport(filepath string) error
- func InitReportData(url string, concurrency uint64)
- func ReceivingResults(ctx context.Context, concurrent uint64, ch <-chan *model.RequestResults, ...)
- type AIConfig
- type AIMessage
- type AIRequest
- type AIResponse
- type ReportData
- type ResponseTimeDistribution
- type ScoreResult
- type TimeRecord
Constants ¶
This section is empty.
Variables ¶
View Source
var ( AIAPIEndpoint string AIAPIKey string AIModel string = "gpt-3.5-turbo" )
AI配置全局变量
View Source
var OutputFormat string = "html"
OutputFormat 报告格式: html(默认) 或 md
View Source
var OutputPath string
OutputPath 报告输出路径
View Source
var SuccessCode int = 200
SuccessCode 成功状态码(由 -code 参数指定)
Functions ¶
func FinalizeReport ¶ added in v1.0.18
func FinalizeReport(successNum, failureNum uint64, totalTime, qps, maxTime, minTime, avgTime float64, receivedBytes int64, errCode *sync.Map, requestTimeList []uint64)
FinalizeReport 完成报告数据
func GenerateHTMLReport ¶ added in v1.0.18
GenerateHTMLReport 生成HTML格式报告
func GenerateMarkdownReport ¶ added in v1.0.18
GenerateMarkdownReport 生成Markdown格式报告
func InitReportData ¶ added in v1.0.18
InitReportData 初始化报告数据
func ReceivingResults ¶
func ReceivingResults(ctx context.Context, concurrent uint64, ch <-chan *model.RequestResults, wg *sync.WaitGroup)
ReceivingResults 接收结果并处理 统计的时间都是纳秒,显示的时间 都是毫秒 concurrent 并发数
Types ¶
type AIResponse ¶ added in v1.0.18
type AIResponse struct {
Choices []struct {
Message struct {
Content string `json:"content"`
} `json:"message"`
} `json:"choices"`
Error *struct {
Message string `json:"message"`
} `json:"error,omitempty"`
}
AIResponse AI API响应结构
type ReportData ¶ added in v1.0.18
type ReportData struct {
URL string // 压测URL
Concurrency uint64 // 并发数
TotalRequests uint64 // 总请求数
SuccessNum uint64 // 成功数
FailureNum uint64 // 失败数
TotalTime float64 // 总耗时(秒)
QPS float64 // QPS
MaxTime float64 // 最大响应时间(ms)
MinTime float64 // 最小响应时间(ms)
AvgTime float64 // 平均响应时间(ms)
TP90 float64 // TP90(ms)
TP95 float64 // TP95(ms)
TP99 float64 // TP99(ms)
ReceivedBytes int64 // 下载字节数
ErrorCodeMap map[int]int // 错误码分布
TimeRecords []TimeRecord // 时间序列记录
RequestTimeList []uint64 // 请求时间列表
StartTime time.Time // 开始时间
EndTime time.Time // 结束时间
}
ReportData 报告数据结构
var CurrentReportData *ReportData
CurrentReportData 当前报告数据
type ResponseTimeDistribution ¶ added in v1.0.18
type ResponseTimeDistribution struct {
Labels []string `json:"labels"`
Values []int `json:"values"`
}
ResponseTimeDistribution 响应时间分布数据
type ScoreResult ¶ added in v1.0.18
type ScoreResult struct {
TotalScore int `json:"total_score"` // 总分 (0-100)
Grade string `json:"grade"` // 评级 (A/B/C/D/F)
SuccessRateScore int `json:"success_rate_score"` // 成功率得分
QPSScore int `json:"qps_score"` // QPS得分
AvgTimeScore int `json:"avg_time_score"` // 平均响应时间得分
TP99Score int `json:"tp99_score"` // TP99稳定性得分
ErrorCodeScore int `json:"error_code_score"` // 错误码得分
Suggestions []string `json:"suggestions"` // 改进建议
Details map[string]string `json:"details"` // 详细说明
}
ScoreResult 评分结果
func CalculateScore ¶ added in v1.0.18
func CalculateScore(data *ReportData) *ScoreResult
CalculateScore 计算内置评分
func CalculateScoreWithAI ¶ added in v1.0.18
func CalculateScoreWithAI(data *ReportData) (*ScoreResult, error)
CalculateScoreWithAI 使用外部AI API计算评分
type TimeRecord ¶ added in v1.0.18
type TimeRecord struct {
Timestamp time.Time // 记录时间点
Elapsed float64 // 耗时(秒)
Concurrent int // 并发数
Success uint64 // 成功数
Failure uint64 // 失败数
SuccessRate float64 // 成功率(%)
QPS float64 // QPS
MaxTime float64 // 最大响应时间(ms)
MinTime float64 // 最小响应时间(ms)
AvgTime float64 // 平均响应时间(ms)
ErrorCodes map[int]int // 错误码分布
}
TimeRecord 时间序列记录
Click to show internal directories.
Click to hide internal directories.