Skip to content

Commit

Permalink
Ignore error when utmp is missing (#5742)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehlerst authored and danielnelson committed Jun 25, 2019
1 parent bd9ddd8 commit a5c94db
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion plugins/inputs/system/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ and number of users logged in. It is similar to the unix `uptime` command.
#### Permissions:

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.
the `telegraf` user to be added to the `utmp` group on some systems. If this file does not exist `n_users` will be skipped.

### Metrics:

Expand Down
7 changes: 5 additions & 2 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"
"log"
"os"
"runtime"
"strings"
Expand Down Expand Up @@ -44,8 +45,10 @@ func (_ *SystemStats) Gather(acc telegraf.Accumulator) error {
users, err := host.Users()
if err == nil {
fields["n_users"] = len(users)
} else if !os.IsPermission(err) {
return err
} else if os.IsNotExist(err) {
log.Printf("D! [inputs.system] Error reading users: %v", err)
} else if os.IsPermission(err) {
log.Printf("D! [inputs.system] %v", err)
}

now := time.Now()
Expand Down

0 comments on commit a5c94db

Please sign in to comment.