Skip to content
Open
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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ To integrate with telegraf, extend the telegraf.conf using the following example
Parent = ["intelcpu_0"] # optional
```

if you want to use it with LibreHardwareMonitor
add the following to your configuration.

https://github.com/LibreHardwareMonitor/LibreHardwareMonitor/tree/master/LibreHardwareMonitor

```
WmiNamespace = "root/LibreHardwareMonitor"
```

### Measurements & Fields:

- All sensors provided by OpenHardwareMonitor or specify subset defined in the SensorsType configuration.
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ go 1.15
require (
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6
github.com/influxdata/telegraf v1.17.0
github.com/influxdata/toml v0.0.0-20190415235208-270119a8ce65
github.com/stretchr/testify v1.6.1
)
24 changes: 18 additions & 6 deletions plugins/inputs/open_hardware_monitor/open_hardware_monitor.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
//go:build windows
// +build windows

package open_hardware_monitor

import (
"fmt"
"strings"

"github.com/StackExchange/wmi"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/inputs"
"strings"
)

type OpenHardwareMonitorConfig struct {
SensorsType []string
Parent []string
SensorsType []string
Parent []string
WmiNamespace string
}

type OpenHardwareMonitorData struct {
Expand All @@ -29,9 +32,12 @@ func (p *OpenHardwareMonitorConfig) Description() string {
const sampleConfig = `
## Sensors to query ( if not given then all is queried )
SensorsType = ["Temperature", "Fan", "Voltage"] # optional

## Which hardware should be available
Parent = ["_intelcpu_0"] # optional

## WMI namespace to use (default: root/OpenHardwareMonitor)
WmiNamespace = "root/OpenHardwareMonitor" # optional
`

func (p *OpenHardwareMonitorConfig) SampleConfig() string {
Expand All @@ -53,7 +59,11 @@ func (p *OpenHardwareMonitorConfig) CreateQuery() (string, error) {

func (p *OpenHardwareMonitorConfig) QueryData(query string) ([]OpenHardwareMonitorData, error) {
var dst []OpenHardwareMonitorData
err := wmi.QueryNamespace(query, &dst, "root/OpenHardwareMonitor")
ns := p.WmiNamespace
if ns == "" {
ns = "root/OpenHardwareMonitor"
}
err := wmi.QueryNamespace(query, &dst, ns)

// Replace all spaces
replace := map[string]string{
Expand Down Expand Up @@ -109,6 +119,8 @@ func (p *OpenHardwareMonitorConfig) Gather(acc telegraf.Accumulator) error {

func init() {
inputs.Add("open_hardware_monitor", func() telegraf.Input {
return &OpenHardwareMonitorConfig{}
return &OpenHardwareMonitorConfig{
WmiNamespace: "root/OpenHardwareMonitor",
}
})
}