diff options
Diffstat (limited to 'vendor/github.com/prometheus/procfs/kernel_random.go')
-rw-r--r-- | vendor/github.com/prometheus/procfs/kernel_random.go | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/vendor/github.com/prometheus/procfs/kernel_random.go b/vendor/github.com/prometheus/procfs/kernel_random.go new file mode 100644 index 0000000..beefdf0 --- /dev/null +++ b/vendor/github.com/prometheus/procfs/kernel_random.go | |||
@@ -0,0 +1,62 @@ | |||
1 | // Copyright 2020 The Prometheus Authors | ||
2 | // Licensed under the Apache License, Version 2.0 (the "License"); | ||
3 | // you may not use this file except in compliance with the License. | ||
4 | // You may obtain a copy of the License at | ||
5 | // | ||
6 | // http://www.apache.org/licenses/LICENSE-2.0 | ||
7 | // | ||
8 | // Unless required by applicable law or agreed to in writing, software | ||
9 | // distributed under the License is distributed on an "AS IS" BASIS, | ||
10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
11 | // See the License for the specific language governing permissions and | ||
12 | // limitations under the License. | ||
13 | |||
14 | // +build !windows | ||
15 | |||
16 | package procfs | ||
17 | |||
18 | import ( | ||
19 | "os" | ||
20 | |||
21 | "github.com/prometheus/procfs/internal/util" | ||
22 | ) | ||
23 | |||
24 | // KernelRandom contains information about to the kernel's random number generator. | ||
25 | type KernelRandom struct { | ||
26 | // EntropyAvaliable gives the available entropy, in bits. | ||
27 | EntropyAvaliable *uint64 | ||
28 | // PoolSize gives the size of the entropy pool, in bytes. | ||
29 | PoolSize *uint64 | ||
30 | // URandomMinReseedSeconds is the number of seconds after which the DRNG will be reseeded. | ||
31 | URandomMinReseedSeconds *uint64 | ||
32 | // WriteWakeupThreshold the number of bits of entropy below which we wake up processes | ||
33 | // that do a select(2) or poll(2) for write access to /dev/random. | ||
34 | WriteWakeupThreshold *uint64 | ||
35 | // ReadWakeupThreshold is the number of bits of entropy required for waking up processes that sleep | ||
36 | // waiting for entropy from /dev/random. | ||
37 | ReadWakeupThreshold *uint64 | ||
38 | } | ||
39 | |||
40 | // KernelRandom returns values from /proc/sys/kernel/random. | ||
41 | func (fs FS) KernelRandom() (KernelRandom, error) { | ||
42 | random := KernelRandom{} | ||
43 | |||
44 | for file, p := range map[string]**uint64{ | ||
45 | "entropy_avail": &random.EntropyAvaliable, | ||
46 | "poolsize": &random.PoolSize, | ||
47 | "urandom_min_reseed_secs": &random.URandomMinReseedSeconds, | ||
48 | "write_wakeup_threshold": &random.WriteWakeupThreshold, | ||
49 | "read_wakeup_threshold": &random.ReadWakeupThreshold, | ||
50 | } { | ||
51 | val, err := util.ReadUintFromFile(fs.proc.Path("sys", "kernel", "random", file)) | ||
52 | if os.IsNotExist(err) { | ||
53 | continue | ||
54 | } | ||
55 | if err != nil { | ||
56 | return random, err | ||
57 | } | ||
58 | *p = &val | ||
59 | } | ||
60 | |||
61 | return random, nil | ||
62 | } | ||