forked from open-falcon/falcon-plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitor.go
53 lines (45 loc) · 1.03 KB
/
monitor.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
package cmd
import (
"fmt"
"os"
"os/exec"
"strings"
"github.com/open-falcon/falcon-plus/g"
"github.com/spf13/cobra"
)
var Monitor = &cobra.Command{
Use: "monitor [Module ...]",
Short: "Display an Open-Falcon module's log",
Long: `
Display the log of the specified Open-Falcon module.
A module represents a single node in a cluster.
Modules:
` + strings.Join(g.AllModulesInOrder, " "),
RunE: monitor,
}
func checkMonReq(name string) error {
if !g.HasModule(name) {
return fmt.Errorf("%s doesn't exist", name)
}
if !g.HasLogfile(name) {
r := g.Rel(g.Cfg(name))
return fmt.Errorf("expect logfile: %s", r)
}
return nil
}
func monitor(c *cobra.Command, args []string) error {
if len(args) < 1 {
return c.Usage()
}
var tailArgs []string = []string{"-f"}
for _, moduleName := range args {
if err := checkMonReq(moduleName); err != nil {
return err
}
tailArgs = append(tailArgs, g.LogPath(moduleName))
}
cmd := exec.Command("tail", tailArgs...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}