Skip to content

Commit

Permalink
At #56 Update the impi_sensor plugin to save the 'temp' tag of ipmi d…
Browse files Browse the repository at this point in the history
…ata as 'cpu_temp' tag
  • Loading branch information
yongsikgi committed Sep 21, 2023
1 parent f568f73 commit e313df4
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions plugins/inputs/ipmi_sensor/ipmi_sensor.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,26 @@ func (m *Ipmi) parseV1(acc telegraf.Accumulator, ipmiIP string, hostname string,
// each line will look something like
// Planar VBAT | 3.05 Volts | ok
scanner := bufio.NewScanner(bytes.NewReader(cmdOut))
cpuIndex := 0
for scanner.Scan() {

ipmiFields := m.extractFieldsFromRegex(reV1ParseLine, scanner.Text())
if len(ipmiFields) != 3 {
continue
}

tag := transform(ipmiFields["name"])

if tag == "temp" {
cpuIndex++
cpuTag := convertToCPUTempTag(ipmiFields, cpuIndex)
if cpuTag == tag {
cpuIndex--
}
tag = cpuTag
}

tags := map[string]string{
"name": transform(ipmiFields["name"]),
"name": tag,
}

// tag the server is we have one
Expand Down Expand Up @@ -230,14 +241,26 @@ func (m *Ipmi) parseV2(acc telegraf.Accumulator, ipmiIP string, hostname string,
// Temp | 0Eh | ok | 3.1 | 55 degrees C
// Drive 0 | A0h | ok | 7.1 | Drive Present
scanner := bufio.NewScanner(bytes.NewReader(cmdOut))
cpuIndex := 0
for scanner.Scan() {
ipmiFields := m.extractFieldsFromRegex(reV2ParseLine, scanner.Text())
if len(ipmiFields) < 3 || len(ipmiFields) > 4 {
continue
}

tag := transform(ipmiFields["name"])

if tag == "temp" {
cpuIndex++
cpuTag := convertToCPUTempTag(ipmiFields, cpuIndex)
if cpuTag == tag {
cpuIndex--
}
tag = cpuTag
}

tags := map[string]string{
"name": transform(ipmiFields["name"]),
"name": tag,
}

// tag the server is we have oneserver
Expand Down Expand Up @@ -327,6 +350,23 @@ func transform(s string) string {
return strings.ReplaceAll(s, " ", "_")
}

func convertToCPUTempTag(ipmiFields map[string]string, index int) string {
s := transform(ipmiFields["name"])
description := ipmiFields["description"]

if strings.Index(description, " ") > 0 {
// split middle column into value and unit
valunit := strings.SplitN(description, " ", 2)

if len(valunit) > 1 {
if transform(valunit[1]) == "degrees_c" {
return fmt.Sprintf("cpu%s_%s", strconv.Itoa(index), s)
}
}
}
return s
}

func init() {
inputs.Add("ipmi_sensor", func() telegraf.Input {
return &Ipmi{Timeout: config.Duration(20 * time.Second)}
Expand Down

0 comments on commit e313df4

Please sign in to comment.