-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
78 lines (70 loc) · 1.54 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
75
76
77
78
package main
import (
"flag"
"fmt"
"os"
"strings"
"github.com/doki/common/model"
"github.com/doki/common/util"
"github.com/doki/parser"
)
var (
services = flag.String("services", "mysqld,mongod,redis-server", "collect service log")
loki = flag.String("loki", "localhost:3100", "loki server url")
domain = flag.String("domain", "dbaas", "domain for instances")
ipprefix = flag.String("prefix", "", "local ip prefix")
)
func init() {
fmt.Printf("[INFO]\tdoki start\n")
flag.Parse()
}
func main() {
defer fmt.Printf("[INFO]\tdoki finish\n")
localServices := strings.Split(*services, ",")
procs, err := util.GetLocalServices(localServices, *ipprefix)
if err != nil {
fmt.Printf("[ERROR]\t%v\n", err)
os.Exit(1)
}
for _, v := range procs {
v.Domain = *domain
}
fmt.Printf("[INFO]\tprocs is: %v\n", printProcs(procs))
parser.Run(procs, *loki)
}
func printProcs(v []*model.Process) string {
procs := ""
for _, v := range v {
procs = fmt.Sprintf("%v\t%v", procs, v)
}
return strings.Trim(procs, "\t")
}
// for furture
func usage() {
fmt.Printf("Usage: %v [mysql=slowlog|redis=addr:pwd|mongodb=log]+\n", os.Args[0])
os.Exit(1)
}
func argsParse() []model.Arg {
p := flag.Args()
if len(p) == 0 {
usage()
}
var args []model.Arg
for _, v := range p {
kv := strings.Split(v, "=")
switch kv[0] {
case "mysql":
case "mongodb":
case "redis":
default:
fmt.Println("error: not match key ", kv[0])
usage()
}
var arg = model.Arg{
Service: kv[0],
File: kv[1],
}
args = append(args, arg)
}
return args
}