-
Notifications
You must be signed in to change notification settings - Fork 13
/
main.go
74 lines (59 loc) · 2.83 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright (c) Mainflux
// SPDX-License-Identifier: Apache-2.0
package main
import (
"log"
bench "github.com/MainfluxLabs/mainflux/tools/mqtt-bench"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
func main() {
confFile := ""
bconf := bench.Config{}
// Command
var rootCmd = &cobra.Command{
Use: "mqtt-bench",
Short: "mqtt-bench is MQTT benchmark tool for Mainflux",
Long: `Tool for exctensive load and benchmarking of MQTT brokers used withing Mainflux platform.
Complete documentation is available at https://mainfluxlabs.github.io/docs`,
Run: func(cmd *cobra.Command, args []string) {
if confFile != "" {
viper.SetConfigFile(confFile)
if err := viper.ReadInConfig(); err != nil {
log.Printf("Failed to load config - %s", err.Error())
}
if err := viper.Unmarshal(&bconf); err != nil {
log.Printf("Unable to decode into struct, %v", err)
}
}
bench.Benchmark(bconf)
},
}
// Flags
// MQTT Broker
rootCmd.PersistentFlags().StringVarP(&bconf.MQTT.Broker.URL, "broker", "b", "tcp://localhost:1883",
"address for mqtt broker, for secure use tcps and 8883")
// MQTT Message
rootCmd.PersistentFlags().IntVarP(&bconf.MQTT.Message.Size, "size", "z", 100, "Size of message payload bytes")
rootCmd.PersistentFlags().StringVarP(&bconf.MQTT.Message.Payload, "payload", "l", "", "Template message")
rootCmd.PersistentFlags().StringVarP(&bconf.MQTT.Message.Format, "format", "f", "text", "Output format: text|json")
rootCmd.PersistentFlags().IntVarP(&bconf.MQTT.Message.QoS, "qos", "q", 0, "QoS for published messages, values 0 1 2")
rootCmd.PersistentFlags().BoolVarP(&bconf.MQTT.Message.Retain, "retain", "r", false, "Retain mqtt messages")
rootCmd.PersistentFlags().IntVarP(&bconf.MQTT.Timeout, "timeout", "o", 10000, "Timeout mqtt messages")
// MQTT TLS
rootCmd.PersistentFlags().BoolVarP(&bconf.MQTT.TLS.MTLS, "mtls", "", false, "Use mtls for connection")
rootCmd.PersistentFlags().BoolVarP(&bconf.MQTT.TLS.SkipTLSVer, "skipTLSVer", "t", false, "Skip tls verification")
rootCmd.PersistentFlags().StringVarP(&bconf.MQTT.TLS.CA, "ca", "", "ca.crt", "CA file")
// Test params
rootCmd.PersistentFlags().IntVarP(&bconf.Test.Count, "count", "n", 100, "Number of messages sent per publisher")
rootCmd.PersistentFlags().IntVarP(&bconf.Test.Subs, "subs", "s", 10, "Number of subscribers")
rootCmd.PersistentFlags().IntVarP(&bconf.Test.Pubs, "pubs", "p", 10, "Number of publishers")
// Log params
rootCmd.PersistentFlags().BoolVarP(&bconf.Log.Quiet, "quiet", "", false, "Supress messages")
// Config file
rootCmd.PersistentFlags().StringVarP(&confFile, "config", "c", "config.toml", "config file for mqtt-bench")
rootCmd.PersistentFlags().StringVarP(&bconf.Mf.ConnFile, "mainflux", "m", "connections.toml", "config file for Mainflux connections")
if err := rootCmd.Execute(); err != nil {
log.Fatal(err)
}
}