Skip to content

Commit

Permalink
Merge pull request #500 from projectdiscovery/stats-interval
Browse files Browse the repository at this point in the history
Added stats-interval for changing stats display frequency
  • Loading branch information
ehsandeep committed Jan 18, 2022
2 parents 8b67220 + 9b9a95a commit f7ca15b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
7 changes: 7 additions & 0 deletions runner/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ type Options struct {
TLSGrab bool
protocol string
ShowStatistics bool
StatsInterval int
RandomAgent bool
StoreChain bool
Deny customlist.CustomList
Expand Down Expand Up @@ -337,6 +338,7 @@ func ParseOptions() *Options {
flagSet.BoolVar(&options.DebugRequests, "debug-req", false, "Show all sent requests"),
flagSet.BoolVar(&options.DebugResponse, "debug-resp", false, "Show all received responses"),
flagSet.BoolVar(&options.ShowStatistics, "stats", false, "Display scan statistic"),
flagSet.IntVarP(&options.StatsInterval, "stats-interval", "si", 0, "number of seconds to wait between showing a statistics update (default: 5)"),
)

createGroup(flagSet, "Optimizations", "Optimizations",
Expand All @@ -351,6 +353,11 @@ func ParseOptions() *Options {
)

_ = flagSet.Parse()

if options.StatsInterval != 0 {
options.ShowStatistics = true
}

// Read the inputs and configure the logging
options.configureOutput()

Expand Down
10 changes: 5 additions & 5 deletions runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ import (
"go.uber.org/ratelimit"
)

const (
statsDisplayInterval = 5
)

// Runner is a client for running the enumeration process.
type Runner struct {
options *Options
Expand Down Expand Up @@ -239,6 +235,9 @@ func New(options *Options) (*Runner, error) {
if err != nil {
return nil, err
}
if options.StatsInterval == 0 {
options.StatsInterval = 5
}
}

hmapOptions := hybrid.DefaultDiskOptions
Expand Down Expand Up @@ -320,7 +319,8 @@ func (r *Runner) prepareInput() {
r.stats.AddCounter("hosts", 0)
r.stats.AddStatic("startedAt", time.Now())
r.stats.AddCounter("requests", 0)
err := r.stats.Start(makePrintCallback(), time.Duration(statsDisplayInterval)*time.Second)

err := r.stats.Start(makePrintCallback(), time.Duration(r.options.StatsInterval)*time.Second)
if err != nil {
gologger.Warning().Msgf("Could not create statistics: %s\n", err)
}
Expand Down

0 comments on commit f7ca15b

Please sign in to comment.