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

Report available fields if utmp is unreadable #4043

Merged
merged 1 commit into from
Apr 18, 2018
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
37 changes: 17 additions & 20 deletions plugins/inputs/system/SYSTEM_README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# System Input Plugin

The system plugin gathers general stats on system load, uptime,
and number of users logged in. It is basically equivalent
to the unix `uptime` command.
and number of users logged in. It is similar to the unix `uptime` command.

### Configuration:

Expand All @@ -11,29 +10,27 @@ to the unix `uptime` command.
[[inputs.system]]
# no configuration
```
#### Permissions:

### Measurements & Fields:
The `n_users` field requires read access to `/var/run/utmp`, and may require
the `telegraf` user to be added to the `utmp` group on some systems.

- system
- load1 (float)
- load15 (float)
- load5 (float)
- n_users (integer)
- n_cpus (integer)
- uptime (integer, seconds)
- uptime_format (string)

### Tags:
### Metrics:

None
- system
- fields:
- load1 (float)
- load15 (float)
- load5 (float)
- n_users (integer)
- n_cpus (integer)
- uptime (integer, seconds)
- uptime_format (string)

### Example Output:

```
$ telegraf --config ~/ws/telegraf.conf --input-filter system --test
* Plugin: system, Collection 1
* Plugin: inputs.system, Collection 1
> system,host=tyrion load1=3.72,load5=2.4,load15=2.1,n_users=3i,n_cpus=4i 1483964144000000000
> system,host=tyrion uptime=1249632i 1483964144000000000
> system,host=tyrion uptime_format="14 days, 11:07" 1483964144000000000
system,host=tyrion load1=3.72,load5=2.4,load15=2.1,n_users=3i,n_cpus=4i 1483964144000000000
system,host=tyrion uptime=1249632i 1483964144000000000
system,host=tyrion uptime_format="14 days, 11:07" 1483964144000000000
```
25 changes: 15 additions & 10 deletions plugins/inputs/system/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"bytes"
"fmt"
"os"
"runtime"
"strings"

Expand All @@ -28,23 +29,27 @@ func (_ *SystemStats) Gather(acc telegraf.Accumulator) error {
return err
}

hostinfo, err := host.Info()
if err != nil {
return err
fields := map[string]interface{}{
"load1": loadavg.Load1,
"load5": loadavg.Load5,
"load15": loadavg.Load15,
"n_cpus": runtime.NumCPU(),
}

users, err := host.Users()
if err == nil {
fields["n_users"] = len(users)
} else if !os.IsPermission(err) {
return err
}

acc.AddGauge("system", fields, nil)

hostinfo, err := host.Info()
if err != nil {
return err
}

acc.AddGauge("system", map[string]interface{}{
"load1": loadavg.Load1,
"load5": loadavg.Load5,
"load15": loadavg.Load15,
"n_users": len(users),
"n_cpus": runtime.NumCPU(),
}, nil)
acc.AddCounter("system", map[string]interface{}{
"uptime": hostinfo.Uptime,
}, nil)
Expand Down