protected void reportMetrics(CommandContext commandContext) { ProcessEngineConfigurationImpl engineConfiguration = commandContext.getProcessEngineConfiguration(); if (engineConfiguration.isHistoryCleanupMetricsEnabled()) { for (Map.Entry<String, Long> report : reports.entrySet()){ engineConfiguration.getDbMetricsReporter().reportValueAtOnce(report.getKey(), report.getValue()); } } }
protected void reportMetrics(CommandContext commandContext) { ProcessEngineConfigurationImpl engineConfiguration = commandContext.getProcessEngineConfiguration(); if (engineConfiguration.isHistoryCleanupMetricsEnabled()) { for (Map.Entry<String, Long> report : reports.entrySet()){ engineConfiguration.getDbMetricsReporter().reportValueAtOnce(report.getKey(), report.getValue()); } } }
@Override public void run() { //set up long startTime = START_TIME.get(); MetricsRegistry metricsRegistry = processEngineConfiguration.getMetricsRegistry(); Set<String> metricNames = metricsRegistry.getMeters().keySet(); //generate metric for (int i = 0; i < ITERATION_PER_EXECUTION; i++) { ClockUtil.setCurrentTime(new Date(startTime)); for (String metricName : metricNames) { //mark occurence metricsRegistry.markOccurrence(metricName, 1); } processEngineConfiguration.getDbMetricsReporter().reportNow(); startTime += INTERVAL; } START_TIME.set(startTime); }
protected boolean isEndTimeAfterLastReportInterval(MetricsQueryImpl query) { long reportingIntervalInSeconds = Context.getProcessEngineConfiguration() .getDbMetricsReporter() .getReportingIntervalInSeconds(); return (query.getEndDate() == null || query.getEndDateMilliseconds()>= ClockUtil.getCurrentTime().getTime() - (1000 * reportingIntervalInSeconds)); }
protected boolean isEndTimeAfterLastReportInterval(MetricsQueryImpl query) { long reportingIntervalInSeconds = Context.getProcessEngineConfiguration() .getDbMetricsReporter() .getReportingIntervalInSeconds(); return (query.getEndDate() == null || query.getEndDateMilliseconds()>= ClockUtil.getCurrentTime().getTime() - (1000 * reportingIntervalInSeconds)); }
protected void reportMetrics() { for (String metricName : metricsRegistry.getMeters().keySet()) { //mark random occurence long occurence = (long) (rand.nextInt((MAX_OCCURENCE - MIN_OCCURENCE) + 1) + MIN_OCCURENCE); metricsRegistry.markOccurrence(metricName, occurence); } //report logged metrics processEngineConfiguration.getDbMetricsReporter().reportNow(); }
public Void execute(CommandContext commandContext) { ProcessEngineConfigurationImpl engineConfiguration = Context.getProcessEngineConfiguration(); if (!engineConfiguration.isMetricsEnabled()) { throw new ProcessEngineException("Metrics reporting is disabled"); } if (!engineConfiguration.isDbMetricsReporterActivate()) { throw new ProcessEngineException("Metrics reporting to database is disabled"); } DbMetricsReporter dbMetricsReporter = engineConfiguration.getDbMetricsReporter(); dbMetricsReporter.reportNow(); return null; }
public Void execute(CommandContext commandContext) { ProcessEngineConfigurationImpl engineConfiguration = Context.getProcessEngineConfiguration(); if (!engineConfiguration.isMetricsEnabled()) { throw new ProcessEngineException("Metrics reporting is disabled"); } if (!engineConfiguration.isDbMetricsReporterActivate()) { throw new ProcessEngineException("Metrics reporting to database is disabled"); } DbMetricsReporter dbMetricsReporter = engineConfiguration.getDbMetricsReporter(); dbMetricsReporter.reportNow(); return null; }
@Before public void initMetrics() throws Exception { runtimeService = ENGINE_RULE.getRuntimeService(); processEngineConfiguration = ENGINE_RULE.getProcessEngineConfiguration(); managementService = ENGINE_RULE.getManagementService(); //clean up before start clearMetrics(); //init metrics processEngineConfiguration.setDbMetricsReporterActivate(true); lastReporterId = processEngineConfiguration.getDbMetricsReporter().getMetricsCollectionTask().getReporter(); processEngineConfiguration.getDbMetricsReporter().setReporterId(REPORTER_ID); metricsRegistry = processEngineConfiguration.getMetricsRegistry(); rand = new Random(new Date().getTime()); generateMeterData(3, DEFAULT_INTERVAL_MILLIS); }
@Override public void close() { ProcessEngines.unregister(this); if(processEngineConfiguration.isMetricsEnabled()) { processEngineConfiguration.getDbMetricsReporter().stop(); } if ((jobExecutor != null)) { // unregister process engine with Job Executor jobExecutor.unregisterProcessEngine(this); } commandExecutorSchemaOperations.execute(new SchemaOperationProcessEngineClose()); processEngineConfiguration.close(); LOG.processEngineClosed(name); }
@Override public void close() { ProcessEngines.unregister(this); if(processEngineConfiguration.isMetricsEnabled()) { processEngineConfiguration.getDbMetricsReporter().stop(); } if ((jobExecutor != null)) { // unregister process engine with Job Executor jobExecutor.unregisterProcessEngine(this); } commandExecutorSchemaOperations.execute(new SchemaOperationProcessEngineClose()); processEngineConfiguration.close(); LOG.processEngineClosed(name); }
@Test public void testQueryEndDateExclusive() { // given // note: dates should be exact seconds due to missing milliseconds precision on // older mysql versions // cannot insert 1970-01-01 00:00:00 into MySQL ClockUtil.setCurrentTime(new Date(5000L)); runtimeService.startProcessInstanceByKey("testProcess"); processEngineConfiguration.getDbMetricsReporter().reportNow(); ClockUtil.setCurrentTime(new Date(6000L)); runtimeService.startProcessInstanceByKey("testProcess"); processEngineConfiguration.getDbMetricsReporter().reportNow(); ClockUtil.setCurrentTime(new Date(7000L)); runtimeService.startProcessInstanceByKey("testProcess"); processEngineConfiguration.getDbMetricsReporter().reportNow(); // then Query#startDate is inclusive and Query#endDate is exclusive assertEquals(18l, managementService.createMetricsQuery().sum()); assertEquals(18l, managementService.createMetricsQuery().startDate(new Date(0)).sum()); assertEquals(12l, managementService.createMetricsQuery().startDate(new Date(0)).endDate(new Date(7000L)).sum()); assertEquals(18l, managementService.createMetricsQuery().startDate(new Date(0)).endDate(new Date(8000L)).sum()); }
@Test public void testDeleteMetricsWithTimestampBefore() { // given runtimeService.startProcessInstanceByKey("testProcess"); processEngineConfiguration.getDbMetricsReporter().reportNow(); // a count of six (start and end) assertEquals(6l, managementService.createMetricsQuery() .sum()); // if // we delete with timestamp before the timestamp of the log entry managementService.deleteMetrics(new Date(ClockUtil.getCurrentTime().getTime() - 10000)); // then // the entires are NOT deleted assertEquals(6l, managementService.createMetricsQuery() .sum()); }
@After public void cleanUp() { ClockUtil.reset(); processEngineConfiguration.setDbMetricsReporterActivate(false); processEngineConfiguration.getDbMetricsReporter().setReporterId(lastReporterId); clearMetrics(); } }
@Test public void testMetricQueryAggregatedByReporterLimitAndTwoReporters() { // clean up default recorded metrics clearLocalMetrics(); // given // generate data for reporter1 processEngineConfiguration.getDbMetricsReporter().setReporterId("reporter1"); generateMeterData(10, DEFAULT_INTERVAL_MILLIS); // generate data for reporter2 processEngineConfiguration.getDbMetricsReporter().setReporterId("reporter2"); generateMeterData(10, DEFAULT_INTERVAL_MILLIS); int limit = 10; // when List<MetricIntervalValue> metrics = managementService.createMetricsQuery().name(Metrics.ACTIVTY_INSTANCE_START).limit(limit).interval(); List<MetricIntervalValue> aggregatedMetrics = managementService.createMetricsQuery().name(Metrics.ACTIVTY_INSTANCE_START).limit(limit).aggregateByReporter().interval(); // then aggregatedMetrics contains wider time interval assertTrue(metrics.get(limit - 1).getTimestamp().getTime() > aggregatedMetrics.get(limit - 1).getTimestamp().getTime()); assertEquals(metrics.size(), aggregatedMetrics.size()); }
@Test public void testMetricQueryAggregatedByReporterThreeReporters() { // given metric data for default reported // generate data for reporter1 processEngineConfiguration.getDbMetricsReporter().setReporterId("reporter1"); generateMeterData(3, DEFAULT_INTERVAL_MILLIS); // generate data for reporter2 processEngineConfiguration.getDbMetricsReporter().setReporterId("reporter2"); generateMeterData(3, DEFAULT_INTERVAL_MILLIS); List<MetricIntervalValue> metrics = managementService.createMetricsQuery().interval(); // when List<MetricIntervalValue> aggregatedMetrics = managementService.createMetricsQuery().aggregateByReporter().interval(); // then // multiply by 3 because there are three reporters: 'REPORTER_ID' (check the #initMetrics()), reporter1 and reporter2 assertEquals(metrics.size(), aggregatedMetrics.size() * 3); for (MetricIntervalValue metricIntervalValue : aggregatedMetrics) { assertNull(metricIntervalValue.getReporter()); } }
@Test public void testDeleteMetrics() { // given runtimeService.startProcessInstanceByKey("testProcess"); processEngineConfiguration.getDbMetricsReporter().reportNow(); // a count of six (start and end) assertEquals(6l, managementService.createMetricsQuery() .sum()); // if // we delete with timestamp "null" managementService.deleteMetrics(null); // then // all entries are deleted assertEquals(0l, managementService.createMetricsQuery() .sum()); } @Test
@Test public void testDeleteMetricsWithTimestamp() { // given runtimeService.startProcessInstanceByKey("testProcess"); processEngineConfiguration.getDbMetricsReporter().reportNow(); // a count of six (start and end) assertEquals(6l, managementService.createMetricsQuery() .sum()); // if // we delete with timestamp older or equal to the timestamp of the log entry managementService.deleteMetrics(ClockUtil.getCurrentTime()); // then // all entries are deleted assertEquals(0l, managementService.createMetricsQuery() .name(Metrics.ACTIVTY_INSTANCE_START) .sum()); }
@Test public void testStartAndEndMetricsAreEqual() { // given //when runtimeService.startProcessInstanceByKey("testProcess"); processEngineConfiguration.getDbMetricsReporter().reportNow(); //then end and start metrics are equal long start = managementService.createMetricsQuery() .name(Metrics.ACTIVTY_INSTANCE_START) .sum(); long end = managementService.createMetricsQuery() .name(Metrics.ACTIVTY_INSTANCE_END) .sum(); assertEquals(end, start); }
@Deployment(resources = "org/camunda/bpm/engine/test/api/mgmt/metrics/asyncServiceTaskProcess.bpmn20.xml") public void testJobAcquisitionMetricReporting() { // given for (int i = 0; i < 3; i++) { runtimeService.startProcessInstanceByKey("asyncServiceTaskProcess"); } // when waitForJobExecutorToProcessAllJobs(5000); processEngineConfiguration.getDbMetricsReporter().reportNow(); // then long acquisitionAttempts = managementService.createMetricsQuery().name(Metrics.JOB_ACQUISITION_ATTEMPT).sum(); assertTrue(acquisitionAttempts >= 1); long acquiredJobs = managementService.createMetricsQuery() .name(Metrics.JOB_ACQUIRED_SUCCESS).sum(); assertEquals(3, acquiredJobs); }