Greenplum final (#175)
* add plugin greenplum monitor * refector code * fix the bug when %7 !=0
This commit is contained in:
parent
cf790cd638
commit
01630b5f7f
|
@ -14,6 +14,7 @@ import (
|
|||
_ "flashcat.cloud/categraf/inputs/docker"
|
||||
_ "flashcat.cloud/categraf/inputs/elasticsearch"
|
||||
_ "flashcat.cloud/categraf/inputs/exec"
|
||||
_ "flashcat.cloud/categraf/inputs/greenplum"
|
||||
_ "flashcat.cloud/categraf/inputs/http_response"
|
||||
_ "flashcat.cloud/categraf/inputs/ipvs"
|
||||
_ "flashcat.cloud/categraf/inputs/jenkins"
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
# # collect interval
|
||||
# interval = 15
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
package greenplum
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strings"
|
||||
"os/exec"
|
||||
|
||||
"flashcat.cloud/categraf/config"
|
||||
"flashcat.cloud/categraf/inputs"
|
||||
"flashcat.cloud/categraf/types"
|
||||
)
|
||||
|
||||
const inputName = "greenplum"
|
||||
|
||||
type Greenplum struct {
|
||||
config.PluginConfig
|
||||
}
|
||||
|
||||
func init() {
|
||||
inputs.Add(inputName, func() inputs.Input {
|
||||
return &Greenplum{}
|
||||
})
|
||||
}
|
||||
|
||||
func (ins *Greenplum) Gather(slist *types.SampleList) {
|
||||
var tags = map[string]string{}
|
||||
bin, err := exec.LookPath("gpstate")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
out, err := exec.Command(bin, "-m").Output()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
stringOut := string(out)
|
||||
const splitHeader string = "Mirror Datadir Port Status Data Status"
|
||||
const lastHeader string = "gpadmin-[INFO]:---"
|
||||
stateValue := stringOut[(strings.Index(stringOut, splitHeader) + len(splitHeader)) : strings.LastIndex(stringOut, lastHeader)-47]
|
||||
stateValue = strings.TrimSpace(stateValue)
|
||||
gpstate := strings.Fields(stateValue)
|
||||
if len(gpstate)%7 != 0 {
|
||||
log.Println("E! failed to parse gpstate -m output: %v", gpstate)
|
||||
return
|
||||
}
|
||||
line := len(gpstate) / 7
|
||||
for i := 0; i < line; i++ {
|
||||
gptags := map[string]string{
|
||||
"Mirror": gpstate[i*7+2],
|
||||
"Datadir": gpstate[i*7+3],
|
||||
"Port": gpstate[i*7+4],
|
||||
}
|
||||
for tag, value := range tags {
|
||||
gptags[tag] = value
|
||||
}
|
||||
var status int32 = 0
|
||||
var dataStatus int32 = 0
|
||||
if gpstate[i*7+5] == "Passive" {
|
||||
status = 1
|
||||
}
|
||||
if gpstate[i*7+6] == "Synchronized" {
|
||||
dataStatus = 1
|
||||
}
|
||||
slist.PushSample(inputName, "Status", status, gptags)
|
||||
slist.PushSample(inputName, "Data_Status", dataStatus, gptags)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue