mirror of
				https://github.com/prometheus/node_exporter.git
				synced 2025-08-20 18:33:52 -07:00 
			
		
		
		
	Merge pull request #1753 from binjip978/entropy
add pool size to entropy collector
This commit is contained in:
		
						commit
						9fab63825b
					
				| 
						 | 
				
			
			@ -20,11 +20,14 @@ import (
 | 
			
		|||
 | 
			
		||||
	"github.com/go-kit/kit/log"
 | 
			
		||||
	"github.com/prometheus/client_golang/prometheus"
 | 
			
		||||
	"github.com/prometheus/procfs"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type entropyCollector struct {
 | 
			
		||||
	entropyAvail *prometheus.Desc
 | 
			
		||||
	logger       log.Logger
 | 
			
		||||
	fs              procfs.FS
 | 
			
		||||
	entropyAvail    *prometheus.Desc
 | 
			
		||||
	entropyPoolSize *prometheus.Desc
 | 
			
		||||
	logger          log.Logger
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func init() {
 | 
			
		||||
| 
						 | 
				
			
			@ -33,23 +36,44 @@ func init() {
 | 
			
		|||
 | 
			
		||||
// NewEntropyCollector returns a new Collector exposing entropy stats.
 | 
			
		||||
func NewEntropyCollector(logger log.Logger) (Collector, error) {
 | 
			
		||||
	fs, err := procfs.NewFS(*procPath)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, fmt.Errorf("failed to open procfs: %w", err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &entropyCollector{
 | 
			
		||||
		fs: fs,
 | 
			
		||||
		entropyAvail: prometheus.NewDesc(
 | 
			
		||||
			prometheus.BuildFQName(namespace, "", "entropy_available_bits"),
 | 
			
		||||
			"Bits of available entropy.",
 | 
			
		||||
			nil, nil,
 | 
			
		||||
		),
 | 
			
		||||
		entropyPoolSize: prometheus.NewDesc(
 | 
			
		||||
			prometheus.BuildFQName(namespace, "", "entropy_pool_size_bits"),
 | 
			
		||||
			"Bits of entropy pool.",
 | 
			
		||||
			nil, nil,
 | 
			
		||||
		),
 | 
			
		||||
		logger: logger,
 | 
			
		||||
	}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *entropyCollector) Update(ch chan<- prometheus.Metric) error {
 | 
			
		||||
	value, err := readUintFromFile(procFilePath("sys/kernel/random/entropy_avail"))
 | 
			
		||||
	stats, err := c.fs.KernelRandom()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return fmt.Errorf("couldn't get entropy_avail: %w", err)
 | 
			
		||||
		return fmt.Errorf("failed to get kernel random stats: %w", err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if stats.EntropyAvaliable == nil {
 | 
			
		||||
		return fmt.Errorf("couldn't get entropy_avail")
 | 
			
		||||
	}
 | 
			
		||||
	ch <- prometheus.MustNewConstMetric(
 | 
			
		||||
		c.entropyAvail, prometheus.GaugeValue, float64(value))
 | 
			
		||||
		c.entropyAvail, prometheus.GaugeValue, float64(*stats.EntropyAvaliable))
 | 
			
		||||
 | 
			
		||||
	if stats.PoolSize == nil {
 | 
			
		||||
		return fmt.Errorf("couldn't get entropy poolsize")
 | 
			
		||||
	}
 | 
			
		||||
	ch <- prometheus.MustNewConstMetric(
 | 
			
		||||
		c.entropyPoolSize, prometheus.GaugeValue, float64(*stats.PoolSize))
 | 
			
		||||
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -654,6 +654,9 @@ node_edac_uncorrectable_errors_total{controller="0"} 5
 | 
			
		|||
# HELP node_entropy_available_bits Bits of available entropy.
 | 
			
		||||
# TYPE node_entropy_available_bits gauge
 | 
			
		||||
node_entropy_available_bits 1337
 | 
			
		||||
# HELP node_entropy_pool_size_bits Bits of entropy pool.
 | 
			
		||||
# TYPE node_entropy_pool_size_bits gauge
 | 
			
		||||
node_entropy_pool_size_bits 4096
 | 
			
		||||
# HELP node_exporter_build_info A metric with a constant '1' value labeled by version, revision, branch, and goversion from which node_exporter was built.
 | 
			
		||||
# TYPE node_exporter_build_info gauge
 | 
			
		||||
# HELP node_filefd_allocated File descriptor statistics: allocated.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										1
									
								
								collector/fixtures/proc/sys/kernel/random/poolsize
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								collector/fixtures/proc/sys/kernel/random/poolsize
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
4096
 | 
			
		||||
		Loading…
	
		Reference in a new issue