Add device, serial_no, and wwn tags to synthetic attributes (#6040)

This commit is contained in:
Daniel Nelson 2019-06-25 11:51:51 -07:00 committed by GitHub
parent e1cfc9f3a0
commit e8a596858c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 69 additions and 11 deletions

View File

@ -253,8 +253,6 @@ func gatherDisk(acc telegraf.Accumulator, usesudo, collectAttributes bool, smart
tags := map[string]string{}
fields := make(map[string]interface{})
attr := attribute.FindStringSubmatch(line)
if len(attr) > 1 {
if collectAttributes {
deviceNode := strings.Split(device, " ")[0]
tags["device"] = path.Base(deviceNode)
@ -265,6 +263,11 @@ func gatherDisk(acc telegraf.Accumulator, usesudo, collectAttributes bool, smart
if wwn, ok := deviceTags["wwn"]; ok {
tags["wwn"] = wwn
}
}
attr := attribute.FindStringSubmatch(line)
if len(attr) > 1 {
if collectAttributes {
tags["id"] = attr[1]
tags["name"] = attr[2]
tags["flags"] = attr[3]

View File

@ -4,7 +4,9 @@ import (
"errors"
"sync"
"testing"
"time"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -443,8 +445,61 @@ func TestGatherNvme(t *testing.T) {
wg.Add(1)
gatherDisk(acc, true, true, "", "", "", wg)
assert.Equal(t, 6, acc.NFields(), "Wrong number of fields gathered")
assert.Equal(t, uint64(4), acc.NMetrics(), "Wrong number of metrics gathered")
expected := []telegraf.Metric{
testutil.MustMetric("smart_device",
map[string]string{
"device": ".",
"model": "TS128GMTE850",
"serial_no": "D704940282?",
},
map[string]interface{}{
"exit_status": 0,
"health_ok": true,
"temp_c": 38,
},
time.Now(),
),
testutil.MustMetric("smart_attribute",
map[string]string{
"device": ".",
"id": "9",
"name": "Power_On_Hours",
"serial_no": "D704940282?",
},
map[string]interface{}{
"raw_value": 6038,
},
time.Now(),
),
testutil.MustMetric("smart_attribute",
map[string]string{
"device": ".",
"id": "12",
"name": "Power_Cycle_Count",
"serial_no": "D704940282?",
},
map[string]interface{}{
"raw_value": 472,
},
time.Now(),
),
testutil.MustMetric("smart_attribute",
map[string]string{
"device": ".",
"id": "194",
"name": "Temperature_Celsius",
"serial_no": "D704940282?",
},
map[string]interface{}{
"raw_value": 38,
},
time.Now(),
),
}
testutil.RequireMetricsEqual(t, expected, acc.GetTelegrafMetrics(),
testutil.SortMetrics(), testutil.IgnoreTime())
}
// smartctl output