add fixes on the comment
This commit is contained in:
parent
1e16540932
commit
97b4f68d72
|
@ -4,6 +4,8 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/influxdb/telegraf/plugins"
|
"github.com/influxdb/telegraf/plugins"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -62,14 +64,12 @@ func (ceph *CephMetrics) gatherMetrics(acc plugins.Accumulator) {
|
||||||
|
|
||||||
var quorum QuorumStat
|
var quorum QuorumStat
|
||||||
|
|
||||||
out, err := exec.Command("/bin/hostname").Output()
|
hostname, err := os.Hostname()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
hostname := string(out)
|
|
||||||
|
|
||||||
if err := ceph.cephCommand(&quorum, "quorum_status"); err != nil {
|
if err := ceph.cephCommand(&quorum, "quorum_status"); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ func (ceph *CephMetrics) gatherMetrics(acc plugins.Accumulator) {
|
||||||
ceph.getOSDPerf(acc)
|
ceph.getOSDPerf(acc)
|
||||||
|
|
||||||
if strings.TrimSpace(hostname) != strings.TrimSpace(quorum.LeaderName) {
|
if strings.TrimSpace(hostname) != strings.TrimSpace(quorum.LeaderName) {
|
||||||
fmt.Printf("Not a leader: quorum leader %s, host %s", quorum.LeaderName, hostname)
|
fmt.Printf("Not a leader: Quorum leader %s, Host %s", quorum.LeaderName, hostname)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,26 +118,22 @@ func (ceph *CephMetrics) getCommon(acc plugins.Accumulator) {
|
||||||
tags := map[string]string{"cluster": ceph.Cluster}
|
tags := map[string]string{"cluster": ceph.Cluster}
|
||||||
|
|
||||||
//Monitors
|
//Monitors
|
||||||
var monitorStr string
|
|
||||||
monitors := quorum.MonitorMap.Mons
|
monitors := quorum.MonitorMap.Mons
|
||||||
|
monitorNames := make([]string, len(monitors))
|
||||||
monitorValueMap := make(map[string]interface{})
|
monitorValueMap := make(map[string]interface{})
|
||||||
monitorValueMap["value"] = len(monitors)
|
monitorValueMap["value"] = len(monitors)
|
||||||
|
|
||||||
for _, value := range monitors {
|
for i, value := range monitors {
|
||||||
monitorStr = fmt.Sprint(monitorStr, ",", value.Name)
|
monitorNames[i] = value.Name
|
||||||
}
|
}
|
||||||
monitorValueMap["name"] = monitorStr
|
|
||||||
|
monitorValueMap["name"] = strings.Join(monitorNames, ",")
|
||||||
|
|
||||||
//Quorum Names
|
//Quorum Names
|
||||||
var memberStr string
|
|
||||||
quorum_name := quorum.QuorumName
|
quorum_name := quorum.QuorumName
|
||||||
quorumValueMap := make(map[string]interface{})
|
quorumValueMap := make(map[string]interface{})
|
||||||
quorumValueMap["value"] = len(quorum_name)
|
quorumValueMap["value"] = len(quorum_name)
|
||||||
|
quorumValueMap["members"] = strings.Join(quorum_name, ",")
|
||||||
for _, value := range quorum_name {
|
|
||||||
memberStr = fmt.Sprint(memberStr, ",", value)
|
|
||||||
}
|
|
||||||
quorumValueMap["members"] = memberStr
|
|
||||||
|
|
||||||
//clientIOs
|
//clientIOs
|
||||||
sumOps := 0
|
sumOps := 0
|
||||||
|
@ -149,13 +145,13 @@ func (ceph *CephMetrics) getCommon(acc plugins.Accumulator) {
|
||||||
|
|
||||||
// OSD Epoch
|
// OSD Epoch
|
||||||
epoch := cephStatus.OSDMap.OSDMap.Epoch
|
epoch := cephStatus.OSDMap.OSDMap.Epoch
|
||||||
acc.Add("osd_epoch", fmt.Sprintf("%d", epoch), map[string]string{"cluster": ceph.Cluster})
|
acc.Add("osd_epoch", epoch, map[string]string{"cluster": ceph.Cluster})
|
||||||
acc.Add("health", health.OverallStatus, tags)
|
acc.Add("health", health.OverallStatus, tags)
|
||||||
acc.Add("total_storage", cephDf.Stats.TotalBytes, tags)
|
acc.Add("total_storage", cephDf.Stats.TotalBytes, tags)
|
||||||
acc.Add("used", cephDf.Stats.TotalUsedBytes, tags)
|
acc.Add("used", cephDf.Stats.TotalUsedBytes, tags)
|
||||||
acc.Add("available", cephDf.Stats.TotalAvailableBytes, tags)
|
acc.Add("available", cephDf.Stats.TotalAvailableBytes, tags)
|
||||||
acc.Add("client_io_kbs", fmt.Sprintf("%d", sumWrs), tags)
|
acc.Add("client_io_kbs", sumWrs, tags)
|
||||||
acc.Add("client_io_ops", fmt.Sprintf("%d", sumOps), tags)
|
acc.Add("client_io_ops", sumOps, tags)
|
||||||
acc.AddValuesWithTime("monitor", monitorValueMap, tags, time.Now())
|
acc.AddValuesWithTime("monitor", monitorValueMap, tags, time.Now())
|
||||||
acc.AddValuesWithTime("quorum", quorumValueMap, tags, time.Now())
|
acc.AddValuesWithTime("quorum", quorumValueMap, tags, time.Now())
|
||||||
}
|
}
|
||||||
|
@ -369,27 +365,27 @@ func (ceph *CephMetrics) getOSDDaemon(acc plugins.Accumulator) {
|
||||||
func (ceph *CephMetrics) getOSDPerf(acc plugins.Accumulator) {
|
func (ceph *CephMetrics) getOSDPerf(acc plugins.Accumulator) {
|
||||||
var osdPerf OsdPerfDump
|
var osdPerf OsdPerfDump
|
||||||
|
|
||||||
out, err := exec.Command("/bin/ls", ceph.SocketDir).Output()
|
osdsArray, err := ioutil.ReadDir(ceph.SocketDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fileStr := string(out)
|
|
||||||
osdsArray := strings.Split(fileStr, "\n")
|
|
||||||
osds := make([]string, len(osdsArray))
|
|
||||||
index := 0
|
|
||||||
|
|
||||||
for _, value := range osdsArray {
|
for _, file := range osdsArray {
|
||||||
if !strings.Contains(value, "osd") {
|
name := file.Name()
|
||||||
|
|
||||||
|
if !strings.HasPrefix(name, ceph.Cluster+"-osd") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
osds[index] = value
|
|
||||||
index++
|
location := fmt.Sprint(ceph.SocketDir, "/", name)
|
||||||
location := fmt.Sprint(ceph.SocketDir, "/", value)
|
|
||||||
args := []string{"--admin-daemon", location, "perf", "dump"}
|
args := []string{"--admin-daemon", location, "perf", "dump"}
|
||||||
|
|
||||||
if err := ceph.cephCommand(&osdPerf, args...); err != nil {
|
if err := ceph.cephCommand(&osdPerf, args...); err != nil {
|
||||||
|
fmt.Println("error ", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
osdId := string(value[strings.LastIndex(value, ".")-1])
|
|
||||||
|
osdId := string(name[strings.LastIndex(name, ".")-1])
|
||||||
tags := map[string]string{"cluster": ceph.Cluster, "osd": osdId}
|
tags := map[string]string{"cluster": ceph.Cluster, "osd": osdId}
|
||||||
osd := osdPerf.Osd
|
osd := osdPerf.Osd
|
||||||
|
|
||||||
|
@ -426,7 +422,7 @@ func getOSDLatencyCalc(osdLatency *OSDLatency) map[string]interface{} {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ceph *CephMetrics) cephCommand(v interface{}, args ...string) error {
|
func (ceph *CephMetrics) cephCommand(v interface{}, args ...string) error {
|
||||||
args = append(args, "-f", "json")
|
args = append(args, "-f", "json", "--cluster="+ceph.Cluster)
|
||||||
out, err := exec.Command(ceph.BinLocation, args...).Output()
|
out, err := exec.Command(ceph.BinLocation, args...).Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue