mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-08-29 03:51:54 +08:00
fix(telegraf-raid-plugin): working for victoria metrics (#24085)
This commit is contained in:
@@ -323,7 +323,7 @@ image:
|
||||
.PHONY: image
|
||||
|
||||
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)
|
||||
ret := []string{}
|
||||
for i := 0; i < len(raidDiskInfo); i++ {
|
||||
statArr := []string{}
|
||||
fieldArr := []string{}
|
||||
tagArr := []string{}
|
||||
raidDiskInfo[i].Status = strings.ToLower(raidDiskInfo[i].Status)
|
||||
jStat := jsonutils.Marshal(raidDiskInfo[i])
|
||||
jMap, _ := jStat.GetMap()
|
||||
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, ",")
|
||||
diskTag := fmt.Sprintf(
|
||||
"%s,%s=%s,%s=%d,%s=%d", tag, "driver", raidDiskInfo[i].Driver,
|
||||
"adapter", raidDiskInfo[i].Adapter, "slot", raidDiskInfo[i].Slot,
|
||||
)
|
||||
line := fmt.Sprintf("%s,%s %s", MEASUREMENT, diskTag, stat)
|
||||
field := strings.Join(fieldArr, ",")
|
||||
diskTag := tag + "," + strings.Join(tagArr, ",")
|
||||
line := fmt.Sprintf("%s,%s %s", MEASUREMENT, diskTag, field)
|
||||
ret = append(ret, line)
|
||||
}
|
||||
return strings.Join(ret, "\n")
|
||||
@@ -185,7 +198,7 @@ func (c *RaidInfoCollector) toTelegrafReportData(raidDiskInfo []*baremetal.Barem
|
||||
func (c *RaidInfoCollector) reportRaidInfoToTelegraf(data string) {
|
||||
body := strings.NewReader(data)
|
||||
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 {
|
||||
log.Errorf("Upload guest metric failed: %s", err)
|
||||
return
|
||||
|
||||
@@ -118,4 +118,6 @@ var All = []SMeasurement{
|
||||
swap,
|
||||
|
||||
temp,
|
||||
|
||||
hostRaid,
|
||||
}
|
||||
|
||||
@@ -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