CAdvisor container monitor
Posted 13224acmer
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CAdvisor container monitor相关的知识,希望对你有一定的参考价值。
Now cadvisor is useful as a container montor tool. Not only it can monitor many container level metrics, but also can expand some metrics which we need.
It`s a open source project URL: https://github.com/google/cadvisor.git
its master branch has a lot of defects. One of the problem is the daemon. url was wrote dead.In docker/container/clients.go, it was wrote to"unix://xxxxxxx",
In order to expand, it should be a dynamic parameter.
eg: func clients (clients string){
******
}
run a docker container:
download the images:
go get githun.com/google/cadvisor / git clone https://github.com/google/cadvisor.git / download the zip package and unzip it
docker command
sudo docker run --volume=/:/rootfs:ro --volume=/var/run:/var/run:rw --volume=/sys:/sys:ro --volume=/var/lib/docker/:/var/lib/docker:ro --volume=/dev/disk/:/dev/disk:ro --publish=8080:8080 --detach=true --name=cadvisor google/cadvisor:latest
the default port is 8080.
the cadvisor container is running on localhost:8080. The metrics infomation is on localhost:8080/metrics The graph show on localhost:8080/graph
Every metrics colector is achived in google/cadvisor/collector/.... We can overwrite the collector and describle interface to register new collector.But if we update this change in vendor, we can not promisor the tags version.(glide up -v or glide up install)
1 // Returns a new CollectorManager that is thread-compatible. 2 func NewCollectorManager() (CollectorManager, error) { 3 return &GenericCollectorManager{ 4 Collectors: []*collectorData{}, 5 NextCollectionTime: time.Now(), 6 }, nil 7 } 8 9 func GetCollectorConfigs(labels map[string]string) map[string]string { 10 configs := map[string]string{} 11 for k, v := range labels { 12 if strings.HasPrefix(k, metricLabelPrefix) { 13 name := strings.TrimPrefix(k, metricLabelPrefix) 14 configs[name] = v 15 } 16 } 17 return configs 18 } 19 20 func (cm *GenericCollectorManager) RegisterCollector(collector Collector) error { 21 cm.Collectors = append(cm.Collectors, &collectorData{ 22 collector: collector, 23 nextCollectionTime: time.Now(), 24 }) 25 return nil 26 } 27 28 func (cm *GenericCollectorManager) GetSpec() ([]v1.MetricSpec, error) { 29 metricSpec := []v1.MetricSpec{} 30 for _, c := range cm.Collectors { 31 specs := c.collector.GetSpec() 32 metricSpec = append(metricSpec, specs...) 33 } 34 35 return metricSpec, nil 36 } 37 38 func (cm *GenericCollectorManager) Collect() (time.Time, map[string][]v1.MetricVal, error) { 39 var errors []error 40 41 // Collect from all collectors that are ready. 42 var next time.Time 43 metrics := map[string][]v1.MetricVal{} 44 for _, c := range cm.Collectors { 45 if c.nextCollectionTime.Before(time.Now()) { 46 var err error3 47 c.nextCollectionTime, metrics, err = c.collector.Collect(metrics) 48 if err != nil { 49 errors = append(errors, err) 50 } 51 } 52 53 // Keep track of the next collector that will be ready. 54 if next.IsZero() || next.After(c.nextCollectionTime) { 55 next = c.nextCollectionTime 56 } 57 } 58 cm.NextCollectionTime = next 59 return next, metrics, compileErrors(errors) 60 }
We can build a new image in the localhost by achive the interface instead of use the default package by glide up -v.
for example:
we can set up a socket client with docker daemon. and get the inspect infomation.Docker inspect info has a container restart count.
we can expand this metrics by use follow step:
(1) register the collector
(2) new a collector client including some infomation (metric name , mode, help and so on)
(3) achive the collect and the descible interface.
以上是关于CAdvisor container monitor的主要内容,如果未能解决你的问题,请参考以下文章
google/cadvisor:latest image monitor container run error
cAdvisor Prometheus container_cpu_load_average_10s 有两个值
[k8s]容器化node-expolore(9100)+cadvisor(8080)+prometheus(9090) metric搜集,grafana展示