Skip to content

Commit

Permalink
More user friendly logs (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
arriven authored Mar 9, 2022
1 parent 9b6ad5e commit 59c8c75
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
7 changes: 5 additions & 2 deletions src/jobs/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ func fastHTTPJob(ctx context.Context, globalConfig GlobalConfig, args Args, debu
return err
}

trafficMonitor := metrics.Default.NewWriter("traffic", uuid.New().String())
trafficMonitor := metrics.Default.NewWriter(metrics.Traffic, uuid.New().String())
go trafficMonitor.Update(ctx, time.Second)
processedTrafficMonitor := metrics.Default.NewWriter(metrics.ProcessedTraffic, uuid.NewString())
go processedTrafficMonitor.Update(ctx, time.Second)

req := fasthttp.AcquireRequest()
defer fasthttp.ReleaseRequest(req)
Expand All @@ -102,12 +104,13 @@ func fastHTTPJob(ctx context.Context, globalConfig GlobalConfig, args Args, debu
dataSize += len(key) + len(value)
}

trafficMonitor.Add(dataSize)
if err := sendFastHTTPRequest(client, req, debug); err != nil {
if debug {
log.Printf("Error sending request %v: %v", req, err)
}
} else {
trafficMonitor.Add(dataSize)
processedTrafficMonitor.Add(dataSize)
}

time.Sleep(time.Duration(jobConfig.IntervalMs) * time.Millisecond)
Expand Down
2 changes: 1 addition & 1 deletion src/jobs/packetgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func packetgenJob(ctx context.Context, globalConfig GlobalConfig, args Args, deb
return err
}

trafficMonitor := metrics.Default.NewWriter("traffic", uuid.New().String())
trafficMonitor := metrics.Default.NewWriter(metrics.Traffic, uuid.New().String())
go trafficMonitor.Update(ctx, time.Second)

for jobConfig.Next(ctx) {
Expand Down
4 changes: 2 additions & 2 deletions src/jobs/rawnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func tcpJob(ctx context.Context, globalConfig GlobalConfig, args Args, debug boo
return fmt.Errorf("error parsing body template %q: %v", jobConfig.Body, err)
}

trafficMonitor := metrics.Default.NewWriter("traffic", uuid.New().String())
trafficMonitor := metrics.Default.NewWriter(metrics.Traffic, uuid.New().String())
go trafficMonitor.Update(ctx, time.Second)

for jobConfig.Next(ctx) {
Expand Down Expand Up @@ -123,7 +123,7 @@ func udpJob(ctx context.Context, globalConfig GlobalConfig, args Args, debug boo
return fmt.Errorf("error parsing body template %q: %v", jobConfig.Body, err)
}

trafficMonitor := metrics.Default.NewWriter("traffic", uuid.New().String())
trafficMonitor := metrics.Default.NewWriter(metrics.Traffic, uuid.New().String())
go trafficMonitor.Update(ctx, time.Second)

for jobConfig.Next(ctx) {
Expand Down
9 changes: 8 additions & 1 deletion src/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ import (
"time"
)

// supported default metrics
const (
Traffic = "traffic"
ProcessedTraffic = "processed_traffic"
)

// Storage is a general struct to store custom metrics
type Storage struct {
trackers map[string]*metricTracker
Expand All @@ -44,7 +50,8 @@ var Default Storage

func init() {
Default = Storage{trackers: make(map[string]*metricTracker)}
Default.trackers["traffic"] = &metricTracker{}
Default.trackers[Traffic] = &metricTracker{}
Default.trackers[ProcessedTraffic] = &metricTracker{}
}

func (ms *Storage) Write(name, jobID string, value int) {
Expand Down
8 changes: 6 additions & 2 deletions src/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,19 @@ func dumpMetrics(path, name, clientID string, debug bool) {
}
}()

bytesGenerated := metrics.Default.Read(name)
bytesGenerated := metrics.Default.Read(metrics.Traffic)
bytesProcessed := metrics.Default.Read(metrics.ProcessedTraffic)
err := utils.ReportStatistics(int64(bytesGenerated), clientID)
if err != nil && debug {
log.Println("error reporting statistics:", err)
}
if bytesGenerated > 0 {
log.Println("Атака проводиться успішно! Руський воєнний корабль іди нахуй!")
log.Println("Attack is successful! Russian warship, go fuck yourself!")
log.Printf("The app has generated approximately %v bytes of traffic", bytesGenerated)
log.Printf("The app has generated approximately %v bytes of traffic\n", bytesGenerated)
if bytesProcessed > 0 {
log.Printf("Of which for %v bytes we received some response from the target", bytesProcessed)
}
} else {
log.Println("The app doesn't seem to generate any traffic, please contact your admin")
}
Expand Down

0 comments on commit 59c8c75

Please sign in to comment.