You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 rivejä
2.1 KiB

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