Early init of procfs (#1315)
Minor change to match naming convention in other collectors. Initialize the proc or sys FS instance once while initializing each collector instead of re-creating for each metric update. Signed-off-by: Paul Gier <pgier@redhat.com>
This commit is contained in:
parent
fbe390709f
commit
b1298677aa
8 changed files with 63 additions and 47 deletions
|
|
@ -24,6 +24,7 @@ import (
|
|||
)
|
||||
|
||||
type statCollector struct {
|
||||
fs procfs.FS
|
||||
intr *prometheus.Desc
|
||||
ctxt *prometheus.Desc
|
||||
forks *prometheus.Desc
|
||||
|
|
@ -38,7 +39,12 @@ func init() {
|
|||
|
||||
// NewStatCollector returns a new Collector exposing kernel/system statistics.
|
||||
func NewStatCollector() (Collector, error) {
|
||||
fs, err := procfs.NewFS(*procPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open procfs: %v", err)
|
||||
}
|
||||
return &statCollector{
|
||||
fs: fs,
|
||||
intr: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, "", "intr_total"),
|
||||
"Total number of interrupts serviced.",
|
||||
|
|
@ -74,11 +80,7 @@ func NewStatCollector() (Collector, error) {
|
|||
|
||||
// Update implements Collector and exposes kernel and system statistics.
|
||||
func (c *statCollector) Update(ch chan<- prometheus.Metric) error {
|
||||
fs, err := procfs.NewFS(*procPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open procfs: %v", err)
|
||||
}
|
||||
stats, err := fs.NewStat()
|
||||
stats, err := c.fs.NewStat()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue