minor metrics fix
This commit is contained in:
parent
115bc9f044
commit
9dcec31b00
|
@ -17,13 +17,13 @@ public class ActuatorMetricService implements IActuatorMetricService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private MetricReaderPublicMetrics publicMetrics;
|
private MetricReaderPublicMetrics publicMetrics;
|
||||||
|
|
||||||
private final List<ArrayList<Integer>> statusMetric;
|
private final List<ArrayList<Integer>> statusMetricsByMinute;
|
||||||
private final List<String> statusList;
|
private final List<String> statusList;
|
||||||
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||||
|
|
||||||
public ActuatorMetricService() {
|
public ActuatorMetricService() {
|
||||||
super();
|
super();
|
||||||
statusMetric = new ArrayList<ArrayList<Integer>>();
|
statusMetricsByMinute = new ArrayList<ArrayList<Integer>>();
|
||||||
statusList = new ArrayList<String>();
|
statusList = new ArrayList<String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ public class ActuatorMetricService implements IActuatorMetricService {
|
||||||
public Object[][] getGraphData() {
|
public Object[][] getGraphData() {
|
||||||
final Date current = new Date();
|
final Date current = new Date();
|
||||||
final int colCount = statusList.size() + 1;
|
final int colCount = statusList.size() + 1;
|
||||||
final int rowCount = statusMetric.size() + 1;
|
final int rowCount = statusMetricsByMinute.size() + 1;
|
||||||
final Object[][] result = new Object[rowCount][colCount];
|
final Object[][] result = new Object[rowCount][colCount];
|
||||||
result[0][0] = "Time";
|
result[0][0] = "Time";
|
||||||
int j = 1;
|
int j = 1;
|
||||||
|
@ -41,19 +41,23 @@ public class ActuatorMetricService implements IActuatorMetricService {
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Integer> temp;
|
|
||||||
List<Integer> last = new ArrayList<Integer>();
|
|
||||||
for (int i = 1; i < rowCount; i++) {
|
for (int i = 1; i < rowCount; i++) {
|
||||||
temp = statusMetric.get(i - 1);
|
|
||||||
result[i][0] = dateFormat.format(new Date(current.getTime() - (60000 * (rowCount - i))));
|
result[i][0] = dateFormat.format(new Date(current.getTime() - (60000 * (rowCount - i))));
|
||||||
for (j = 1; j <= temp.size(); j++) {
|
}
|
||||||
result[i][j] = temp.get(j - 1) - (last.size() >= j ? last.get(j - 1) : 0);
|
|
||||||
|
List<Integer> minuteOfStatuses;
|
||||||
|
List<Integer> last = new ArrayList<Integer>();
|
||||||
|
|
||||||
|
for (int i = 1; i < rowCount; i++) {
|
||||||
|
minuteOfStatuses = statusMetricsByMinute.get(i - 1);
|
||||||
|
for (j = 1; j <= minuteOfStatuses.size(); j++) {
|
||||||
|
result[i][j] = minuteOfStatuses.get(j - 1) - (last.size() >= j ? last.get(j - 1) : 0);
|
||||||
}
|
}
|
||||||
while (j < colCount) {
|
while (j < colCount) {
|
||||||
result[i][j] = 0;
|
result[i][j] = 0;
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
last = temp;
|
last = minuteOfStatuses;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -62,16 +66,16 @@ public class ActuatorMetricService implements IActuatorMetricService {
|
||||||
|
|
||||||
@Scheduled(fixedDelay = 60000)
|
@Scheduled(fixedDelay = 60000)
|
||||||
private void exportMetrics() {
|
private void exportMetrics() {
|
||||||
final ArrayList<Integer> statusCount = initializeCounterList(statusList.size());
|
final ArrayList<Integer> lastMinuteStatuses = initializeStatuses(statusList.size());
|
||||||
|
|
||||||
for (final Metric<?> counterMetric : publicMetrics.metrics()) {
|
for (final Metric<?> counterMetric : publicMetrics.metrics()) {
|
||||||
updateStatusCount(counterMetric, statusCount);
|
updateMetrics(counterMetric, lastMinuteStatuses);
|
||||||
}
|
}
|
||||||
|
|
||||||
statusMetric.add(statusCount);
|
statusMetricsByMinute.add(lastMinuteStatuses);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArrayList<Integer> initializeCounterList(final int size) {
|
private ArrayList<Integer> initializeStatuses(final int size) {
|
||||||
final ArrayList<Integer> counterList = new ArrayList<Integer>();
|
final ArrayList<Integer> counterList = new ArrayList<Integer>();
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
counterList.add(0);
|
counterList.add(0);
|
||||||
|
@ -79,22 +83,26 @@ public class ActuatorMetricService implements IActuatorMetricService {
|
||||||
return counterList;
|
return counterList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateStatusCount(final Metric<?> counterMetric, final ArrayList<Integer> statusCount) {
|
private void updateMetrics(final Metric<?> counterMetric, final ArrayList<Integer> statusCount) {
|
||||||
String status = "";
|
String status = "";
|
||||||
int index = -1;
|
int index = -1;
|
||||||
int oldCount = 0;
|
int oldCount = 0;
|
||||||
|
|
||||||
if (counterMetric.getName().contains("counter.status.")) {
|
if (counterMetric.getName().contains("counter.status.")) {
|
||||||
status = counterMetric.getName().substring(15, 18); // example 404, 200
|
status = counterMetric.getName().substring(15, 18); // example 404, 200
|
||||||
if (!statusList.contains(status)) {
|
appendStatusIfNotExist(status, statusCount);
|
||||||
statusList.add(status);
|
|
||||||
statusCount.add(0);
|
|
||||||
}
|
|
||||||
index = statusList.indexOf(status);
|
index = statusList.indexOf(status);
|
||||||
oldCount = statusCount.get(index) == null ? 0 : statusCount.get(index);
|
oldCount = statusCount.get(index) == null ? 0 : statusCount.get(index);
|
||||||
statusCount.set(index, counterMetric.getValue().intValue() + oldCount);
|
statusCount.set(index, counterMetric.getValue().intValue() + oldCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void appendStatusIfNotExist(final String status, final ArrayList<Integer> statusCount) {
|
||||||
|
if (!statusList.contains(status)) {
|
||||||
|
statusList.add(status);
|
||||||
|
statusCount.add(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
}
|
}
|
Loading…
Reference in New Issue