Comment more packages to pass go lint
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
// Config for the cgroups monitor
|
||||
type Config struct {
|
||||
NoPrometheus bool `toml:"no_prometheus"`
|
||||
}
|
||||
@@ -28,14 +29,15 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
// New returns a new cgroups monitor
|
||||
func New(ic *plugin.InitContext) (interface{}, error) {
|
||||
var ns *metrics.Namespace
|
||||
config := ic.Config.(*Config)
|
||||
if !config.NoPrometheus {
|
||||
ns = metrics.NewNamespace("container", "", nil)
|
||||
}
|
||||
collector := NewCollector(ns)
|
||||
oom, err := NewOOMCollector(ns)
|
||||
collector := newCollector(ns)
|
||||
oom, err := newOOMCollector(ns)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -51,8 +53,8 @@ func New(ic *plugin.InitContext) (interface{}, error) {
|
||||
}
|
||||
|
||||
type cgroupsMonitor struct {
|
||||
collector *Collector
|
||||
oom *OOMCollector
|
||||
collector *collector
|
||||
oom *oomCollector
|
||||
context context.Context
|
||||
publisher events.Publisher
|
||||
}
|
||||
|
||||
@@ -14,22 +14,24 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrAlreadyCollected is returned when a cgroups is already being monitored
|
||||
ErrAlreadyCollected = errors.New("cgroup is already being collected")
|
||||
ErrCgroupNotExists = errors.New("cgroup does not exist in the collector")
|
||||
// ErrCgroupNotExists is returns when a cgroup no longer exists
|
||||
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, string, cgroups.Cgroup)
|
||||
|
||||
// New registers the Collector with the provided namespace and returns it so
|
||||
// newCollector registers the collector with the provided namespace and returns it so
|
||||
// that cgroups can be added for collection
|
||||
func NewCollector(ns *metrics.Namespace) *Collector {
|
||||
func newCollector(ns *metrics.Namespace) *collector {
|
||||
if ns == nil {
|
||||
return &Collector{}
|
||||
return &collector{}
|
||||
}
|
||||
// add machine cpus and memory info
|
||||
c := &Collector{
|
||||
c := &collector{
|
||||
ns: ns,
|
||||
cgroups: make(map[string]*task),
|
||||
}
|
||||
@@ -52,9 +54,9 @@ func taskID(id, namespace string) string {
|
||||
return fmt.Sprintf("%s-%s", id, namespace)
|
||||
}
|
||||
|
||||
// Collector provides the ability to collect container stats and export
|
||||
// collector provides the ability to collect container stats and export
|
||||
// them in the prometheus format
|
||||
type Collector struct {
|
||||
type collector struct {
|
||||
mu sync.RWMutex
|
||||
|
||||
cgroups map[string]*task
|
||||
@@ -62,13 +64,13 @@ type Collector struct {
|
||||
metrics []*metric
|
||||
}
|
||||
|
||||
func (c *Collector) Describe(ch chan<- *prometheus.Desc) {
|
||||
func (c *collector) Describe(ch chan<- *prometheus.Desc) {
|
||||
for _, m := range c.metrics {
|
||||
ch <- m.desc(c.ns)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Collector) Collect(ch chan<- prometheus.Metric) {
|
||||
func (c *collector) Collect(ch chan<- prometheus.Metric) {
|
||||
c.mu.RLock()
|
||||
wg := &sync.WaitGroup{}
|
||||
for _, t := range c.cgroups {
|
||||
@@ -79,7 +81,7 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) {
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func (c *Collector) collect(id, namespace string, cg cgroups.Cgroup, ch chan<- prometheus.Metric, wg *sync.WaitGroup) {
|
||||
func (c *collector) collect(id, namespace string, cg cgroups.Cgroup, ch chan<- prometheus.Metric, wg *sync.WaitGroup) {
|
||||
defer wg.Done()
|
||||
stats, err := cg.Stat(cgroups.IgnoreNotExist)
|
||||
if err != nil {
|
||||
@@ -92,7 +94,7 @@ func (c *Collector) collect(id, namespace string, cg cgroups.Cgroup, ch chan<- p
|
||||
}
|
||||
|
||||
// Add adds the provided cgroup and id so that metrics are collected and exported
|
||||
func (c *Collector) Add(id, namespace string, cg cgroups.Cgroup) error {
|
||||
func (c *collector) Add(id, namespace string, cg cgroups.Cgroup) error {
|
||||
if c.ns == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -110,7 +112,7 @@ func (c *Collector) Add(id, namespace string, cg cgroups.Cgroup) error {
|
||||
}
|
||||
|
||||
// Remove removes the provided cgroup by id from the collector
|
||||
func (c *Collector) Remove(id, namespace string) {
|
||||
func (c *collector) Remove(id, namespace string) {
|
||||
if c.ns == nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func NewOOMCollector(ns *metrics.Namespace) (*OOMCollector, error) {
|
||||
func newOOMCollector(ns *metrics.Namespace) (*oomCollector, error) {
|
||||
fd, err := unix.EpollCreate1(unix.EPOLL_CLOEXEC)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -23,7 +23,7 @@ func NewOOMCollector(ns *metrics.Namespace) (*OOMCollector, error) {
|
||||
if ns != nil {
|
||||
desc = ns.NewDesc("memory_oom", "The number of times a container has received an oom event", metrics.Total, "container_id", "namespace")
|
||||
}
|
||||
c := &OOMCollector{
|
||||
c := &oomCollector{
|
||||
fd: fd,
|
||||
desc: desc,
|
||||
set: make(map[uintptr]*oom),
|
||||
@@ -35,7 +35,7 @@ func NewOOMCollector(ns *metrics.Namespace) (*OOMCollector, error) {
|
||||
return c, nil
|
||||
}
|
||||
|
||||
type OOMCollector struct {
|
||||
type oomCollector struct {
|
||||
mu sync.Mutex
|
||||
|
||||
desc *prometheus.Desc
|
||||
@@ -51,7 +51,7 @@ type oom struct {
|
||||
count int64
|
||||
}
|
||||
|
||||
func (o *OOMCollector) Add(id, namespace string, cg cgroups.Cgroup, triggers ...Trigger) error {
|
||||
func (o *oomCollector) Add(id, namespace string, cg cgroups.Cgroup, triggers ...Trigger) error {
|
||||
o.mu.Lock()
|
||||
defer o.mu.Unlock()
|
||||
fd, err := cg.OOMEventFD()
|
||||
@@ -71,11 +71,11 @@ func (o *OOMCollector) Add(id, namespace string, cg cgroups.Cgroup, triggers ...
|
||||
return unix.EpollCtl(o.fd, unix.EPOLL_CTL_ADD, int(fd), &event)
|
||||
}
|
||||
|
||||
func (o *OOMCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||
func (o *oomCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||
ch <- o.desc
|
||||
}
|
||||
|
||||
func (o *OOMCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
func (o *oomCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
o.mu.Lock()
|
||||
defer o.mu.Unlock()
|
||||
for _, t := range o.set {
|
||||
@@ -85,11 +85,11 @@ func (o *OOMCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
}
|
||||
|
||||
// Close closes the epoll fd
|
||||
func (o *OOMCollector) Close() error {
|
||||
func (o *oomCollector) Close() error {
|
||||
return unix.Close(int(o.fd))
|
||||
}
|
||||
|
||||
func (o *OOMCollector) start() {
|
||||
func (o *oomCollector) start() {
|
||||
var events [128]unix.EpollEvent
|
||||
for {
|
||||
n, err := unix.EpollWait(o.fd, events[:], -1)
|
||||
@@ -105,7 +105,7 @@ func (o *OOMCollector) start() {
|
||||
}
|
||||
}
|
||||
|
||||
func (o *OOMCollector) process(fd uintptr, event uint32) {
|
||||
func (o *oomCollector) process(fd uintptr, event uint32) {
|
||||
// make sure to always flush the fd
|
||||
flush(fd)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user