@@ -296,6 +296,7 @@ func main() {
296
296
noEvalMetricsEnabled = flag .Bool ("no-eval-metrics" , false , "disable eval metrics collection" )
297
297
noDeploymentMetricsEnabled = flag .Bool ("no-deployment-metrics" , false , "disable deployment metrics collection" )
298
298
noAllocationStatsMetricsEnabled = flag .Bool ("no-allocation-stats-metrics" , false , "disable stats metrics collection" )
299
+ concurrency = flag .Int ("concurrency" , 20 , "max number of goroutines to launch concurrently when poking the API" )
299
300
)
300
301
flag .Parse ()
301
302
@@ -342,6 +343,7 @@ func main() {
342
343
EvalMetricsEnabled : ! * noEvalMetricsEnabled ,
343
344
DeploymentMetricsEnabled : ! * noDeploymentMetricsEnabled ,
344
345
AllocationStatsMetricsEnabled : ! * noAllocationStatsMetricsEnabled ,
346
+ Concurrency : * concurrency ,
345
347
}
346
348
347
349
logrus .Debugf ("Created exporter %#v" , * exporter )
@@ -385,6 +387,7 @@ type Exporter struct {
385
387
EvalMetricsEnabled bool
386
388
DeploymentMetricsEnabled bool
387
389
AllocationStatsMetricsEnabled bool
390
+ Concurrency int
388
391
}
389
392
390
393
func (e * Exporter ) shouldReadMetrics () bool {
@@ -560,47 +563,47 @@ func (e *Exporter) collectNodes(ch chan<- prometheus.Metric) error {
560
563
logrus .Debugf ("I've the nodes list with %d nodes" , len (nodes ))
561
564
562
565
var w sync.WaitGroup
563
- pool := make (chan func (), 10 ) // Only run 10 at a time
566
+ pool := make (chan func (), e . Concurrency )
564
567
go func () {
565
- f := <- pool
566
- f ()
568
+ for f := range pool {
569
+ go f ()
570
+ }
567
571
}()
568
572
569
573
for _ , node := range nodes {
570
- state := 1
571
- drain := strconv .FormatBool (node .Drain )
572
-
573
- ch <- prometheus .MustNewConstMetric (
574
- nodeInfo , prometheus .GaugeValue , 1 ,
575
- node .Name , node .Version , node .NodeClass , node .Status ,
576
- drain , node .Datacenter , node .SchedulingEligibility ,
577
- )
574
+ w .Add (1 )
575
+ pool <- func (node api.NodeListStub ) func () {
576
+ return func () {
577
+ defer w .Done ()
578
+ state := 1
579
+ drain := strconv .FormatBool (node .Drain )
578
580
579
- if node .Status == "down" {
580
- state = 0
581
- }
582
- ch <- prometheus .MustNewConstMetric (
583
- serfLanMembersStatus , prometheus .GaugeValue , float64 (state ),
584
- node .Datacenter , node .NodeClass , node .Name , drain ,
585
- )
581
+ ch <- prometheus .MustNewConstMetric (
582
+ nodeInfo , prometheus .GaugeValue , 1 ,
583
+ node .Name , node .Version , node .NodeClass , node .Status ,
584
+ drain , node .Datacenter , node .SchedulingEligibility ,
585
+ )
586
586
587
- if ! validVersion (node .Name , node .Version ) {
588
- continue
589
- }
587
+ if node .Status == "down" {
588
+ state = 0
589
+ }
590
+ ch <- prometheus .MustNewConstMetric (
591
+ serfLanMembersStatus , prometheus .GaugeValue , float64 (state ),
592
+ node .Datacenter , node .NodeClass , node .Name , drain ,
593
+ )
590
594
591
- if ! e . AllocationStatsMetricsEnabled {
592
- continue
593
- }
595
+ if ! validVersion ( node . Name , node . Version ) {
596
+ return
597
+ }
594
598
595
- w .Add (1 )
596
- pool <- func (a api.NodeListStub ) func () {
597
- return func () {
598
- defer w .Done ()
599
+ if ! e .AllocationStatsMetricsEnabled {
600
+ return
601
+ }
599
602
600
- logrus .Debugf ("Fetching node %#v" , a )
601
- node , _ , err := e .client .Nodes ().Info (a .ID , opts )
603
+ logrus .Debugf ("Fetching node %#v" , node )
604
+ node , _ , err := e .client .Nodes ().Info (node .ID , opts )
602
605
if err != nil {
603
- logError (fmt .Errorf ("failed to get node %s info: %s" , a .Name , err ))
606
+ logError (fmt .Errorf ("failed to get node %s info: %s" , node .Name , err ))
604
607
return
605
608
}
606
609
@@ -648,7 +651,7 @@ func (e *Exporter) collectNodes(ch chan<- prometheus.Metric) error {
648
651
nodeLabels ... ,
649
652
)
650
653
651
- nodeStats , err := e .client .Nodes ().Stats (a .ID , opts )
654
+ nodeStats , err := e .client .Nodes ().Stats (node .ID , opts )
652
655
if err != nil {
653
656
logError (fmt .Errorf ("failed to get node %s stats: %s" , node .Name , err ))
654
657
return
@@ -723,7 +726,7 @@ func (e *Exporter) collectAllocations(ch chan<- prometheus.Metric) error {
723
726
for _ , allocStub := range allocStubs {
724
727
w .Add (1 )
725
728
726
- go func (allocStub * api.AllocationListStub ) {
729
+ go func (allocStub api.AllocationListStub ) {
727
730
defer w .Done ()
728
731
729
732
alloc , _ , err := e .client .Allocations ().Info (allocStub .ID , & api.QueryOptions {
@@ -814,7 +817,7 @@ func (e *Exporter) collectAllocations(ch chan<- prometheus.Metric) error {
814
817
)
815
818
}
816
819
817
- }(allocStub )
820
+ }(* allocStub )
818
821
}
819
822
820
823
w .Wait ()
0 commit comments