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

Monitor available entropy #3524

Merged
merged 5 commits into from
Jan 5, 2018
Merged
Show file tree
Hide file tree
Changes from 3 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
11 changes: 9 additions & 2 deletions plugins/inputs/system/KERNEL_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ This plugin is only available on Linux.

The kernel plugin gathers info about the kernel that doesn't fit into other
plugins. In general, it is the statistics available in `/proc/stat` that are
not covered by other plugins.
not covered by other plugins as well as the value of `/proc/sys/kernel/random/entropy_avail`

The metrics are documented in `man proc` under the `/proc/stat` section.
The metrics are documented in `man 4 random` under the `/proc/stat` section.

```


/proc/sys/kernel/random/entropy_avail
Contains the value of available entropy

/proc/stat
kernel/system statistics. Varies with architecture. Common entries include:

Expand Down Expand Up @@ -50,6 +56,7 @@ Number of forks since boot.
- disk_pages_out (integer, `page (1)`)
- interrupts (integer, `intr`)
- processes_forked (integer, `processes`)
- entropy_avail (integer, `entropy_available`)

### Tags:

Expand All @@ -60,5 +67,5 @@ None
```
$ telegraf --config ~/ws/telegraf.conf --input-filter kernel --test
* Plugin: kernel, Collection 1
> kernel boot_time=1457505775i,context_switches=2626618i,disk_pages_in=5741i,disk_pages_out=1808i,interrupts=1472736i,processes_forked=10673i 1457613402960879816
> kernel entropy_available=2469i,boot_time=1457505775i,context_switches=2626618i,disk_pages_in=5741i,disk_pages_out=1808i,interrupts=1472736i,processes_forked=10673i 1457613402960879816
```
21 changes: 19 additions & 2 deletions plugins/inputs/system/kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io/ioutil"
"os"
"strconv"
"strings"

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/inputs"
Expand All @@ -23,7 +24,8 @@ var (
)

type Kernel struct {
statFile string
statFile string
entropyStatFile string
}

func (k *Kernel) Description() string {
Expand All @@ -33,13 +35,27 @@ func (k *Kernel) Description() string {
func (k *Kernel) SampleConfig() string { return "" }

func (k *Kernel) Gather(acc telegraf.Accumulator) error {

data, err := k.getProcStat()
if err != nil {
return err
}

entropyData, err := ioutil.ReadFile(k.entropyStatFile)
if err != nil {
return err
}

entropyString := string(entropyData)
entropyValue, err := strconv.ParseInt(strings.TrimSpace(entropyString), 10, 64)
if err != nil {
return err
}

fields := make(map[string]interface{})

fields["entropy_available"] = int64(entropyValue)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just call it entropy_avail to match what is in proc.


dataFields := bytes.Fields(data)
for i, field := range dataFields {
switch {
Expand Down Expand Up @@ -104,7 +120,8 @@ func (k *Kernel) getProcStat() ([]byte, error) {
func init() {
inputs.Add("kernel", func() telegraf.Input {
return &Kernel{
statFile: "/proc/stat",
statFile: "/proc/stat",
entropyStatFile: "/proc/sys/kernel/random/entropy_avail",
}
})
}