-
Notifications
You must be signed in to change notification settings - Fork 0
/
root.go
52 lines (42 loc) · 1.48 KB
/
root.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
package cmd
import (
"regexp"
"strings"
"github.com/aokabi/ngraphinx/lib"
graph "github.com/aokabi/ngraphinx/lib/graph"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var (
// Used for flags.
userLicense string
rootCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
regStrs := strings.Split(aggregates, ",")
option := graph.NewOption(imageWidth, imageHeight, reqMinCountPerSec)
regexps := make(lib.Regexps, len(regStrs))
for i, aggregate := range regStrs {
regexps[i] = regexp.MustCompile(aggregate)
}
return graph.GenerateGraph(regexps, nginxAccessLogFilepath, option)
},
}
nginxAccessLogFilepath string
aggregates string
imageWidth graph.Inch
imageHeight graph.Inch
reqMinCountPerSec int
)
func Execute() error {
return rootCmd.Execute()
}
func init() {
cobra.OnInitialize()
rootCmd.PersistentFlags().StringVarP(&userLicense, "license", "l", "", "name of license for the project")
rootCmd.PersistentFlags().StringVar(&aggregates, "aggregates", "", "aggregate endpoint")
rootCmd.PersistentFlags().StringVar(&nginxAccessLogFilepath, "path", "access.log", "nginx access log path")
rootCmd.PersistentFlags().IntVar(&imageWidth, "width", 10, "image width(Inch)")
rootCmd.PersistentFlags().IntVar(&imageHeight, "height", 10, "image height(Inch)")
rootCmd.PersistentFlags().IntVar(&reqMinCountPerSec, "mincount", 20, "required min request count per sec")
viper.SetDefault("license", "apache")
}