forked from prometheus-community/windows_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
collector.go
39 lines (31 loc) · 921 Bytes
/
collector.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package collector
import (
"github.com/leoluk/perflib_exporter/perflib"
"github.com/prometheus/client_golang/prometheus"
)
// ...
const (
// TODO: Make package-local
Namespace = "wmi"
// Conversion factors
ticksToSecondsScaleFactor = 1 / 1e7
windowsEpoch = 116444736000000000
)
// Factories ...
var Factories = make(map[string]func() (Collector, error))
// Collector is the interface a collector has to implement.
type Collector interface {
// Get new metrics and expose them via prometheus registry.
Collect(ctx *ScrapeContext, ch chan<- prometheus.Metric) (err error)
}
type ScrapeContext struct {
perfObjects map[string]*perflib.PerfObject
}
// PrepareScrapeContext creates a ScrapeContext to be used during a single scrape
func PrepareScrapeContext() (*ScrapeContext, error) {
objs, err := getPerflibSnapshot()
if err != nil {
return nil, err
}
return &ScrapeContext{objs}, nil
}