mirror of
https://github.com/chainreactors/spray.git
synced 2025-09-15 11:40:13 +00:00
优化stat, 添加了source的相关统计
This commit is contained in:
parent
b120d703b8
commit
880b11e860
@ -223,10 +223,12 @@ func (r *Runner) Prepare(ctx context.Context) error {
|
||||
}
|
||||
if r.Color {
|
||||
logs.Log.Important(pool.Statistor.ColorString())
|
||||
logs.Log.Important(pool.Statistor.ColorDetail())
|
||||
logs.Log.Important(pool.Statistor.ColorCountString())
|
||||
logs.Log.Important(pool.Statistor.ColorSourceString())
|
||||
} else {
|
||||
logs.Log.Important(pool.Statistor.String())
|
||||
logs.Log.Important(pool.Statistor.Detail())
|
||||
logs.Log.Important(pool.Statistor.CountString())
|
||||
logs.Log.Important(pool.Statistor.SourceString())
|
||||
}
|
||||
|
||||
if r.StatFile != nil {
|
||||
|
@ -17,6 +17,7 @@ func NewStatistor(url string) *Statistor {
|
||||
stat := DefaultStatistor
|
||||
stat.StartTime = time.Now().Unix()
|
||||
stat.Counts = make(map[int]int)
|
||||
stat.Sources = make(map[int]int)
|
||||
stat.BaseUrl = url
|
||||
return &stat
|
||||
}
|
||||
@ -30,6 +31,7 @@ func NewStatistorFromStat(origin *Statistor) *Statistor {
|
||||
RuleFiles: origin.RuleFiles,
|
||||
RuleFilter: origin.RuleFilter,
|
||||
Counts: make(map[int]int),
|
||||
Sources: map[int]int{},
|
||||
StartTime: time.Now().Unix(),
|
||||
}
|
||||
}
|
||||
@ -37,6 +39,7 @@ func NewStatistorFromStat(origin *Statistor) *Statistor {
|
||||
type Statistor struct {
|
||||
BaseUrl string `json:"url"`
|
||||
Counts map[int]int `json:"counts"`
|
||||
Sources map[int]int `json:"sources"`
|
||||
FailedNumber int32 `json:"failed"`
|
||||
ReqTotal int32 `json:"req_total"`
|
||||
CheckNumber int `json:"check"`
|
||||
@ -44,17 +47,16 @@ type Statistor struct {
|
||||
FilteredNumber int `json:"filtered"`
|
||||
FuzzyNumber int `json:"fuzzy"`
|
||||
WafedNumber int `json:"wafed"`
|
||||
|
||||
End int `json:"end"`
|
||||
Offset int `json:"offset"`
|
||||
Total int `json:"total"`
|
||||
StartTime int64 `json:"start_time"`
|
||||
EndTime int64 `json:"end_time"`
|
||||
WordCount int `json:"word_count"`
|
||||
Word string `json:"word"`
|
||||
Dictionaries []string `json:"dictionaries"`
|
||||
RuleFiles []string `json:"rule_files"`
|
||||
RuleFilter string `json:"rule_filter"`
|
||||
End int `json:"end"`
|
||||
Offset int `json:"offset"`
|
||||
Total int `json:"total"`
|
||||
StartTime int64 `json:"start_time"`
|
||||
EndTime int64 `json:"end_time"`
|
||||
WordCount int `json:"word_count"`
|
||||
Word string `json:"word"`
|
||||
Dictionaries []string `json:"dictionaries"`
|
||||
RuleFiles []string `json:"rule_files"`
|
||||
RuleFilter string `json:"rule_filter"`
|
||||
}
|
||||
|
||||
func (stat *Statistor) ColorString() string {
|
||||
@ -88,7 +90,7 @@ func (stat *Statistor) String() string {
|
||||
return s.String()
|
||||
}
|
||||
|
||||
func (stat *Statistor) Detail() string {
|
||||
func (stat *Statistor) CountString() string {
|
||||
var s strings.Builder
|
||||
s.WriteString("[stat] ")
|
||||
s.WriteString(stat.BaseUrl)
|
||||
@ -101,7 +103,17 @@ func (stat *Statistor) Detail() string {
|
||||
return s.String()
|
||||
}
|
||||
|
||||
func (stat *Statistor) ColorDetail() string {
|
||||
func (stat *Statistor) SourceString() string {
|
||||
var s strings.Builder
|
||||
s.WriteString("[stat] ")
|
||||
s.WriteString(stat.BaseUrl)
|
||||
for k, v := range stat.Sources {
|
||||
s.WriteString(fmt.Sprintf(" %s: %d,", GetSourceName(k), v))
|
||||
}
|
||||
return s.String()
|
||||
}
|
||||
|
||||
func (stat *Statistor) ColorCountString() string {
|
||||
var s strings.Builder
|
||||
s.WriteString("[stat] ")
|
||||
s.WriteString(stat.BaseUrl)
|
||||
@ -114,6 +126,16 @@ func (stat *Statistor) ColorDetail() string {
|
||||
return s.String()
|
||||
}
|
||||
|
||||
func (stat *Statistor) ColorSourceString() string {
|
||||
var s strings.Builder
|
||||
s.WriteString("[stat] ")
|
||||
s.WriteString(stat.BaseUrl)
|
||||
for k, v := range stat.Sources {
|
||||
s.WriteString(fmt.Sprintf(" %s: %s,", logs.YellowBold(GetSourceName(k)), logs.YellowBold(strconv.Itoa(v))))
|
||||
}
|
||||
return s.String()
|
||||
}
|
||||
|
||||
func (stat *Statistor) Json() string {
|
||||
content, err := json.Marshal(stat)
|
||||
if err != nil {
|
||||
@ -136,6 +158,7 @@ func ReadStatistors(filename string) (Statistors, error) {
|
||||
}
|
||||
stats = append(stats, &stat)
|
||||
}
|
||||
|
||||
return stats, nil
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user