-
Notifications
You must be signed in to change notification settings - Fork 0
/
watchdoge.go
38 lines (34 loc) · 951 Bytes
/
watchdoge.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
package main
import(
"fmt"
"strings"
"strconv"
"time"
"github.com/hypersleep/easyssh"
)
type Watchdoge struct {
Pid, Stat string
Period, Iterations int
}
func RunPidstat(ssh_params *easyssh.MakeConfig, watchdoge *Watchdoge) {
response, err := ssh_params.Run("cat /proc/" + watchdoge.Pid + "/status | grep " + watchdoge.Stat)
if err != nil {
fmt.Println(err.Error())
} else {
fmt.Println(strings.TrimSpace(response))
b := strings.Split(response, " ")
key := "metrics:" + ssh_params.Server
key += ":" + watchdoge.Pid
key += ":" + strings.TrimSpace(b[0]) + strconv.Itoa(int(time.Now().Unix()))
value := b[2] + b[3]
redis_client.Set(key, value)
}
return
}
func PullRemoteProcessMetrics(ssh_params *easyssh.MakeConfig, watchdoge *Watchdoge) {
fmt.Println("Process info:")
for i := 0; i < watchdoge.Iterations; i++ {
go RunPidstat(ssh_params, watchdoge)
time.Sleep(time.Duration(watchdoge.Period) * time.Second)
}
}