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

Added support for gosensors plugin #519

Closed
wants to merge 4 commits into from
Closed
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ configurations overwritten by the upgrade. There is a backup stored at
- Added ability to specify per-plugin measurement suffix and prefix.
(`name_prefix` and `name_suffix`)
- Added ability to override base plugin measurement name. (`name_override`)
- Added a sensors input based on lm-sensors

### Bugfixes

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ Telegraf currently has support for collecting metrics from:
* twemproxy
* zfs
* zookeeper
* sensors
* system
* cpu
* mem
Expand Down
1 change: 1 addition & 0 deletions plugins/inputs/all/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
_ "github.com/influxdb/telegraf/plugins/inputs/rabbitmq"
_ "github.com/influxdb/telegraf/plugins/inputs/redis"
_ "github.com/influxdb/telegraf/plugins/inputs/rethinkdb"
_ "github.com/influxdb/telegraf/plugins/inputs/sensors"
_ "github.com/influxdb/telegraf/plugins/inputs/statsd"
_ "github.com/influxdb/telegraf/plugins/inputs/system"
_ "github.com/influxdb/telegraf/plugins/inputs/trig"
Expand Down
90 changes: 90 additions & 0 deletions plugins/inputs/sensors/sensors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// +build linux

package sensors

import (
"strings"

"github.com/md14454/gosensors"

"github.com/influxdb/telegraf/plugins/inputs"
)

type Sensors struct {
Sensors []string
}

func (_ *Sensors) Description() string {
return "Monitor sensors using lm-sensors package"
}

var sensorsSampleConfig = `
# By default, telegraf gathers stats from all sensors
# detected by the lm-sensors module.
#
# Only collect stats from the selected sensors. Sensors
# are listed as <chip name>:<feature name>. This
# information can be found by running the sensors command.
# e.g. sensors -u
# A * as the feature name will return all features of the chip
#
# sensors = ["coretemp-isa-0000:Core 0", "coretemp-isa-0001:*", ... ]
`

func (_ *Sensors) SampleConfig() string {
return sensorsSampleConfig
}

func (s *Sensors) Gather(acc inputs.Accumulator) error {
gosensors.Init()
defer gosensors.Cleanup()

for _, chip := range gosensors.GetDetectedChips() {
for _, feature := range chip.GetFeatures() {
chipName := chip.String()
featureLabel := feature.GetLabel()

if len(s.Sensors) != 0 {
var found bool

for _, sensor := range s.Sensors {
parts := strings.SplitN(":", sensor, 2)

if parts[0] == chipName {
if parts[1] == "*" || parts[1] == featureLabel {
found = true
break
}
}
}

if !found {
continue
}
}

tags := map[string]string{
"chip": chipName,
"adapter": chip.AdapterName(),
"feature-name": feature.Name,
"feature-label": featureLabel,
}

fieldName := chipName + ":" + featureLabel

fields := map[string]interface{}{
fieldName: feature.GetValue(),
}

acc.AddFields("sensors", fields, tags)
}
}

return nil
}

func init() {
inputs.Add("sensors", func() inputs.Input {
return &Sensors{}
})
}