1313import org .springframework .stereotype .Service ;
1414
1515@ Service
16- public class MetricService {
16+ public class MetricService implements IMetricService {
1717
1818 @ Autowired
1919 private MetricRepository repo ;
2020
2121 @ Autowired
2222 private CounterService counter ;
2323
24- private ArrayList <ArrayList <Integer >> statusMetric ;
24+ private List <ArrayList <Integer >> statusMetric ;
2525 private List <String > statusList ;
26-
2726 private static final SimpleDateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd HH:mm" );
2827
2928 public MetricService () {
@@ -32,35 +31,19 @@ public MetricService() {
3231 statusList = new ArrayList <String >();
3332 }
3433
34+ // API
35+
3536 public void increaseCount (final int status ) {
3637 counter .increment ("status." + status );
3738 if (!statusList .contains ("counter.status." + status )) {
3839 statusList .add ("counter.status." + status );
3940 }
4041 }
4142
42- @ Scheduled (fixedDelay = 60000 )
43- private void exportMetrics () {
44- Metric <?> metric ;
45- ArrayList <Integer > statusCount = new ArrayList <Integer >();
46- for (String status : statusList ) {
47- metric = repo .findOne (status );
48- if (metric != null ) {
49- statusCount .add (metric .getValue ().intValue ());
50- repo .reset (status );
51- } else {
52- statusCount .add (0 );
53- }
54-
55- }
56- statusMetric .add (statusCount );
57- }
58-
5943 public Object [][] getGraphData () {
6044 Date current = new Date ();
6145 int colCount = statusList .size () + 1 ;
6246 int rowCount = statusMetric .size () + 1 ;
63-
6447 Object [][] result = new Object [rowCount ][colCount ];
6548 result [0 ][0 ] = "Time" ;
6649
@@ -70,7 +53,7 @@ public Object[][] getGraphData() {
7053 j ++;
7154 }
7255
73- ArrayList <Integer > temp ;
56+ List <Integer > temp ;
7457 for (int i = 1 ; i < rowCount ; i ++) {
7558 temp = statusMetric .get (i - 1 );
7659 result [i ][0 ] = dateFormat .format (new Date (current .getTime () - (60000 * (rowCount - i ))));
@@ -82,8 +65,25 @@ public Object[][] getGraphData() {
8265 j ++;
8366 }
8467 }
85-
8668 return result ;
8769 }
8870
71+ // Non - API
72+
73+ @ Scheduled (fixedDelay = 60000 )
74+ private void exportMetrics () {
75+ Metric <?> metric ;
76+ ArrayList <Integer > statusCount = new ArrayList <Integer >();
77+ for (String status : statusList ) {
78+ metric = repo .findOne (status );
79+ if (metric != null ) {
80+ statusCount .add (metric .getValue ().intValue ());
81+ repo .reset (status );
82+ } else {
83+ statusCount .add (0 );
84+ }
85+
86+ }
87+ statusMetric .add (statusCount );
88+ }
8989}
0 commit comments