Ignore error when utmp is missing (#5742)
This commit is contained in:
parent
bd9ddd8cb1
commit
a5c94db625
|
@ -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:
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue