Skip to content

Commit

Permalink
Don't call Jenkins.get() within loop
Browse files Browse the repository at this point in the history
  • Loading branch information
waschndolos committed Nov 26, 2023
1 parent 8dab3b1 commit 7e3f6e6
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ public class JenkinsStatusCollector extends Collector {
public List<MetricFamilySamples> collect() {

CollectorFactory factory = new CollectorFactory();

Jenkins jenkins = Jenkins.get();
List<MetricCollector<Jenkins, ? extends Collector>> collectors = new ArrayList<>();

collectors.add(factory.createJenkinsCollector(CollectorType.JENKINS_VERSION_INFO_GAUGE, new String[]{}));
collectors.add(factory.createJenkinsCollector(CollectorType.JENKINS_UP_GAUGE, new String[]{}));
collectors.add(factory.createJenkinsCollector(CollectorType.JENKINS_UPTIME_GAUGE, new String[]{}));
collectors.add(factory.createJenkinsCollector(CollectorType.NODES_ONLINE_GAUGE, new String[]{"node"}));

collectors.forEach(c -> c.calculateMetric(Jenkins.get(), new String[]{}));
collectors.forEach(c -> c.calculateMetric(jenkins, new String[]{}));

return collectors.stream()
.map(MetricCollector::collect)
Expand Down

0 comments on commit 7e3f6e6

Please sign in to comment.