2016-07-21 16:00:54 +00:00
|
|
|
// +build linux
|
|
|
|
|
|
|
|
package hddtemp
|
|
|
|
|
|
|
|
import (
|
2016-12-23 15:18:27 +00:00
|
|
|
"github.com/influxdata/telegraf/plugins"
|
2016-07-21 16:00:54 +00:00
|
|
|
"github.com/influxdata/telegraf/plugins/inputs"
|
|
|
|
gohddtemp "github.com/influxdata/telegraf/plugins/inputs/hddtemp/go-hddtemp"
|
|
|
|
)
|
|
|
|
|
|
|
|
const defaultAddress = "127.0.0.1:7634"
|
|
|
|
|
|
|
|
type HDDTemp struct {
|
|
|
|
Address string
|
|
|
|
Devices []string
|
2016-12-13 19:40:55 +00:00
|
|
|
fetcher Fetcher
|
|
|
|
}
|
|
|
|
|
|
|
|
type Fetcher interface {
|
|
|
|
Fetch(address string) ([]gohddtemp.Disk, error)
|
2016-07-21 16:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (_ *HDDTemp) Description() string {
|
|
|
|
return "Monitor disks' temperatures using hddtemp"
|
|
|
|
}
|
|
|
|
|
|
|
|
var hddtempSampleConfig = `
|
|
|
|
## 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", "*"]
|
|
|
|
`
|
|
|
|
|
|
|
|
func (_ *HDDTemp) SampleConfig() string {
|
|
|
|
return hddtempSampleConfig
|
|
|
|
}
|
|
|
|
|
2016-12-23 15:18:27 +00:00
|
|
|
func (h *HDDTemp) Gather(acc plugins.Accumulator) error {
|
2016-12-13 19:40:55 +00:00
|
|
|
if h.fetcher == nil {
|
|
|
|
h.fetcher = gohddtemp.New()
|
|
|
|
}
|
|
|
|
disks, err := h.fetcher.Fetch(h.Address)
|
2016-07-21 16:00:54 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, disk := range disks {
|
|
|
|
for _, chosenDevice := range h.Devices {
|
|
|
|
if chosenDevice == "*" || chosenDevice == disk.DeviceName {
|
|
|
|
tags := map[string]string{
|
|
|
|
"device": disk.DeviceName,
|
|
|
|
"model": disk.Model,
|
|
|
|
"unit": disk.Unit,
|
|
|
|
"status": disk.Status,
|
|
|
|
}
|
|
|
|
|
|
|
|
fields := map[string]interface{}{
|
2016-12-13 19:40:55 +00:00
|
|
|
"temperature": disk.Temperature,
|
2016-07-21 16:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
acc.AddFields("hddtemp", fields, tags)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2016-12-23 15:18:27 +00:00
|
|
|
inputs.Add("hddtemp", func() plugins.Input {
|
2016-07-21 16:00:54 +00:00
|
|
|
return &HDDTemp{
|
|
|
|
Address: defaultAddress,
|
|
|
|
Devices: []string{"*"},
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|