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 //go:build !windows 15 // +build !windows 16 17 package procfs 18 19 import ( 20 "os" 21 22 "github.com/prometheus/procfs/internal/util" 23 ) 24 25 // KernelRandom contains information about to the kernel's random number generator. 26 type KernelRandom struct { 27 // EntropyAvaliable gives the available entropy, in bits. 28 EntropyAvaliable *uint64 29 // PoolSize gives the size of the entropy pool, in bits. 30 PoolSize *uint64 31 // URandomMinReseedSeconds is the number of seconds after which the DRNG will be reseeded. 32 URandomMinReseedSeconds *uint64 33 // WriteWakeupThreshold the number of bits of entropy below which we wake up processes 34 // that do a select(2) or poll(2) for write access to /dev/random. 35 WriteWakeupThreshold *uint64 36 // ReadWakeupThreshold is the number of bits of entropy required for waking up processes that sleep 37 // waiting for entropy from /dev/random. 38 ReadWakeupThreshold *uint64 39 } 40 41 // KernelRandom returns values from /proc/sys/kernel/random. 42 func (fs FS) KernelRandom() (KernelRandom, error) { 43 random := KernelRandom{} 44 45 for file, p := range map[string]**uint64{ 46 "entropy_avail": &random.EntropyAvaliable, 47 "poolsize": &random.PoolSize, 48 "urandom_min_reseed_secs": &random.URandomMinReseedSeconds, 49 "write_wakeup_threshold": &random.WriteWakeupThreshold, 50 "read_wakeup_threshold": &random.ReadWakeupThreshold, 51 } { 52 val, err := util.ReadUintFromFile(fs.proc.Path("sys", "kernel", "random", file)) 53 if os.IsNotExist(err) { 54 continue 55 } 56 if err != nil { 57 return random, err 58 } 59 *p = &val 60 } 61 62 return random, nil 63 } 64