Merge pull request #880 from jimmidyson/prom-machine-spec
Add machine memory & cpu cores to prometheus metrics
This commit is contained in:
commit
5aa8b0fc86
@ -27,8 +27,10 @@ import (
|
|||||||
type infoProvider interface {
|
type infoProvider interface {
|
||||||
// Get information about all subcontainers of the specified container (includes self).
|
// Get information about all subcontainers of the specified container (includes self).
|
||||||
SubcontainersInfo(containerName string, query *info.ContainerInfoRequest) ([]*info.ContainerInfo, error)
|
SubcontainersInfo(containerName string, query *info.ContainerInfoRequest) ([]*info.ContainerInfo, error)
|
||||||
// Get information about the machine.
|
// Get information about the version.
|
||||||
GetVersionInfo() (*info.VersionInfo, error)
|
GetVersionInfo() (*info.VersionInfo, error)
|
||||||
|
// Get information about the machine.
|
||||||
|
GetMachineInfo() (*info.MachineInfo, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// metricValue describes a single metric value for a given set of label values
|
// metricValue describes a single metric value for a given set of label values
|
||||||
@ -445,6 +447,8 @@ func NewPrometheusCollector(infoProvider infoProvider) *PrometheusCollector {
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
versionInfoDesc = prometheus.NewDesc("cadvisor_version_info", "A metric with a constant '1' value labeled by kernel version, OS version, docker version & cadvisor version.", []string{"kernelVersion", "osVersion", "dockerVersion", "cadvisorVersion"}, nil)
|
versionInfoDesc = prometheus.NewDesc("cadvisor_version_info", "A metric with a constant '1' value labeled by kernel version, OS version, docker version & cadvisor version.", []string{"kernelVersion", "osVersion", "dockerVersion", "cadvisorVersion"}, nil)
|
||||||
|
machineInfoCoresDesc = prometheus.NewDesc("machine_cpu_cores", "Number of CPU cores on the machine.", nil, nil)
|
||||||
|
machineInfoMemoryDesc = prometheus.NewDesc("machine_memory_bytes", "Amount of memory installed on the machine.", nil, nil)
|
||||||
)
|
)
|
||||||
|
|
||||||
// Describe describes all the metrics ever exported by cadvisor. It
|
// Describe describes all the metrics ever exported by cadvisor. It
|
||||||
@ -455,11 +459,14 @@ func (c *PrometheusCollector) Describe(ch chan<- *prometheus.Desc) {
|
|||||||
ch <- cm.desc([]string{})
|
ch <- cm.desc([]string{})
|
||||||
}
|
}
|
||||||
ch <- versionInfoDesc
|
ch <- versionInfoDesc
|
||||||
|
ch <- machineInfoCoresDesc
|
||||||
|
ch <- machineInfoMemoryDesc
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect fetches the stats from all containers and delivers them as
|
// Collect fetches the stats from all containers and delivers them as
|
||||||
// Prometheus metrics. It implements prometheus.PrometheusCollector.
|
// Prometheus metrics. It implements prometheus.PrometheusCollector.
|
||||||
func (c *PrometheusCollector) Collect(ch chan<- prometheus.Metric) {
|
func (c *PrometheusCollector) Collect(ch chan<- prometheus.Metric) {
|
||||||
|
c.collectMachineInfo(ch)
|
||||||
c.collectVersionInfo(ch)
|
c.collectVersionInfo(ch)
|
||||||
c.collectContainersInfo(ch)
|
c.collectContainersInfo(ch)
|
||||||
c.errors.Collect(ch)
|
c.errors.Collect(ch)
|
||||||
@ -523,6 +530,17 @@ func (c *PrometheusCollector) collectVersionInfo(ch chan<- prometheus.Metric) {
|
|||||||
ch <- prometheus.MustNewConstMetric(versionInfoDesc, prometheus.GaugeValue, 1, []string{versionInfo.KernelVersion, versionInfo.ContainerOsVersion, versionInfo.DockerVersion, versionInfo.CadvisorVersion}...)
|
ch <- prometheus.MustNewConstMetric(versionInfoDesc, prometheus.GaugeValue, 1, []string{versionInfo.KernelVersion, versionInfo.ContainerOsVersion, versionInfo.DockerVersion, versionInfo.CadvisorVersion}...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *PrometheusCollector) collectMachineInfo(ch chan<- prometheus.Metric) {
|
||||||
|
machineInfo, err := c.infoProvider.GetMachineInfo()
|
||||||
|
if err != nil {
|
||||||
|
c.errors.Set(1)
|
||||||
|
glog.Warningf("Couldn't get machine info: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ch <- prometheus.MustNewConstMetric(machineInfoCoresDesc, prometheus.GaugeValue, float64(machineInfo.NumCores))
|
||||||
|
ch <- prometheus.MustNewConstMetric(machineInfoMemoryDesc, prometheus.GaugeValue, float64(machineInfo.MemoryCapacity))
|
||||||
|
}
|
||||||
|
|
||||||
// Size after which we consider memory to be "unlimited". This is not
|
// Size after which we consider memory to be "unlimited". This is not
|
||||||
// MaxInt64 due to rounding by the kernel.
|
// MaxInt64 due to rounding by the kernel.
|
||||||
const maxMemorySize = uint64(1 << 62)
|
const maxMemorySize = uint64(1 << 62)
|
||||||
|
@ -38,6 +38,13 @@ func (p testSubcontainersInfoProvider) GetVersionInfo() (*info.VersionInfo, erro
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p testSubcontainersInfoProvider) GetMachineInfo() (*info.MachineInfo, error) {
|
||||||
|
return &info.MachineInfo{
|
||||||
|
NumCores: 4,
|
||||||
|
MemoryCapacity: 1024,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (p testSubcontainersInfoProvider) SubcontainersInfo(string, *info.ContainerInfoRequest) ([]*info.ContainerInfo, error) {
|
func (p testSubcontainersInfoProvider) SubcontainersInfo(string, *info.ContainerInfoRequest) ([]*info.ContainerInfo, error) {
|
||||||
return []*info.ContainerInfo{
|
return []*info.ContainerInfo{
|
||||||
{
|
{
|
||||||
|
6
metrics/testdata/prometheus_metrics
vendored
6
metrics/testdata/prometheus_metrics
vendored
@ -138,6 +138,12 @@ http_response_size_bytes{handler="prometheus",quantile="0.9"} 0
|
|||||||
http_response_size_bytes{handler="prometheus",quantile="0.99"} 0
|
http_response_size_bytes{handler="prometheus",quantile="0.99"} 0
|
||||||
http_response_size_bytes_sum{handler="prometheus"} 0
|
http_response_size_bytes_sum{handler="prometheus"} 0
|
||||||
http_response_size_bytes_count{handler="prometheus"} 0
|
http_response_size_bytes_count{handler="prometheus"} 0
|
||||||
|
# HELP machine_cpu_cores Number of CPU cores on the machine.
|
||||||
|
# TYPE machine_cpu_cores gauge
|
||||||
|
machine_cpu_cores 4
|
||||||
|
# HELP machine_memory_bytes Amount of memory installed on the machine.
|
||||||
|
# TYPE machine_memory_bytes gauge
|
||||||
|
machine_memory_bytes 1024
|
||||||
# HELP process_cpu_seconds_total Total user and system CPU time spent in seconds.
|
# HELP process_cpu_seconds_total Total user and system CPU time spent in seconds.
|
||||||
# TYPE process_cpu_seconds_total counter
|
# TYPE process_cpu_seconds_total counter
|
||||||
process_cpu_seconds_total 0
|
process_cpu_seconds_total 0
|
||||||
|
Loading…
Reference in New Issue
Block a user