Skip to content

Commit ac485ee

Browse files
committed
Tag spring.batch.job.active metric with the job name
Resolves #3750
1 parent 3a09efe commit ac485ee

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2019 the original author or authors.
2+
* Copyright 2006-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -301,7 +301,8 @@ public final void execute(JobExecution execution) {
301301
}
302302

303303
JobSynchronizationManager.register(execution);
304-
LongTaskTimer longTaskTimer = BatchMetrics.createLongTaskTimer("job.active", "Active jobs");
304+
LongTaskTimer longTaskTimer = BatchMetrics.createLongTaskTimer("job.active", "Active jobs",
305+
Tag.of("name", execution.getJobInstance().getJobName()));
305306
LongTaskTimer.Sample longTaskTimerSample = longTaskTimer.start();
306307
Timer.Sample timerSample = BatchMetrics.createTimerSample();
307308
try {

spring-batch-samples/src/test/java/org/springframework/batch/sample/metrics/BatchMetricsTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ public void testBatchMetrics() throws Exception {
162162

163163
try {
164164
Metrics.globalRegistry.get("spring.batch.job.active")
165+
.tag("name", "job")
165166
.longTaskTimer();
166167
} catch (Exception e) {
167168
fail("There should be a meter of type LONG_TASK_TIMER named spring.batch.job.active" +

0 commit comments

Comments
 (0)