Skip to content

Commit

Permalink
Report GA metrics after writing stats to the console (#436)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdoe7865623 authored Mar 26, 2022
1 parent be30d0c commit 325cf35
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions src/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,34 +209,27 @@ func dumpMetrics(clientID string) error {

bytesGenerated := metrics.Default.Read(metrics.Traffic)
bytesProcessed := metrics.Default.Read(metrics.ProcessedTraffic)

if err := utils.ReportStatistics(int64(bytesGenerated), clientID); err != nil {
return err
}

networkStatsWriter := tabwriter.NewWriter(os.Stdout, 1, 1, 1, ' ', tabwriter.AlignRight)

if bytesGenerated > 0 {
fmt.Fprintln(networkStatsWriter, "\n\n!Атака проводиться успішно! Русскій воєнний корабль іди нахуй!")
fmt.Fprintln(networkStatsWriter, "!Attack is successful! Russian warship, go fuck yourself!")

const BytesInMegabytes = 1024 * 1024
megabytesGenerated := float64(bytesGenerated) / BytesInMegabytes
megabytesProcessed := float64(bytesProcessed) / BytesInMegabytes

const PercentConversionMultilpier = 100
responsePercent := float64(bytesProcessed) / float64(bytesGenerated) * PercentConversionMultilpier
const (
BytesInMegabyte = 1024 * 1024
PercentConversionMultilpier = 100
)

fmt.Fprint(networkStatsWriter, "---------Traffic stats---------\n")
fmt.Fprintf(networkStatsWriter, "[\tGenerated\t]\t%.2f\tMB\t|\t%v \tbytes\n", megabytesGenerated, bytesGenerated)
fmt.Fprintf(networkStatsWriter, "[\tReceived\t]\t%.2f\tMB\t|\t%v \tbytes\n", megabytesProcessed, bytesProcessed)
fmt.Fprintf(networkStatsWriter, "[\tResponse rate\t]\t%.1f\t%%\n", responsePercent)
fmt.Fprintf(networkStatsWriter, "[\tGenerated\t]\t%.2f\tMB\t|\t%v \tbytes\n", float64(bytesGenerated)/BytesInMegabyte, bytesGenerated)
fmt.Fprintf(networkStatsWriter, "[\tReceived\t]\t%.2f\tMB\t|\t%v \tbytes\n", float64(bytesProcessed)/BytesInMegabyte, bytesProcessed)
fmt.Fprintf(networkStatsWriter, "[\tResponse rate\t]\t%.1f\t%%\n", float64(bytesProcessed)/float64(bytesGenerated)*PercentConversionMultilpier)
fmt.Fprint(networkStatsWriter, "-------------------------------\n\n")
} else {
fmt.Fprintln(networkStatsWriter, "[Error] No traffic generated. If you see this message a lot - contact admins")
}

networkStatsWriter.Flush()

return nil
return utils.ReportStatistics(int64(bytesGenerated), clientID)
}

0 comments on commit 325cf35

Please sign in to comment.