cubefs
63 строки · 2.1 Кб
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
17package procfs
18
19import (
20"os"
21
22"github.com/prometheus/procfs/internal/util"
23)
24
25// KernelRandom contains information about to the kernel's random number generator.
26type KernelRandom struct {
27// EntropyAvaliable gives the available entropy, in bits.
28EntropyAvaliable *uint64
29// PoolSize gives the size of the entropy pool, in bits.
30PoolSize *uint64
31// URandomMinReseedSeconds is the number of seconds after which the DRNG will be reseeded.
32URandomMinReseedSeconds *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.
35WriteWakeupThreshold *uint64
36// ReadWakeupThreshold is the number of bits of entropy required for waking up processes that sleep
37// waiting for entropy from /dev/random.
38ReadWakeupThreshold *uint64
39}
40
41// KernelRandom returns values from /proc/sys/kernel/random.
42func (fs FS) KernelRandom() (KernelRandom, error) {
43random := KernelRandom{}
44
45for 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} {
52val, err := util.ReadUintFromFile(fs.proc.Path("sys", "kernel", "random", file))
53if os.IsNotExist(err) {
54continue
55}
56if err != nil {
57return random, err
58}
59*p = &val
60}
61
62return random, nil
63}
64