2121package eu .openanalytics .containerproxy .stat .impl ;
2222
2323import eu .openanalytics .containerproxy .event .*;
24+ import eu .openanalytics .containerproxy .model .spec .ProxySpec ;
2425import eu .openanalytics .containerproxy .service .EventService ;
26+ import eu .openanalytics .containerproxy .service .ProxyService ;
2527import eu .openanalytics .containerproxy .stat .IStatCollector ;
2628import io .micrometer .core .instrument .Counter ;
2729import io .micrometer .core .instrument .MeterRegistry ;
28- import io .micrometer .core .instrument .Timer ;
2930import org .springframework .context .event .EventListener ;
3031import org .springframework .core .env .Environment ;
3132import org .springframework .stereotype .Component ;
@@ -40,9 +41,8 @@ public class Micrometer implements IStatCollector {
4041 @ Inject
4142 private MeterRegistry registry ;
4243
43- private Timer appStartupTimer ;
44-
45- private Timer appUsageTimer ;
44+ @ Inject
45+ private ProxyService proxyService ;
4646
4747 private Counter appStartFailedCounter ;
4848
@@ -52,20 +52,19 @@ public class Micrometer implements IStatCollector {
5252
5353 private Counter userLogouts ;
5454
55- private Counter appStarts ;
56-
57- private Counter appStops ;
58-
5955 @ PostConstruct
6056 public void init () {
6157 userLogins = registry .counter ("userLogins" );
6258 userLogouts = registry .counter ("userLogouts" );
63- appStarts = registry .counter ("appStarts" );
64- appStops = registry .counter ("appStops" );
65- appStartupTimer = registry .timer ("startupTime" );
66- appUsageTimer = registry .timer ("usageTime" );
6759 appStartFailedCounter = registry .counter ("startFailed" );
6860 authFailedCounter = registry .counter ("authFailed" );
61+
62+ for (ProxySpec spec : proxyService .getProxySpecs (null , true )) {
63+ registry .counter ("appStarts" , "spec.id" , spec .getId ());
64+ registry .counter ("appStops" , "spec.id" , spec .getId ());
65+ registry .timer ("startupTime" , "spec.id" , spec .getId ());
66+ registry .timer ("usageTime" , "spec.id" , spec .getId ());
67+ }
6968 }
7069
7170 @ Override
@@ -89,16 +88,16 @@ public void onUserLoginEvent(UserLoginEvent event) {
8988 public void onProxyStartEvent (ProxyStartEvent event ) {
9089 System .out .printf ("ProxyStartEvent %s ,%s\n " , event .getUserId (), event .getStartupTime ());
9190
92- appStarts .increment ();
93- appStartupTimer .record (event .getStartupTime ());
91+ registry . counter ( " appStarts" , "spec.id" , event . getSpecId ()) .increment ();
92+ registry . timer ( "startupTime" , "spec.id" , event . getSpecId ()) .record (event .getStartupTime ());
9493 }
9594
9695 @ EventListener
9796 public void onProxyStopEvent (ProxyStopEvent event ) {
9897 System .out .printf ("ProxyStopEvent %s, %s\n " , event .getUserId (), event .getUsageTime ());
9998
100- appStops .increment ();
101- appUsageTimer .record (event .getUsageTime ());
99+ registry . counter ( " appStops" , "spec.id" , event . getSpecId ()) .increment ();
100+ registry . timer ( "usageTime" , "spec.id" , event . getSpecId ()) .record (event .getUsageTime ());
102101 }
103102
104103 @ EventListener
0 commit comments