public MeasurementSession getMeasurementSession() { return Stagemonitor.getMeasurementSession(); }
public AlerterTypeServlet() { this(Stagemonitor.getPlugin(AlertingPlugin.class), Stagemonitor.getMeasurementSession()); }
@Override public void onStart(SpanWrapper spanWrapper) { info = SpanContextInformation.forSpan(spanWrapper); info.spanWrapper = spanWrapper; info.setParent(SpanContextInformation.getCurrent()); spanContextMap.put(spanWrapper, info); for (Map.Entry<String, String> entry : Stagemonitor.getMeasurementSession().asMap().entrySet()) { spanWrapper.setTag(entry.getKey(), entry.getValue()); } }
@Override public void injectHtml(HtmlInjector.InjectArguments injectArguments) { final List<String> pathsOfWidgetTabPlugins = new ArrayList<String>(); for (String path : Stagemonitor.getPathsOfWidgetTabPlugins()) { pathsOfWidgetTabPlugins.add(contextPath + path); } final List<String> pathsOfWidgetMetricTabPlugins = new ArrayList<String>(); for (String path : Stagemonitor.getPathsOfWidgetMetricTabPlugins()) { pathsOfWidgetMetricTabPlugins.add(contextPath + path); } final SpanWrapper span = injectArguments.getSpanWrapper(); injectArguments.setContentToInjectBeforeClosingBody(widgetTemplate .replace("@@JSON_REQUEST_TRACE_PLACEHOLDER@@", span != null ? JsonUtils.toJson(span, SpanUtils.CALL_TREE_ASCII) : "null") .replace("@@CONFIGURATION_OPTIONS@@", JsonUtils.toJson(configuration.getConfigurationOptionsByCategory())) .replace("@@CONFIGURATION_PWD_SET@@", Boolean.toString(servletPlugin.getConfigurationPasswordChecker().isPasswordSet())) .replace("@@CONFIGURATION_SOURCES@@", JsonUtils.toJson(configuration.getNamesOfConfigurationSources())) .replace("@@MEASUREMENT_SESSION@@", JsonUtils.toJson(Stagemonitor.getMeasurementSession())) .replace("@@PATHS_OF_TAB_PLUGINS@@", JsonUtils.toJson(pathsOfWidgetTabPlugins)) .replace("@@PATHS_OF_WIDGET_METRIC_TAB_PLUGINS@@", JsonUtils.toJson(pathsOfWidgetMetricTabPlugins)) .replace("@@CONNECTION_ID@@", UUID.randomUUID().toString())); } }
@Override public void onStartup(ServletContext ctx) { if (ServletContainerInitializerUtil.avoidDoubleInit(this, ctx)) return; final AlertingPlugin alertingPlugin = Stagemonitor.getPlugin(AlertingPlugin.class); ctx.addServlet(AlerterTypeServlet.class.getSimpleName(), new AlerterTypeServlet(alertingPlugin, Stagemonitor.getMeasurementSession())) .addMapping("/stagemonitor/alerter-types"); ctx.addServlet(IncidentServlet.class.getSimpleName(), new IncidentServlet(alertingPlugin)) .addMapping("/stagemonitor/incidents"); ctx.addServlet(TestAlertSenderServlet.class.getSimpleName(), new TestAlertSenderServlet()) .addMapping("/stagemonitor/test-alert"); } }
@Test public void testStartMonitoring() throws Exception { when(corePlugin.isStagemonitorActive()).thenReturn(true); Stagemonitor.setConfiguration(configuration); Stagemonitor.reset(); final MeasurementSession measurementSession = new MeasurementSession("StagemonitorTest", "testHost", "testInstance"); Stagemonitor.reset(measurementSession); assertTrue(Stagemonitor.isStarted()); assertTrue(Stagemonitor.getMeasurementSession().isInitialized()); assertSame(measurementSession, Stagemonitor.getMeasurementSession()); assertThat(healthCheckRegistry.runHealthCheck("TestPlugin").isHealthy()).isTrue(); assertThat(healthCheckRegistry.runHealthCheck("TestExceptionPlugin").isHealthy()).isFalse(); }
@Test public void testStartMonitoringNotActive() throws Exception { when(corePlugin.isStagemonitorActive()).thenReturn(false); final MeasurementSession measurementSession = new MeasurementSession("StagemonitorTest", "testHost", "testInstance"); Stagemonitor.reset(measurementSession); assertTrue(Stagemonitor.isDisabled()); assertFalse(Stagemonitor.isStarted()); assertTrue(Stagemonitor.getMeasurementSession().isInitialized()); assertThat(healthCheckRegistry.getNames()).doesNotContain("TestPlugin", "TestExceptionPlugin"); }
public HttpRequestTrace(String requestId, String url, Map<String, String> headers, String method, String connectionId, boolean showWidgetAllowed) { this(requestId, url, headers, method, connectionId, showWidgetAllowed, Stagemonitor.getMeasurementSession(), Stagemonitor.getPlugin(RequestMonitorPlugin.class)); }
public RequestTrace(String requestId) { this(requestId, Stagemonitor.getMeasurementSession(), Stagemonitor.getPlugin(RequestMonitorPlugin.class)); }
@Override public void injectHtml(HtmlInjector.InjectArguments injectArguments) { HttpRequestTrace requestTrace = null; if (injectArguments.getRequestInformation() != null) { requestTrace = injectArguments.getRequestInformation().getRequestTrace(); } final List<String> pathsOfWidgetTabPlugins = new ArrayList<String>(); for (String path : Stagemonitor.getPathsOfWidgetTabPlugins()) { pathsOfWidgetTabPlugins.add(contextPath + path); } final List<String> pathsOfWidgetMetricTabPlugins = new ArrayList<String>(); for (String path : Stagemonitor.getPathsOfWidgetMetricTabPlugins()) { pathsOfWidgetMetricTabPlugins.add(contextPath + path); } injectArguments.setContentToInjectBeforeClosingBody(widgetTemplate .replace("@@JSON_REQUEST_TACE_PLACEHOLDER@@", requestTrace != null ? requestTrace.toJson() : "null") .replace("@@CONFIGURATION_OPTIONS@@", JsonUtils.toJson(configuration.getConfigurationOptionsByCategory())) .replace("@@CONFIGURATION_PWD_SET@@", Boolean.toString(configuration.isPasswordSet())) .replace("@@CONFIGURATION_SOURCES@@", JsonUtils.toJson(configuration.getNamesOfConfigurationSources())) .replace("@@MEASUREMENT_SESSION@@", JsonUtils.toJson(Stagemonitor.getMeasurementSession())) .replace("@@PATHS_OF_TAB_PLUGINS@@", JsonUtils.toJson(pathsOfWidgetTabPlugins)) .replace("@@PATHS_OF_WIDGET_METRIC_TAB_PLUGINS@@", JsonUtils.toJson(pathsOfWidgetMetricTabPlugins))); } }
public <T extends RequestTrace> void monitorStart(MonitoredRequest<T> monitoredRequest) { final long start = System.nanoTime(); RequestInformation<T> info = new RequestInformation<T>(); info.monitoredRequest = monitoredRequest; detectForwardedRequest(info); request.set(info); try { if (!corePlugin.isStagemonitorActive()) { return; } if (Stagemonitor.getMeasurementSession().isNull()) { createMeasurementSession(); } info.firstRequest = noOfRequests.get() == 0; if (Stagemonitor.getMeasurementSession().getInstanceName() == null) { getInstanceNameFromExecution(monitoredRequest); } if (info.monitorThisRequest()) { if (!Stagemonitor.isStarted()) { info.startup = Stagemonitor.startMonitoring(); } beforeExecution(monitoredRequest, info); } } finally { info.overhead1 = System.nanoTime() - start; } }
private synchronized void createMeasurementSession() { if (Stagemonitor.getMeasurementSession().isNull()) { MeasurementSession session = new MeasurementSession(corePlugin.getApplicationName(), corePlugin.getHostName(), corePlugin.getInstanceName()); Stagemonitor.setMeasurementSession(session); } }
private synchronized void getInstanceNameFromExecution(MonitoredRequest<?> monitoredRequest) { final MeasurementSession measurementSession = Stagemonitor.getMeasurementSession(); if (measurementSession.getInstanceName() == null) { MeasurementSession session = new MeasurementSession(measurementSession.getApplicationName(), measurementSession.getHostName(), monitoredRequest.getInstanceName()); Stagemonitor.setMeasurementSession(session); } }