Add config for exporting container metrics to prom

This adds an option for the cgroups monitor to include container metrics
in the prometheus output.  We will have to use the plugin to emit oom
events via the events service but when the `no_prom` setting is set for
the plugin container metrics will not be included in the prom output.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby
2017-09-07 13:18:00 -04:00
parent aa8bd16ae7
commit 72bcdb8fa9
4 changed files with 47 additions and 34 deletions

View File

@@ -15,24 +15,33 @@ import (
"golang.org/x/net/context"
)
type Config struct {
NoPrometheus bool `toml:"no_prometheus"`
}
func init() {
plugin.Register(&plugin.Registration{
Type: plugin.TaskMonitorPlugin,
ID: "cgroups",
Init: New,
Type: plugin.TaskMonitorPlugin,
ID: "cgroups",
Init: New,
Config: &Config{},
})
}
func New(ic *plugin.InitContext) (interface{}, error) {
var (
ns = metrics.NewNamespace("container", "", nil)
collector = NewCollector(ns)
)
var ns *metrics.Namespace
config := ic.Config.(*Config)
if !config.NoPrometheus {
ns = metrics.NewNamespace("container", "", nil)
}
collector := NewCollector(ns)
oom, err := NewOOMCollector(ns)
if err != nil {
return nil, err
}
metrics.Register(ns)
if ns != nil {
metrics.Register(ns)
}
return &cgroupsMonitor{
collector: collector,
oom: oom,