Skip to content

Commit 716d207

Browse files
committed
minor metric fix
1 parent 9dcec31 commit 716d207

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

‎spring-security-rest-full/src/main/java/org/baeldung/web/metric/CustomActuatorMetricService.java‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ public class CustomActuatorMetricService implements ICustomActuatorMetricService
2121
@Autowired
2222
private CounterService counter;
2323

24-
private final List<ArrayList<Integer>> statusMetric;
24+
private final List<ArrayList<Integer>> statusMetricsByMinute;
2525
private final List<String> statusList;
2626
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
2727

2828
public CustomActuatorMetricService() {
2929
super();
3030
repo = new InMemoryMetricRepository();
31-
statusMetric = new ArrayList<ArrayList<Integer>>();
31+
statusMetricsByMinute = new ArrayList<ArrayList<Integer>>();
3232
statusList = new ArrayList<String>();
3333
}
3434

@@ -46,7 +46,7 @@ public void increaseCount(final int status) {
4646
public Object[][] getGraphData() {
4747
final Date current = new Date();
4848
final int colCount = statusList.size() + 1;
49-
final int rowCount = statusMetric.size() + 1;
49+
final int rowCount = statusMetricsByMinute.size() + 1;
5050
final Object[][] result = new Object[rowCount][colCount];
5151
result[0][0] = "Time";
5252

@@ -56,12 +56,15 @@ public Object[][] getGraphData() {
5656
j++;
5757
}
5858

59-
List<Integer> temp;
6059
for (int i = 1; i < rowCount; i++) {
61-
temp = statusMetric.get(i - 1);
6260
result[i][0] = dateFormat.format(new Date(current.getTime() - (60000 * (rowCount - i))));
63-
for (j = 1; j <= temp.size(); j++) {
64-
result[i][j] = temp.get(j - 1);
61+
}
62+
63+
List<Integer> minuteOfStatuses;
64+
for (int i = 1; i < rowCount; i++) {
65+
minuteOfStatuses = statusMetricsByMinute.get(i - 1);
66+
for (j = 1; j <= minuteOfStatuses.size(); j++) {
67+
result[i][j] = minuteOfStatuses.get(j - 1);
6568
}
6669
while (j < colCount) {
6770
result[i][j] = 0;
@@ -87,6 +90,6 @@ private void exportMetrics() {
8790
}
8891

8992
}
90-
statusMetric.add(statusCount);
93+
statusMetricsByMinute.add(statusCount);
9194
}
9295
}

0 commit comments

Comments
 (0)