Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add source tag to hddtemp plugin #5955

Merged
merged 1 commit into from
Jun 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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