diff --git a/README.md b/README.md index 21ebfdb..2f3e19f 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ Usage of mqtt-benchmark: -format="text": Output format: text|json -password="": MQTT password (empty if auth disabled) -qos=1: QoS for published messages + -quiet=false : Suppress logs while running (except errors and the result) -size=100: Size of the messages payload (bytes) -topic="/test": MQTT topic for incoming message -username="": MQTT username (empty if auth disabled) @@ -57,7 +58,7 @@ Total Bandwidth (msg/sec): 676.112 Similarly, in JSON: ``` -> mqtt-benchmark --broker tcp://broker.local:1883 --count 100 --size 100 --clients 100 --qos 2 --format json +> mqtt-benchmark --broker tcp://broker.local:1883 --count 100 --size 100 --clients 100 --qos 2 --format json --quiet { runs: [ ... @@ -86,4 +87,4 @@ Similarly, in JSON: "avg_msgs_per_sec": 6.810374046459865 } } -``` \ No newline at end of file +``` diff --git a/client.go b/client.go index 67d5e7f..9d4c271 100644 --- a/client.go +++ b/client.go @@ -20,6 +20,7 @@ type Client struct { MsgSize int MsgCount int MsgQoS byte + Quiet bool } func (c *Client) Run(res chan *RunResults) { @@ -80,7 +81,9 @@ func (c *Client) genMessages(ch chan *Message, done chan bool) { func (c *Client) pubMessages(in, out chan *Message, doneGen, donePub chan bool) { onConnected := func(client mqtt.Client) { - log.Printf("CLIENT %v is connected to the broker %v\n", c.ID, c.BrokerURL) + if !c.Quiet { + log.Printf("CLIENT %v is connected to the broker %v\n", c.ID, c.BrokerURL) + } ctr := 0 for { select { @@ -98,12 +101,16 @@ func (c *Client) pubMessages(in, out chan *Message, doneGen, donePub chan bool) out <- m if ctr > 0 && ctr%100 == 0 { - log.Printf("CLIENT %v published %v messages and keeps publishing...\n", c.ID, ctr) + if !c.Quiet { + log.Printf("CLIENT %v published %v messages and keeps publishing...\n", c.ID, ctr) + } } ctr++ case <-doneGen: donePub <- true - log.Printf("CLIENT %v is done publishing\n", c.ID) + if !c.Quiet { + log.Printf("CLIENT %v is done publishing\n", c.ID) + } return } } diff --git a/main.go b/main.go index 4ef5d2b..6008ed0 100644 --- a/main.go +++ b/main.go @@ -67,6 +67,7 @@ func main() { count = flag.Int("count", 100, "Number of messages to send per client") clients = flag.Int("clients", 10, "Number of clients to start") format = flag.String("format", "text", "Output format: text|json") + quiet = flag.Bool("quiet", false, "Suppress logs while running") ) flag.Parse() @@ -77,7 +78,9 @@ func main() { resCh := make(chan *RunResults) start := time.Now() for i := 0; i < *clients; i++ { - log.Println("Starting client ", i) + if !*quiet { + log.Println("Starting client ", i) + } c := &Client{ ID: i, BrokerURL: *broker, @@ -87,6 +90,7 @@ func main() { MsgSize: *size, MsgCount: *count, MsgQoS: byte(*qos), + Quiet: *quiet, } go c.Run(resCh) }