Skip to content
This repository has been archived by the owner on Aug 31, 2020. It is now read-only.

Commit

Permalink
implemented option to do implicit or explicit service scanning, selec…
Browse files Browse the repository at this point in the history
…ted using Docker labels
  • Loading branch information
nustiueudinastea committed Apr 2, 2017
1 parent 9fff195 commit 86db8de
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,17 @@ func discoverSwarm(prometheusContainerID string, outputFile string, discoveryTyp

for _, task := range tasks {

if _, ok := task.Spec.ContainerSpec.Labels[excludeLabel]; ok {
logger.Debugf("Task %s ignored by Prometheus", task.ID)
continue
if discoveryType == implicit {
if _, ok := task.Spec.ContainerSpec.Labels[excludeLabel]; ok {
logger.Debugf("Task %s ignored by Prometheus", task.ID)
continue
}
} else if discoveryType == explicit {
if _, ok := task.Spec.ContainerSpec.Labels[includeLabel]; ok {
logger.Debugf("Task %s should be scanned by Prometheus", task.ID)
} else {
continue
}
}

ports := collectPorts(task, serviceIDMap)
Expand All @@ -251,6 +259,8 @@ func discoverSwarm(prometheusContainerID string, outputFile string, discoveryTyp
allNetworks[k] = v
}

// if exposed ports are found, or ports defined through labels, add them to the Prometheus target.
// if not, add only the container IP as a target, and Prometheus will use the default port (80).
for _, ip := range containerIPs {
if len(ports) > 0 {
for port := range ports {
Expand Down

0 comments on commit 86db8de

Please sign in to comment.