Skip to content

Commit

Permalink
Add source tag to hddtemp plugin (influxdata#5955)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielnelson authored and Helge Waastad committed Jun 13, 2019
1 parent 7f9e3a2 commit 02e6bf3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 29 deletions.
54 changes: 26 additions & 28 deletions plugins/inputs/hddtemp/README.md
Original file line number Diff line number Diff line change
@@ -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
```
9 changes: 8 additions & 1 deletion plugins/inputs/hddtemp/hddtemp.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
}
Expand All @@ -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{}{
Expand Down
3 changes: 3 additions & 0 deletions plugins/inputs/hddtemp/hddtemp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func newMockFetcher() *mockFetcher {
func TestFetch(t *testing.T) {
hddtemp := &HDDTemp{
fetcher: newMockFetcher(),
Address: "localhost",
Devices: []string{"*"},
}

Expand All @@ -58,6 +59,7 @@ func TestFetch(t *testing.T) {
"model": "Model1",
"unit": "C",
"status": "",
"source": "localhost",
},
},
{
Expand All @@ -69,6 +71,7 @@ func TestFetch(t *testing.T) {
"model": "Model2",
"unit": "C",
"status": "",
"source": "localhost",
},
},
}
Expand Down

0 comments on commit 02e6bf3

Please sign in to comment.