Add source tag to hddtemp plugin (#5955)

This commit is contained in:
Daniel Nelson 2019-06-05 12:47:17 -07:00 committed by GitHub
parent 77cac557ba
commit 7be74816a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 29 deletions

View File

@ -1,43 +1,41 @@
# Hddtemp Input Plugin
# HDDtemp Input Plugin
This plugin reads data from hddtemp daemon
This plugin reads data from hddtemp daemon.
## Requirements
Hddtemp should be installed and its daemon running.
Hddtemp should be installed and its daemon running
## Configuration
### Configuration
```toml
[[inputs.hddtemp]]
## By default, telegraf gathers temps data from all disks detected by the
## hddtemp.
##
## Only collect temps from the selected disks.
##
## A * as the device name will return the temperature values of all disks.
##
# address = "127.0.0.1:7634"
# devices = ["sda", "*"]
## By default, telegraf gathers temps data from all disks detected by the
## hddtemp.
##
## Only collect temps from the selected disks.
##
## A * as the device name will return the temperature values of all disks.
##
# address = "127.0.0.1:7634"
# devices = ["sda", "*"]
```
## Measurements
### Metrics
- hddtemp
- temperature
Tags:
- device
- model
- unit
- status
- tags:
- device
- model
- unit
- status
- source
- fields:
- temperature
## Example output
### Example output
```
> hddtemp,unit=C,status=,host=server1,device=sdb,model=WDC\ WD740GD-00FLA1 temperature=43i 1481655647000000000
> hddtemp,device=sdc,model=SAMSUNG\ HD103UI,unit=C,status=,host=server1 temperature=38i 148165564700000000
> hddtemp,device=sdd,model=SAMSUNG\ HD103UI,unit=C,status=,host=server1 temperature=36i 1481655647000000000
hddtemp,source=server1,unit=C,status=,device=sdb,model=WDC\ WD740GD-00FLA1 temperature=43i 1481655647000000000
hddtemp,device=sdc,model=SAMSUNG\ HD103UI,unit=C,source=server1,status= temperature=38i 148165564700000000
hddtemp,device=sdd,model=SAMSUNG\ HD103UI,unit=C,source=server1,status= temperature=36i 1481655647000000000
```

View File

@ -1,6 +1,8 @@
package hddtemp
import (
"net"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/inputs"
gohddtemp "github.com/influxdata/telegraf/plugins/inputs/hddtemp/go-hddtemp"
@ -42,8 +44,12 @@ func (h *HDDTemp) Gather(acc telegraf.Accumulator) error {
if h.fetcher == nil {
h.fetcher = gohddtemp.New()
}
disks, err := h.fetcher.Fetch(h.Address)
source, _, err := net.SplitHostPort(h.Address)
if err != nil {
source = h.Address
}
disks, err := h.fetcher.Fetch(h.Address)
if err != nil {
return err
}
@ -56,6 +62,7 @@ func (h *HDDTemp) Gather(acc telegraf.Accumulator) error {
"model": disk.Model,
"unit": disk.Unit,
"status": disk.Status,
"source": source,
}
fields := map[string]interface{}{

View File

@ -36,6 +36,7 @@ func newMockFetcher() *mockFetcher {
func TestFetch(t *testing.T) {
hddtemp := &HDDTemp{
fetcher: newMockFetcher(),
Address: "localhost",
Devices: []string{"*"},
}
@ -58,6 +59,7 @@ func TestFetch(t *testing.T) {
"model": "Model1",
"unit": "C",
"status": "",
"source": "localhost",
},
},
{
@ -69,6 +71,7 @@ func TestFetch(t *testing.T) {
"model": "Model2",
"unit": "C",
"status": "",
"source": "localhost",
},
},
}