mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/yunionio/cloudpods.git
synced 2026-09-20 08:03:53 +08:00
fix(telegraf-raid-plugin): working for victoria metrics (#24087)
This commit is contained in:
2
Makefile
2
Makefile
@@ -323,7 +323,7 @@ image:
|
|||||||
.PHONY: image
|
.PHONY: image
|
||||||
|
|
||||||
image-telegraf-raid-plugin:
|
image-telegraf-raid-plugin:
|
||||||
VERSION=release-1.6.6 GOOS=linux ARCH=all make image telegraf-raid-plugin
|
VERSION=v4.0-20260115.0 GOOS=linux ARCH=all make image telegraf-raid-plugin
|
||||||
|
|
||||||
%:
|
%:
|
||||||
@:
|
@:
|
||||||
|
|||||||
@@ -164,19 +164,32 @@ func (c *RaidInfoCollector) toTelegrafReportData(raidDiskInfo []*baremetal.Barem
|
|||||||
tag := fmt.Sprintf("%s=%s,%s=%s", "hostname", c.Hostname, "host_ip", c.HostIp)
|
tag := fmt.Sprintf("%s=%s,%s=%s", "hostname", c.Hostname, "host_ip", c.HostIp)
|
||||||
ret := []string{}
|
ret := []string{}
|
||||||
for i := 0; i < len(raidDiskInfo); i++ {
|
for i := 0; i < len(raidDiskInfo); i++ {
|
||||||
statArr := []string{}
|
fieldArr := []string{}
|
||||||
|
tagArr := []string{}
|
||||||
raidDiskInfo[i].Status = strings.ToLower(raidDiskInfo[i].Status)
|
raidDiskInfo[i].Status = strings.ToLower(raidDiskInfo[i].Status)
|
||||||
jStat := jsonutils.Marshal(raidDiskInfo[i])
|
jStat := jsonutils.Marshal(raidDiskInfo[i])
|
||||||
jMap, _ := jStat.GetMap()
|
jMap, _ := jStat.GetMap()
|
||||||
for k, v := range jMap {
|
for k, v := range jMap {
|
||||||
statArr = append(statArr, fmt.Sprintf("%s=%s", k, v.String()))
|
vStr, _ := v.GetString()
|
||||||
|
if vStr == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
vStr = strings.ReplaceAll(vStr, " ", "\\ ")
|
||||||
|
kv := fmt.Sprintf("%s=%s", k, vStr)
|
||||||
|
switch k {
|
||||||
|
case "adapter", "slot":
|
||||||
|
fieldArr = append(fieldArr, kv)
|
||||||
|
case "model", "driver", "status":
|
||||||
|
tagArr = append(tagArr, kv)
|
||||||
|
case "index":
|
||||||
|
continue
|
||||||
|
default:
|
||||||
|
tagArr = append(tagArr, kv)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
stat := strings.Join(statArr, ",")
|
field := strings.Join(fieldArr, ",")
|
||||||
diskTag := fmt.Sprintf(
|
diskTag := tag + "," + strings.Join(tagArr, ",")
|
||||||
"%s,%s=%s,%s=%d,%s=%d", tag, "driver", raidDiskInfo[i].Driver,
|
line := fmt.Sprintf("%s,%s %s", MEASUREMENT, diskTag, field)
|
||||||
"adapter", raidDiskInfo[i].Adapter, "slot", raidDiskInfo[i].Slot,
|
|
||||||
)
|
|
||||||
line := fmt.Sprintf("%s,%s %s", MEASUREMENT, diskTag, stat)
|
|
||||||
ret = append(ret, line)
|
ret = append(ret, line)
|
||||||
}
|
}
|
||||||
return strings.Join(ret, "\n")
|
return strings.Join(ret, "\n")
|
||||||
@@ -185,7 +198,7 @@ func (c *RaidInfoCollector) toTelegrafReportData(raidDiskInfo []*baremetal.Barem
|
|||||||
func (c *RaidInfoCollector) reportRaidInfoToTelegraf(data string) {
|
func (c *RaidInfoCollector) reportRaidInfoToTelegraf(data string) {
|
||||||
body := strings.NewReader(data)
|
body := strings.NewReader(data)
|
||||||
res, err := httputils.Request(
|
res, err := httputils.Request(
|
||||||
httputils.GetDefaultClient(), context.Background(), "POST", TelegrafServer, nil, body, false)
|
httputils.GetDefaultClient(), context.Background(), "POST", TelegrafServer, nil, body, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Upload guest metric failed: %s", err)
|
log.Errorf("Upload guest metric failed: %s", err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -118,4 +118,6 @@ var All = []SMeasurement{
|
|||||||
swap,
|
swap,
|
||||||
|
|
||||||
temp,
|
temp,
|
||||||
|
|
||||||
|
hostRaid,
|
||||||
}
|
}
|
||||||
|
|||||||
36
pkg/monitor/dbinit/measurements/host_raid.go
Normal file
36
pkg/monitor/dbinit/measurements/host_raid.go
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
// Copyright 2019 Yunion
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package measurements
|
||||||
|
|
||||||
|
import "yunion.io/x/onecloud/pkg/apis/monitor"
|
||||||
|
|
||||||
|
var hostRaid = SMeasurement{
|
||||||
|
Context: []SMonitorContext{
|
||||||
|
{
|
||||||
|
"host_raid", "Host RAID metrics",
|
||||||
|
monitor.METRIC_RES_TYPE_HOST, monitor.METRIC_DATABASE_TELE,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Metrics: []SMetric{
|
||||||
|
{
|
||||||
|
"adapter", "Raid controller adapter",
|
||||||
|
monitor.METRIC_UNIT_NULL,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"slot", "Physical disk slot",
|
||||||
|
monitor.METRIC_UNIT_NULL,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user