update cadvisor godeps to v0.33.0

This commit is contained in:
David Ashpole
2019-02-27 11:02:48 -08:00
parent 4fa5ece62c
commit 4e063fe007
25 changed files with 734 additions and 371 deletions

View File

@@ -21,7 +21,6 @@ import (
"github.com/google/cadvisor/container"
info "github.com/google/cadvisor/info/v1"
"github.com/prometheus/client_golang/prometheus"
"k8s.io/klog"
)
@@ -40,8 +39,9 @@ type infoProvider interface {
// metricValue describes a single metric value for a given set of label values
// within a parent containerMetric.
type metricValue struct {
value float64
labels []string
value float64
labels []string
timestamp time.Time
}
type metricValues []metricValue
@@ -55,30 +55,35 @@ func asNanosecondsToSeconds(v uint64) float64 {
}
// fsValues is a helper method for assembling per-filesystem stats.
func fsValues(fsStats []info.FsStats, valueFn func(*info.FsStats) float64) metricValues {
func fsValues(fsStats []info.FsStats, valueFn func(*info.FsStats) float64, timestamp time.Time) metricValues {
values := make(metricValues, 0, len(fsStats))
for _, stat := range fsStats {
values = append(values, metricValue{
value: valueFn(&stat),
labels: []string{stat.Device},
value: valueFn(&stat),
labels: []string{stat.Device},
timestamp: timestamp,
})
}
return values
}
// ioValues is a helper method for assembling per-disk and per-filesystem stats.
func ioValues(ioStats []info.PerDiskStats, ioType string, ioValueFn func(uint64) float64, fsStats []info.FsStats, valueFn func(*info.FsStats) float64) metricValues {
func ioValues(ioStats []info.PerDiskStats, ioType string, ioValueFn func(uint64) float64,
fsStats []info.FsStats, valueFn func(*info.FsStats) float64, timestamp time.Time) metricValues {
values := make(metricValues, 0, len(ioStats)+len(fsStats))
for _, stat := range ioStats {
values = append(values, metricValue{
value: ioValueFn(stat.Stats[ioType]),
labels: []string{stat.Device},
value: ioValueFn(stat.Stats[ioType]),
labels: []string{stat.Device},
timestamp: timestamp,
})
}
for _, stat := range fsStats {
values = append(values, metricValue{
value: valueFn(&stat),
labels: []string{stat.Device},
value: valueFn(&stat),
labels: []string{stat.Device},
timestamp: timestamp,
})
}
return values
@@ -134,7 +139,10 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
help: "Last time a container was seen by the exporter",
valueType: prometheus.GaugeValue,
getValues: func(s *info.ContainerStats) metricValues {
return metricValues{{value: float64(time.Now().Unix())}}
return metricValues{{
value: float64(time.Now().Unix()),
timestamp: time.Now(),
}}
},
},
},
@@ -147,14 +155,24 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
help: "Cumulative user cpu time consumed in seconds.",
valueType: prometheus.CounterValue,
getValues: func(s *info.ContainerStats) metricValues {
return metricValues{{value: float64(s.Cpu.Usage.User) / float64(time.Second)}}
return metricValues{
{
value: float64(s.Cpu.Usage.User) / float64(time.Second),
timestamp: s.Timestamp,
},
}
},
}, {
name: "container_cpu_system_seconds_total",
help: "Cumulative system cpu time consumed in seconds.",
valueType: prometheus.CounterValue,
getValues: func(s *info.ContainerStats) metricValues {
return metricValues{{value: float64(s.Cpu.Usage.System) / float64(time.Second)}}
return metricValues{
{
value: float64(s.Cpu.Usage.System) / float64(time.Second),
timestamp: s.Timestamp,
},
}
},
}, {
name: "container_cpu_usage_seconds_total",
@@ -165,8 +183,9 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
if len(s.Cpu.Usage.PerCpu) == 0 {
if s.Cpu.Usage.Total > 0 {
return metricValues{{
value: float64(s.Cpu.Usage.Total) / float64(time.Second),
labels: []string{"total"},
value: float64(s.Cpu.Usage.Total) / float64(time.Second),
labels: []string{"total"},
timestamp: s.Timestamp,
}}
}
}
@@ -174,8 +193,9 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
for i, value := range s.Cpu.Usage.PerCpu {
if value > 0 {
values = append(values, metricValue{
value: float64(value) / float64(time.Second),
labels: []string{fmt.Sprintf("cpu%02d", i)},
value: float64(value) / float64(time.Second),
labels: []string{fmt.Sprintf("cpu%02d", i)},
timestamp: s.Timestamp,
})
}
}
@@ -187,7 +207,11 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
valueType: prometheus.CounterValue,
condition: func(s info.ContainerSpec) bool { return s.Cpu.Quota != 0 },
getValues: func(s *info.ContainerStats) metricValues {
return metricValues{{value: float64(s.Cpu.CFS.Periods)}}
return metricValues{
{
value: float64(s.Cpu.CFS.Periods),
timestamp: s.Timestamp,
}}
},
}, {
name: "container_cpu_cfs_throttled_periods_total",
@@ -195,7 +219,11 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
valueType: prometheus.CounterValue,
condition: func(s info.ContainerSpec) bool { return s.Cpu.Quota != 0 },
getValues: func(s *info.ContainerStats) metricValues {
return metricValues{{value: float64(s.Cpu.CFS.ThrottledPeriods)}}
return metricValues{
{
value: float64(s.Cpu.CFS.ThrottledPeriods),
timestamp: s.Timestamp,
}}
},
}, {
name: "container_cpu_cfs_throttled_seconds_total",
@@ -203,7 +231,11 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
valueType: prometheus.CounterValue,
condition: func(s info.ContainerSpec) bool { return s.Cpu.Quota != 0 },
getValues: func(s *info.ContainerStats) metricValues {
return metricValues{{value: float64(s.Cpu.CFS.ThrottledTime) / float64(time.Second)}}
return metricValues{
{
value: float64(s.Cpu.CFS.ThrottledTime) / float64(time.Second),
timestamp: s.Timestamp,
}}
},
},
}...)
@@ -215,21 +247,30 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
help: "Time duration the processes of the container have run on the CPU.",
valueType: prometheus.CounterValue,
getValues: func(s *info.ContainerStats) metricValues {
return metricValues{{value: float64(s.Cpu.Schedstat.RunTime) / float64(time.Second)}}
return metricValues{{
value: float64(s.Cpu.Schedstat.RunTime) / float64(time.Second),
timestamp: s.Timestamp,
}}
},
}, {
name: "container_cpu_schedstat_runqueue_seconds_total",
help: "Time duration processes of the container have been waiting on a runqueue.",
valueType: prometheus.CounterValue,
getValues: func(s *info.ContainerStats) metricValues {
return metricValues{{value: float64(s.Cpu.Schedstat.RunqueueTime) / float64(time.Second)}}
return metricValues{{
value: float64(s.Cpu.Schedstat.RunqueueTime) / float64(time.Second),
timestamp: s.Timestamp,
}}
},
}, {
name: "container_cpu_schedstat_run_periods_total",
help: "Number of times processes of the cgroup have run on the cpu",
valueType: prometheus.CounterValue,
getValues: func(s *info.ContainerStats) metricValues {
return metricValues{{value: float64(s.Cpu.Schedstat.RunPeriods)}}
return metricValues{{
value: float64(s.Cpu.Schedstat.RunPeriods),
timestamp: s.Timestamp,
}}
},
},
}...)
@@ -241,7 +282,7 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
help: "Value of container cpu load average over the last 10 seconds.",
valueType: prometheus.GaugeValue,
getValues: func(s *info.ContainerStats) metricValues {
return metricValues{{value: float64(s.Cpu.LoadAverage)}}
return metricValues{{value: float64(s.Cpu.LoadAverage), timestamp: s.Timestamp}}
},
}, {
name: "container_tasks_state",
@@ -251,24 +292,29 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
getValues: func(s *info.ContainerStats) metricValues {
return metricValues{
{
value: float64(s.TaskStats.NrSleeping),
labels: []string{"sleeping"},
value: float64(s.TaskStats.NrSleeping),
labels: []string{"sleeping"},
timestamp: s.Timestamp,
},
{
value: float64(s.TaskStats.NrRunning),
labels: []string{"running"},
value: float64(s.TaskStats.NrRunning),
labels: []string{"running"},
timestamp: s.Timestamp,
},
{
value: float64(s.TaskStats.NrStopped),
labels: []string{"stopped"},
value: float64(s.TaskStats.NrStopped),
labels: []string{"stopped"},
timestamp: s.Timestamp,
},
{
value: float64(s.TaskStats.NrUninterruptible),
labels: []string{"uninterruptible"},
value: float64(s.TaskStats.NrUninterruptible),
labels: []string{"uninterruptible"},
timestamp: s.Timestamp,
},
{
value: float64(s.TaskStats.NrIoWait),
labels: []string{"iowaiting"},
value: float64(s.TaskStats.NrIoWait),
labels: []string{"iowaiting"},
timestamp: s.Timestamp,
},
}
},
@@ -282,42 +328,45 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
help: "Number of bytes of page cache memory.",
valueType: prometheus.GaugeValue,
getValues: func(s *info.ContainerStats) metricValues {
return metricValues{{value: float64(s.Memory.Cache)}}
return metricValues{{value: float64(s.Memory.Cache), timestamp: s.Timestamp}}
},
}, {
name: "container_memory_rss",
help: "Size of RSS in bytes.",
valueType: prometheus.GaugeValue,
getValues: func(s *info.ContainerStats) metricValues {
return metricValues{{value: float64(s.Memory.RSS)}}
return metricValues{{value: float64(s.Memory.RSS), timestamp: s.Timestamp}}
},
}, {
name: "container_memory_mapped_file",
help: "Size of memory mapped files in bytes.",
valueType: prometheus.GaugeValue,
getValues: func(s *info.ContainerStats) metricValues {
return metricValues{{value: float64(s.Memory.MappedFile)}}
return metricValues{{value: float64(s.Memory.MappedFile), timestamp: s.Timestamp}}
},
}, {
name: "container_memory_swap",
help: "Container swap usage in bytes.",
valueType: prometheus.GaugeValue,
getValues: func(s *info.ContainerStats) metricValues {
return metricValues{{value: float64(s.Memory.Swap)}}
return metricValues{{value: float64(s.Memory.Swap), timestamp: s.Timestamp}}
},
}, {
name: "container_memory_failcnt",
help: "Number of memory usage hits limits",
valueType: prometheus.CounterValue,
getValues: func(s *info.ContainerStats) metricValues {
return metricValues{{value: float64(s.Memory.Failcnt)}}
return metricValues{{
value: float64(s.Memory.Failcnt),
timestamp: s.Timestamp,
}}
},
}, {
name: "container_memory_usage_bytes",
help: "Current memory usage in bytes, including all memory regardless of when it was accessed",
valueType: prometheus.GaugeValue,
getValues: func(s *info.ContainerStats) metricValues {
return metricValues{{value: float64(s.Memory.Usage)}}
return metricValues{{value: float64(s.Memory.Usage), timestamp: s.Timestamp}}
},
},
{
@@ -325,14 +374,14 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
help: "Maximum memory usage recorded in bytes",
valueType: prometheus.GaugeValue,
getValues: func(s *info.ContainerStats) metricValues {
return metricValues{{value: float64(s.Memory.MaxUsage)}}
return metricValues{{value: float64(s.Memory.MaxUsage), timestamp: s.Timestamp}}
},
}, {
name: "container_memory_working_set_bytes",
help: "Current working set in bytes.",
valueType: prometheus.GaugeValue,
getValues: func(s *info.ContainerStats) metricValues {
return metricValues{{value: float64(s.Memory.WorkingSet)}}
return metricValues{{value: float64(s.Memory.WorkingSet), timestamp: s.Timestamp}}
},
}, {
name: "container_memory_failures_total",
@@ -342,20 +391,24 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
getValues: func(s *info.ContainerStats) metricValues {
return metricValues{
{
value: float64(s.Memory.ContainerData.Pgfault),
labels: []string{"pgfault", "container"},
value: float64(s.Memory.ContainerData.Pgfault),
labels: []string{"pgfault", "container"},
timestamp: s.Timestamp,
},
{
value: float64(s.Memory.ContainerData.Pgmajfault),
labels: []string{"pgmajfault", "container"},
value: float64(s.Memory.ContainerData.Pgmajfault),
labels: []string{"pgmajfault", "container"},
timestamp: s.Timestamp,
},
{
value: float64(s.Memory.HierarchicalData.Pgfault),
labels: []string{"pgfault", "hierarchy"},
value: float64(s.Memory.HierarchicalData.Pgfault),
labels: []string{"pgfault", "hierarchy"},
timestamp: s.Timestamp,
},
{
value: float64(s.Memory.HierarchicalData.Pgmajfault),
labels: []string{"pgmajfault", "hierarchy"},
value: float64(s.Memory.HierarchicalData.Pgmajfault),
labels: []string{"pgmajfault", "hierarchy"},
timestamp: s.Timestamp,
},
}
},
@@ -373,8 +426,9 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
values := make(metricValues, 0, len(s.Accelerators))
for _, value := range s.Accelerators {
values = append(values, metricValue{
value: float64(value.MemoryTotal),
labels: []string{value.Make, value.Model, value.ID},
value: float64(value.MemoryTotal),
labels: []string{value.Make, value.Model, value.ID},
timestamp: s.Timestamp,
})
}
return values
@@ -388,8 +442,9 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
values := make(metricValues, 0, len(s.Accelerators))
for _, value := range s.Accelerators {
values = append(values, metricValue{
value: float64(value.MemoryUsed),
labels: []string{value.Make, value.Model, value.ID},
value: float64(value.MemoryUsed),
labels: []string{value.Make, value.Model, value.ID},
timestamp: s.Timestamp,
})
}
return values
@@ -403,8 +458,9 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
values := make(metricValues, 0, len(s.Accelerators))
for _, value := range s.Accelerators {
values = append(values, metricValue{
value: float64(value.DutyCycle),
labels: []string{value.Make, value.Model, value.ID},
value: float64(value.DutyCycle),
labels: []string{value.Make, value.Model, value.ID},
timestamp: s.Timestamp,
})
}
return values
@@ -422,7 +478,7 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
getValues: func(s *info.ContainerStats) metricValues {
return fsValues(s.Filesystem, func(fs *info.FsStats) float64 {
return float64(fs.InodesFree)
})
}, s.Timestamp)
},
}, {
name: "container_fs_inodes_total",
@@ -432,7 +488,7 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
getValues: func(s *info.ContainerStats) metricValues {
return fsValues(s.Filesystem, func(fs *info.FsStats) float64 {
return float64(fs.Inodes)
})
}, s.Timestamp)
},
}, {
name: "container_fs_limit_bytes",
@@ -442,7 +498,7 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
getValues: func(s *info.ContainerStats) metricValues {
return fsValues(s.Filesystem, func(fs *info.FsStats) float64 {
return float64(fs.Limit)
})
}, s.Timestamp)
},
}, {
name: "container_fs_usage_bytes",
@@ -452,7 +508,7 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
getValues: func(s *info.ContainerStats) metricValues {
return fsValues(s.Filesystem, func(fs *info.FsStats) float64 {
return float64(fs.Usage)
})
}, s.Timestamp)
},
},
}...)
@@ -468,6 +524,7 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
return ioValues(
s.DiskIo.IoServiceBytes, "Read", asFloat64,
nil, nil,
s.Timestamp,
)
},
}, {
@@ -481,6 +538,7 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
s.Filesystem, func(fs *info.FsStats) float64 {
return float64(fs.ReadsCompleted)
},
s.Timestamp,
)
},
}, {
@@ -494,6 +552,7 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
s.Filesystem, func(fs *info.FsStats) float64 {
return float64(fs.SectorsRead)
},
s.Timestamp,
)
},
}, {
@@ -507,6 +566,7 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
s.Filesystem, func(fs *info.FsStats) float64 {
return float64(fs.ReadsMerged)
},
s.Timestamp,
)
},
}, {
@@ -520,6 +580,7 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
s.Filesystem, func(fs *info.FsStats) float64 {
return float64(fs.ReadTime) / float64(time.Second)
},
s.Timestamp,
)
},
}, {
@@ -531,6 +592,7 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
return ioValues(
s.DiskIo.IoServiceBytes, "Write", asFloat64,
nil, nil,
s.Timestamp,
)
},
}, {
@@ -544,6 +606,7 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
s.Filesystem, func(fs *info.FsStats) float64 {
return float64(fs.WritesCompleted)
},
s.Timestamp,
)
},
}, {
@@ -557,6 +620,7 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
s.Filesystem, func(fs *info.FsStats) float64 {
return float64(fs.SectorsWritten)
},
s.Timestamp,
)
},
}, {
@@ -570,6 +634,7 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
s.Filesystem, func(fs *info.FsStats) float64 {
return float64(fs.WritesMerged)
},
s.Timestamp,
)
},
}, {
@@ -583,6 +648,7 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
s.Filesystem, func(fs *info.FsStats) float64 {
return float64(fs.WriteTime) / float64(time.Second)
},
s.Timestamp,
)
},
}, {
@@ -596,6 +662,7 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
s.Filesystem, func(fs *info.FsStats) float64 {
return float64(fs.IoInProgress)
},
s.Timestamp,
)
},
}, {
@@ -609,6 +676,7 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
s.Filesystem, func(fs *info.FsStats) float64 {
return float64(float64(fs.IoTime) / float64(time.Second))
},
s.Timestamp,
)
},
}, {
@@ -619,7 +687,7 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
getValues: func(s *info.ContainerStats) metricValues {
return fsValues(s.Filesystem, func(fs *info.FsStats) float64 {
return float64(fs.WeightedIoTime) / float64(time.Second)
})
}, s.Timestamp)
},
},
}...)
@@ -635,8 +703,9 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
values := make(metricValues, 0, len(s.Network.Interfaces))
for _, value := range s.Network.Interfaces {
values = append(values, metricValue{
value: float64(value.RxBytes),
labels: []string{value.Name},
value: float64(value.RxBytes),
labels: []string{value.Name},
timestamp: s.Timestamp,
})
}
return values
@@ -650,8 +719,9 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
values := make(metricValues, 0, len(s.Network.Interfaces))
for _, value := range s.Network.Interfaces {
values = append(values, metricValue{
value: float64(value.RxPackets),
labels: []string{value.Name},
value: float64(value.RxPackets),
labels: []string{value.Name},
timestamp: s.Timestamp,
})
}
return values
@@ -665,8 +735,9 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
values := make(metricValues, 0, len(s.Network.Interfaces))
for _, value := range s.Network.Interfaces {
values = append(values, metricValue{
value: float64(value.RxDropped),
labels: []string{value.Name},
value: float64(value.RxDropped),
labels: []string{value.Name},
timestamp: s.Timestamp,
})
}
return values
@@ -680,8 +751,9 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
values := make(metricValues, 0, len(s.Network.Interfaces))
for _, value := range s.Network.Interfaces {
values = append(values, metricValue{
value: float64(value.RxErrors),
labels: []string{value.Name},
value: float64(value.RxErrors),
labels: []string{value.Name},
timestamp: s.Timestamp,
})
}
return values
@@ -695,8 +767,9 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
values := make(metricValues, 0, len(s.Network.Interfaces))
for _, value := range s.Network.Interfaces {
values = append(values, metricValue{
value: float64(value.TxBytes),
labels: []string{value.Name},
value: float64(value.TxBytes),
labels: []string{value.Name},
timestamp: s.Timestamp,
})
}
return values
@@ -710,8 +783,9 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
values := make(metricValues, 0, len(s.Network.Interfaces))
for _, value := range s.Network.Interfaces {
values = append(values, metricValue{
value: float64(value.TxPackets),
labels: []string{value.Name},
value: float64(value.TxPackets),
labels: []string{value.Name},
timestamp: s.Timestamp,
})
}
return values
@@ -725,8 +799,9 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
values := make(metricValues, 0, len(s.Network.Interfaces))
for _, value := range s.Network.Interfaces {
values = append(values, metricValue{
value: float64(value.TxDropped),
labels: []string{value.Name},
value: float64(value.TxDropped),
labels: []string{value.Name},
timestamp: s.Timestamp,
})
}
return values
@@ -740,8 +815,9 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
values := make(metricValues, 0, len(s.Network.Interfaces))
for _, value := range s.Network.Interfaces {
values = append(values, metricValue{
value: float64(value.TxErrors),
labels: []string{value.Name},
value: float64(value.TxErrors),
labels: []string{value.Name},
timestamp: s.Timestamp,
})
}
return values
@@ -759,48 +835,126 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
getValues: func(s *info.ContainerStats) metricValues {
return metricValues{
{
value: float64(s.Network.Tcp.Established),
labels: []string{"established"},
value: float64(s.Network.Tcp.Established),
labels: []string{"established"},
timestamp: s.Timestamp,
},
{
value: float64(s.Network.Tcp.SynSent),
labels: []string{"synsent"},
value: float64(s.Network.Tcp.SynSent),
labels: []string{"synsent"},
timestamp: s.Timestamp,
},
{
value: float64(s.Network.Tcp.SynRecv),
labels: []string{"synrecv"},
value: float64(s.Network.Tcp.SynRecv),
labels: []string{"synrecv"},
timestamp: s.Timestamp,
},
{
value: float64(s.Network.Tcp.FinWait1),
labels: []string{"finwait1"},
value: float64(s.Network.Tcp.FinWait1),
labels: []string{"finwait1"},
timestamp: s.Timestamp,
},
{
value: float64(s.Network.Tcp.FinWait2),
labels: []string{"finwait2"},
value: float64(s.Network.Tcp.FinWait2),
labels: []string{"finwait2"},
timestamp: s.Timestamp,
},
{
value: float64(s.Network.Tcp.TimeWait),
labels: []string{"timewait"},
value: float64(s.Network.Tcp.TimeWait),
labels: []string{"timewait"},
timestamp: s.Timestamp,
},
{
value: float64(s.Network.Tcp.Close),
labels: []string{"close"},
value: float64(s.Network.Tcp.Close),
labels: []string{"close"},
timestamp: s.Timestamp,
},
{
value: float64(s.Network.Tcp.CloseWait),
labels: []string{"closewait"},
value: float64(s.Network.Tcp.CloseWait),
labels: []string{"closewait"},
timestamp: s.Timestamp,
},
{
value: float64(s.Network.Tcp.LastAck),
labels: []string{"lastack"},
value: float64(s.Network.Tcp.LastAck),
labels: []string{"lastack"},
timestamp: s.Timestamp,
},
{
value: float64(s.Network.Tcp.Listen),
labels: []string{"listen"},
value: float64(s.Network.Tcp.Listen),
labels: []string{"listen"},
timestamp: s.Timestamp,
},
{
value: float64(s.Network.Tcp.Closing),
labels: []string{"closing"},
value: float64(s.Network.Tcp.Closing),
labels: []string{"closing"},
timestamp: s.Timestamp,
},
}
},
},
}...)
c.containerMetrics = append(c.containerMetrics, []containerMetric{
{
name: "container_network_tcp6_usage_total",
help: "tcp6 connection usage statistic for container",
valueType: prometheus.GaugeValue,
extraLabels: []string{"tcp_state"},
getValues: func(s *info.ContainerStats) metricValues {
return metricValues{
{
value: float64(s.Network.Tcp6.Established),
labels: []string{"established"},
timestamp: s.Timestamp,
},
{
value: float64(s.Network.Tcp6.SynSent),
labels: []string{"synsent"},
timestamp: s.Timestamp,
},
{
value: float64(s.Network.Tcp6.SynRecv),
labels: []string{"synrecv"},
timestamp: s.Timestamp,
},
{
value: float64(s.Network.Tcp6.FinWait1),
labels: []string{"finwait1"},
timestamp: s.Timestamp,
},
{
value: float64(s.Network.Tcp6.FinWait2),
labels: []string{"finwait2"},
timestamp: s.Timestamp,
},
{
value: float64(s.Network.Tcp6.TimeWait),
labels: []string{"timewait"},
timestamp: s.Timestamp,
},
{
value: float64(s.Network.Tcp6.Close),
labels: []string{"close"},
timestamp: s.Timestamp,
},
{
value: float64(s.Network.Tcp6.CloseWait),
labels: []string{"closewait"},
timestamp: s.Timestamp,
},
{
value: float64(s.Network.Tcp6.LastAck),
labels: []string{"lastack"},
timestamp: s.Timestamp,
},
{
value: float64(s.Network.Tcp6.Listen),
labels: []string{"listen"},
timestamp: s.Timestamp,
},
{
value: float64(s.Network.Tcp6.Closing),
labels: []string{"closing"},
timestamp: s.Timestamp,
},
}
},
@@ -808,6 +962,38 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
}...)
}
if includedMetrics.Has(container.NetworkUdpUsageMetrics) {
c.containerMetrics = append(c.containerMetrics, []containerMetric{
{
name: "container_network_udp6_usage_total",
help: "udp6 connection usage statistic for container",
valueType: prometheus.GaugeValue,
extraLabels: []string{"udp_state"},
getValues: func(s *info.ContainerStats) metricValues {
return metricValues{
{
value: float64(s.Network.Udp6.Listen),
labels: []string{"listen"},
timestamp: s.Timestamp,
},
{
value: float64(s.Network.Udp6.Dropped),
labels: []string{"dropped"},
timestamp: s.Timestamp,
},
{
value: float64(s.Network.Udp6.RxQueued),
labels: []string{"rxqueued"},
timestamp: s.Timestamp,
},
{
value: float64(s.Network.Udp6.TxQueued),
labels: []string{"txqueued"},
timestamp: s.Timestamp,
},
}
},
},
}...)
c.containerMetrics = append(c.containerMetrics, []containerMetric{
{
name: "container_network_udp_usage_total",
@@ -817,20 +1003,24 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
getValues: func(s *info.ContainerStats) metricValues {
return metricValues{
{
value: float64(s.Network.Udp.Listen),
labels: []string{"listen"},
value: float64(s.Network.Udp.Listen),
labels: []string{"listen"},
timestamp: s.Timestamp,
},
{
value: float64(s.Network.Udp.Dropped),
labels: []string{"dropped"},
value: float64(s.Network.Udp.Dropped),
labels: []string{"dropped"},
timestamp: s.Timestamp,
},
{
value: float64(s.Network.Udp.RxQueued),
labels: []string{"rxqueued"},
value: float64(s.Network.Udp.RxQueued),
labels: []string{"rxqueued"},
timestamp: s.Timestamp,
},
{
value: float64(s.Network.Udp.TxQueued),
labels: []string{"txqueued"},
value: float64(s.Network.Udp.TxQueued),
labels: []string{"txqueued"},
timestamp: s.Timestamp,
},
}
},
@@ -844,7 +1034,7 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
help: "Number of processes running inside the container.",
valueType: prometheus.GaugeValue,
getValues: func(s *info.ContainerStats) metricValues {
return metricValues{{value: float64(s.Processes.ProcessCount)}}
return metricValues{{value: float64(s.Processes.ProcessCount), timestamp: s.Timestamp}}
},
},
{
@@ -852,7 +1042,7 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
help: "Number of open file descriptors for the container.",
valueType: prometheus.GaugeValue,
getValues: func(s *info.ContainerStats) metricValues {
return metricValues{{value: float64(s.Processes.FdCount)}}
return metricValues{{value: float64(s.Processes.FdCount), timestamp: s.Timestamp}}
},
},
}...)
@@ -922,17 +1112,29 @@ func DefaultContainerLabels(container *info.ContainerInfo) map[string]string {
return set
}
// BaseContainerLabels implements ContainerLabelsFunc. It only exports the
// container name, first alias, and image name.
func BaseContainerLabels(container *info.ContainerInfo) map[string]string {
set := map[string]string{LabelID: container.Name}
if len(container.Aliases) > 0 {
set[LabelName] = container.Aliases[0]
// BaseContainerLabels returns a ContainerLabelsFunc that exports the container
// name, first alias, image name as well as white listed label values.
func BaseContainerLabels(whiteList []string) func(container *info.ContainerInfo) map[string]string {
whiteListMap := make(map[string]struct{}, len(whiteList))
for _, k := range whiteList {
whiteListMap[k] = struct{}{}
}
if image := container.Spec.Image; len(image) > 0 {
set[LabelImage] = image
return func(container *info.ContainerInfo) map[string]string {
set := map[string]string{LabelID: container.Name}
if len(container.Aliases) > 0 {
set[LabelName] = container.Aliases[0]
}
if image := container.Spec.Image; len(image) > 0 {
set[LabelImage] = image
}
for k, v := range container.Spec.Labels {
if _, ok := whiteListMap[k]; ok {
set[ContainerLabelPrefix+k] = v
}
}
return set
}
return set
}
func (c *PrometheusCollector) collectContainersInfo(ch chan<- prometheus.Metric) {
@@ -993,7 +1195,10 @@ func (c *PrometheusCollector) collectContainersInfo(ch chan<- prometheus.Metric)
}
desc := cm.desc(labels)
for _, metricValue := range cm.getValues(stats) {
ch <- prometheus.MustNewConstMetric(desc, cm.valueType, float64(metricValue.value), append(values, metricValue.labels...)...)
ch <- prometheus.NewMetricWithTimestamp(
metricValue.timestamp,
prometheus.MustNewConstMetric(desc, cm.valueType, float64(metricValue.value), append(values, metricValue.labels...)...),
)
}
}
}