Collect at every scrape, rather than at regular intervals.
Switch to Update using the Collecter Collect interface, due to not knowing all metricnames in all modules beforehand we can't use Describe and thus the full Collecter interface. Remove 'updates', it's meaning varies by module and doesn't add much.
This commit is contained in:
parent
5c15c86f77
commit
1c17481a42
17 changed files with 193 additions and 286 deletions
|
|
@ -41,29 +41,22 @@ func init() {
|
|||
// It exposes the number of configured and active slave of linux bonding interfaces.
|
||||
func NewBondingCollector(config Config) (Collector, error) {
|
||||
c := bondingCollector{}
|
||||
if _, err := prometheus.RegisterOrGet(bondingSlaves); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, err := prometheus.RegisterOrGet(bondingSlavesActive); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &c, nil
|
||||
}
|
||||
|
||||
// Update reads and exposes bonding states, implements Collector interface. Caution: This works only on linux.
|
||||
func (c *bondingCollector) Update() (int, error) {
|
||||
func (c *bondingCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||
bondingStats, err := readBondingStats(sysfsNet)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
return err
|
||||
}
|
||||
updates := 0
|
||||
for master, status := range bondingStats {
|
||||
bondingSlaves.WithLabelValues(master).Set(float64(status[0]))
|
||||
updates++
|
||||
bondingSlavesActive.WithLabelValues(master).Set(float64(status[1]))
|
||||
updates++
|
||||
}
|
||||
return updates, nil
|
||||
bondingSlaves.Collect(ch)
|
||||
bondingSlavesActive.Collect(ch)
|
||||
return nil
|
||||
}
|
||||
|
||||
func readBondingStats(root string) (status map[string][2]int, err error) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue