Bump cgroups pkg to e950a27f3faf567abbf995bfbec90

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby
2017-04-13 14:24:59 -07:00
parent d41f146eed
commit e745efdddb
3 changed files with 15 additions and 6 deletions

View File

@@ -16,6 +16,10 @@ var (
ErrCgroupNotExists = errors.New("cgroup does not exist in the collector")
)
// Trigger will be called when an event happens and provides the cgroup
// where the event originated from
type Trigger func(string, cgroups.Cgroup)
// New registers the Collector with the provided namespace and returns it so
// that cgroups can be added for collection
func New(ns *metrics.Namespace) *Collector {

View File

@@ -33,11 +33,12 @@ type OOMCollector struct {
}
type oom struct {
id string
c cgroups.Cgroup
id string
c cgroups.Cgroup
triggers []Trigger
}
func (o *OOMCollector) Add(id string, cg cgroups.Cgroup) error {
func (o *OOMCollector) Add(id string, cg cgroups.Cgroup, triggers ...Trigger) error {
o.mu.Lock()
defer o.mu.Unlock()
fd, err := cg.OOMEventFD()
@@ -45,8 +46,9 @@ func (o *OOMCollector) Add(id string, cg cgroups.Cgroup) error {
return err
}
o.set[fd] = &oom{
id: id,
c: cg,
id: id,
c: cg,
triggers: triggers,
}
// set the gauge's default value
o.memoryOOM.WithValues(id).Set(0)
@@ -102,6 +104,9 @@ func (o *OOMCollector) process(fd uintptr, event uint32) {
return
}
o.memoryOOM.WithValues(info.id).Inc(1)
for _, t := range info.triggers {
t(info.id, info.c)
}
}
func flush(fd uintptr) error {