Skip to content

Commit

Permalink
Use cgroups proto for prom metrics
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
  • Loading branch information
crosbymichael committed Sep 5, 2017
1 parent 0973a08 commit ed45952
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 82 deletions.
12 changes: 10 additions & 2 deletions linux/task.go
Expand Up @@ -19,7 +19,7 @@ type Task struct {
pid int
shim *client.Client
namespace string
cg *cgroups.Cgroup
cg cgroups.Cgroup
}

func newTask(id, namespace string, pid int, shim *client.Client) (*Task, error) {
Expand Down Expand Up @@ -210,5 +210,13 @@ func (t *Task) Process(ctx context.Context, id string) (runtime.Process, error)
}

func (t *Task) Metrics(ctx context.Context) (interface{}, error) {
return nil, nil
stats, err := t.cg.Stat(cgroups.IgnoreNotExist)
if err != nil {
return nil, err
}
return stats, nil
}

func (t *Task) Cgroup() cgroups.Cgroup {
return t.cg
}
14 changes: 7 additions & 7 deletions metrics/cgroups/blkio.go
Expand Up @@ -15,7 +15,7 @@ var blkioMetrics = []*metric{
unit: metrics.Total,
vt: prometheus.GaugeValue,
labels: []string{"op", "device", "major", "minor"},
getValues: func(stats *cgroups.Stats) []value {
getValues: func(stats *cgroups.Metrics) []value {
if stats.Blkio == nil {
return nil
}
Expand All @@ -28,7 +28,7 @@ var blkioMetrics = []*metric{
unit: metrics.Total,
vt: prometheus.GaugeValue,
labels: []string{"op", "device", "major", "minor"},
getValues: func(stats *cgroups.Stats) []value {
getValues: func(stats *cgroups.Metrics) []value {
if stats.Blkio == nil {
return nil
}
Expand All @@ -41,7 +41,7 @@ var blkioMetrics = []*metric{
unit: metrics.Bytes,
vt: prometheus.GaugeValue,
labels: []string{"op", "device", "major", "minor"},
getValues: func(stats *cgroups.Stats) []value {
getValues: func(stats *cgroups.Metrics) []value {
if stats.Blkio == nil {
return nil
}
Expand All @@ -54,7 +54,7 @@ var blkioMetrics = []*metric{
unit: metrics.Total,
vt: prometheus.GaugeValue,
labels: []string{"op", "device", "major", "minor"},
getValues: func(stats *cgroups.Stats) []value {
getValues: func(stats *cgroups.Metrics) []value {
if stats.Blkio == nil {
return nil
}
Expand All @@ -67,7 +67,7 @@ var blkioMetrics = []*metric{
unit: metrics.Total,
vt: prometheus.GaugeValue,
labels: []string{"op", "device", "major", "minor"},
getValues: func(stats *cgroups.Stats) []value {
getValues: func(stats *cgroups.Metrics) []value {
if stats.Blkio == nil {
return nil
}
Expand All @@ -80,7 +80,7 @@ var blkioMetrics = []*metric{
unit: metrics.Total,
vt: prometheus.GaugeValue,
labels: []string{"op", "device", "major", "minor"},
getValues: func(stats *cgroups.Stats) []value {
getValues: func(stats *cgroups.Metrics) []value {
if stats.Blkio == nil {
return nil
}
Expand All @@ -93,7 +93,7 @@ var blkioMetrics = []*metric{
unit: metrics.Total,
vt: prometheus.GaugeValue,
labels: []string{"op", "device", "major", "minor"},
getValues: func(stats *cgroups.Stats) []value {
getValues: func(stats *cgroups.Metrics) []value {
if stats.Blkio == nil {
return nil
}
Expand Down
6 changes: 4 additions & 2 deletions metrics/cgroups/cgroups.go
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/containerd/cgroups"
eventsapi "github.com/containerd/containerd/api/services/events/v1"
"github.com/containerd/containerd/events"
"github.com/containerd/containerd/linux"
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/plugin"
Expand Down Expand Up @@ -49,10 +50,11 @@ type cgroupsMonitor struct {

func (m *cgroupsMonitor) Monitor(c runtime.Task) error {
info := c.Info()
if err := m.collector.Add(info.ID, info.Namespace, c); err != nil {
t := c.(*linux.Task)
if err := m.collector.Add(info.ID, info.Namespace, t.Cgroup()); err != nil {
return err
}
return m.oom.Add(info.ID, info.Namespace, cg, m.trigger)
return m.oom.Add(info.ID, info.Namespace, t.Cgroup(), m.trigger)
}

func (m *cgroupsMonitor) Stop(c runtime.Task) error {
Expand Down
14 changes: 7 additions & 7 deletions metrics/cgroups/cpu.go
Expand Up @@ -16,7 +16,7 @@ var cpuMetrics = []*metric{
help: "The total cpu time",
unit: metrics.Nanoseconds,
vt: prometheus.GaugeValue,
getValues: func(stats *cgroups.Stats) []value {
getValues: func(stats *cgroups.Metrics) []value {
if stats.Cpu == nil {
return nil
}
Expand All @@ -32,7 +32,7 @@ var cpuMetrics = []*metric{
help: "The total kernel cpu time",
unit: metrics.Nanoseconds,
vt: prometheus.GaugeValue,
getValues: func(stats *cgroups.Stats) []value {
getValues: func(stats *cgroups.Metrics) []value {
if stats.Cpu == nil {
return nil
}
Expand All @@ -48,7 +48,7 @@ var cpuMetrics = []*metric{
help: "The total user cpu time",
unit: metrics.Nanoseconds,
vt: prometheus.GaugeValue,
getValues: func(stats *cgroups.Stats) []value {
getValues: func(stats *cgroups.Metrics) []value {
if stats.Cpu == nil {
return nil
}
Expand All @@ -65,7 +65,7 @@ var cpuMetrics = []*metric{
unit: metrics.Nanoseconds,
vt: prometheus.GaugeValue,
labels: []string{"cpu"},
getValues: func(stats *cgroups.Stats) []value {
getValues: func(stats *cgroups.Metrics) []value {
if stats.Cpu == nil {
return nil
}
Expand All @@ -84,7 +84,7 @@ var cpuMetrics = []*metric{
help: "The total cpu throttle periods",
unit: metrics.Total,
vt: prometheus.GaugeValue,
getValues: func(stats *cgroups.Stats) []value {
getValues: func(stats *cgroups.Metrics) []value {
if stats.Cpu == nil {
return nil
}
Expand All @@ -100,7 +100,7 @@ var cpuMetrics = []*metric{
help: "The total cpu throttled periods",
unit: metrics.Total,
vt: prometheus.GaugeValue,
getValues: func(stats *cgroups.Stats) []value {
getValues: func(stats *cgroups.Metrics) []value {
if stats.Cpu == nil {
return nil
}
Expand All @@ -116,7 +116,7 @@ var cpuMetrics = []*metric{
help: "The total cpu throttled time",
unit: metrics.Nanoseconds,
vt: prometheus.GaugeValue,
getValues: func(stats *cgroups.Stats) []value {
getValues: func(stats *cgroups.Metrics) []value {
if stats.Cpu == nil {
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions metrics/cgroups/hugetlb.go
Expand Up @@ -15,7 +15,7 @@ var hugetlbMetrics = []*metric{
unit: metrics.Bytes,
vt: prometheus.GaugeValue,
labels: []string{"page"},
getValues: func(stats *cgroups.Stats) []value {
getValues: func(stats *cgroups.Metrics) []value {
if stats.Hugetlb == nil {
return nil
}
Expand All @@ -35,7 +35,7 @@ var hugetlbMetrics = []*metric{
unit: metrics.Total,
vt: prometheus.GaugeValue,
labels: []string{"page"},
getValues: func(stats *cgroups.Stats) []value {
getValues: func(stats *cgroups.Metrics) []value {
if stats.Hugetlb == nil {
return nil
}
Expand All @@ -55,7 +55,7 @@ var hugetlbMetrics = []*metric{
unit: metrics.Bytes,
vt: prometheus.GaugeValue,
labels: []string{"page"},
getValues: func(stats *cgroups.Stats) []value {
getValues: func(stats *cgroups.Metrics) []value {
if stats.Hugetlb == nil {
return nil
}
Expand Down

0 comments on commit ed45952

Please sign in to comment.