13224ACMer

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 demand url was wrote dead.In docker/container/clients.go, it was wrote to"unix://xxxxxxx",

In order to expand, he 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

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 user follow step:

(1) register the collector

(2) new a collector clients including some infomation (metric name , mode, help and so on)

(3) achive the collect and the descible interface.

 

分类:

docker

技术点:

相关文章:

  • 2021-05-05
  • 2021-06-04
  • 2021-06-16
  • 2022-12-23
  • 2022-03-14
  • 2021-07-25
  • 2021-12-21
猜你喜欢
  • 2021-06-06
  • 2021-06-30
  • 2021-05-17
  • 2021-11-17
  • 2022-01-28
  • 2021-06-29
相关资源
相似解决方案