Merge pull request #1984 from jaloren/filter_docker_prom_mets
Control whether container labels are exported as prometheus metrics.
This commit is contained in:
commit
98283308f9
@ -35,6 +35,7 @@ import (
|
||||
"crypto/tls"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/google/cadvisor/metrics"
|
||||
)
|
||||
|
||||
var argIp = flag.String("listen_ip", "", "IP to listen on, defaults to all IPs")
|
||||
@ -58,6 +59,8 @@ var enableProfiling = flag.Bool("profiling", false, "Enable profiling via web in
|
||||
var collectorCert = flag.String("collector_cert", "", "Collector's certificate, exposed to endpoints for certificate based authentication.")
|
||||
var collectorKey = flag.String("collector_key", "", "Key for the collector's certificate")
|
||||
|
||||
var storeContainerLabels = flag.Bool("store_container_labels", true, "convert container labels and environment variables into labels on prometheus metrics for each container. If flag set to false, then only metrics exported are container name, first alias, and image name")
|
||||
|
||||
var (
|
||||
// Metrics to be ignored.
|
||||
// Tcp metrics are ignored by default.
|
||||
@ -152,7 +155,11 @@ func main() {
|
||||
glog.Fatalf("Failed to register HTTP handlers: %v", err)
|
||||
}
|
||||
|
||||
cadvisorhttp.RegisterPrometheusHandler(mux, containerManager, *prometheusEndpoint, nil)
|
||||
containerLabelFunc := metrics.DefaultContainerLabels
|
||||
if !*storeContainerLabels {
|
||||
containerLabelFunc = metrics.BaseContainerLabels
|
||||
}
|
||||
cadvisorhttp.RegisterPrometheusHandler(mux, containerManager, *prometheusEndpoint, containerLabelFunc)
|
||||
|
||||
// Start the manager.
|
||||
if err := containerManager.Start(); err != nil {
|
||||
|
@ -842,6 +842,19 @@ 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]
|
||||
}
|
||||
if image := container.Spec.Image; len(image) > 0 {
|
||||
set[LabelImage] = image
|
||||
}
|
||||
return set
|
||||
}
|
||||
|
||||
func (c *PrometheusCollector) collectContainersInfo(ch chan<- prometheus.Metric) {
|
||||
containers, err := c.infoProvider.SubcontainersInfo("/", &info.ContainerInfoRequest{NumStats: 1})
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user