/** * Get the counter metric with the supplied name, within the scope of this monitor. * * @param name the name of the counter * @return the counter */ public Counter counter(String name) { return metrics.getCounter(name); }
/** * Get the histogram metric with the supplied name, within the scope of this monitor. * * @param name the name of the histogram * @return the histogram */ public Counter histogram(String name) { return metrics.getCounter(name); }
/** * Get the counter metric with the supplied name, within the scope of this monitor. * * @param name the name of the counter * @return the counter */ public Counter counter(String name) { return metrics.getCounter(name); }
/** * Get the histogram metric with the supplied name, within the scope of this monitor. * * @param name the name of the histogram * @return the histogram */ public Counter histogram(String name) { return metrics.getCounter(name); }
/** * Persist entity counts into the Metrics object, as we only want to do this once per process() * function and not every time we add an entity. */ public void persistCounts() { for (Entry<String, Long> entry : entityAddedCounts.entrySet()) { metrics.getCounter(entry.getKey() + "-added").inc(entry.getValue()); } entityAddedCounts.clear(); for (Entry<String, Long> entry : entityRemovedCounts.entrySet()) { metrics.getCounter(entry.getKey() + "-removed").inc(entry.getValue()); } entityRemovedCounts.clear(); }
/** * Persist entity counts into the Metrics object, as we only want to do this once per process() * function and not every time we add an entity. */ public void persistCounts() { for (Entry<String, Long> entry : entityAddedCounts.entrySet()) { metrics.getCounter(entry.getKey() + "-added").inc(entry.getValue()); } entityAddedCounts.clear(); for (Entry<String, Long> entry : entityRemovedCounts.entrySet()) { metrics.getCounter(entry.getKey() + "-removed").inc(entry.getValue()); } entityRemovedCounts.clear(); }
/** Create a new pipeline from the provided YAML, with the given name */ public BaleenPipeline create(String name, PipelineConfiguration config) throws BaleenException { if (pipelines.containsKey(name)) { throw new BaleenException("A " + getType() + " of that name already exists"); } logger.info("Creating {}", name); BaleenPipeline pipeline = toPipeline(name, config); pipelines.put(name, pipeline); es.submit(pipeline); metrics.getCounter("created").inc(); return pipeline; }
/** Create a new pipeline from the provided YAML, with the given name */ public BaleenPipeline create(String name, PipelineConfiguration config) throws BaleenException { if (pipelines.containsKey(name)) { throw new BaleenException("A " + getType() + " of that name already exists"); } logger.info("Creating {}", name); BaleenPipeline pipeline = toPipeline(name, config); pipelines.put(name, pipeline); es.submit(pipeline); metrics.getCounter("created").inc(); return pipeline; }
/** Remove a pipeline by name */ public boolean remove(String name) { BaleenPipeline pipeline = pipelines.remove(name); if (pipeline != null) { logger.info("Removing {} {}", getType(), name); try { pipeline.destroy(); } catch (Exception e) { logger.error("Error destroying {} {}", getType(), name, e); } metrics.getCounter("removed").inc(); return true; } else { logger.warn("Unable to find to remove {} {}", getType(), name); return false; } }
/** Remove a pipeline by name */ public boolean remove(String name) { BaleenPipeline pipeline = pipelines.remove(name); if (pipeline != null) { logger.info("Removing {} {}", getType(), name); try { pipeline.destroy(); } catch (Exception e) { logger.error("Error destroying {} {}", getType(), name, e); } metrics.getCounter("removed").inc(); return true; } else { logger.warn("Unable to find to remove {} {}", getType(), name); return false; } }
@Test public void testGetCounter() { metrics.getCounter("counter"); verify(factory).getCounter(anyString(), eq("counter")); }
} else { logger.warn("Configuration omited for {} {} - will be skipped", getType(), name); metrics.getCounter("errors").inc(); continue;
} else { logger.warn("Configuration omitted for {} {} - will be skipped", getType(), name); metrics.getCounter("errors").inc(); continue;
@Test public void testEntityAdded() { UimaMonitor monitor = new UimaMonitor(PIPELINE, this.getClass()); monitor.entityAdded(ENTITY_TYPE_1); monitor.entityAdded(ENTITY_TYPE_1); monitor.entityAdded(ENTITY_TYPE_2); monitor.entityAdded(ENTITY_TYPE_2); monitor.entityAdded(ENTITY_TYPE_1); monitor.persistCounts(); Metrics m = MetricsFactory.getMetrics(PIPELINE, this.getClass()); assertEquals(3, m.getCounter(ENTITY_TYPE_1 + "-added").getCount()); assertEquals(2, m.getCounter(ENTITY_TYPE_2 + "-added").getCount()); }
@Test public void testEntityRemoved() { UimaMonitor monitor = new UimaMonitor(PIPELINE, this.getClass()); monitor.entityRemoved(ENTITY_TYPE_1); monitor.entityRemoved(ENTITY_TYPE_1); monitor.entityRemoved(ENTITY_TYPE_2); monitor.entityRemoved(ENTITY_TYPE_2); monitor.entityRemoved(ENTITY_TYPE_1); monitor.persistCounts(); Metrics m = MetricsFactory.getMetrics(PIPELINE, this.getClass()); assertEquals(3, m.getCounter(ENTITY_TYPE_1 + "-removed").getCount()); assertEquals(2, m.getCounter(ENTITY_TYPE_2 + "-removed").getCount()); }
@Test public void testConfiguration() throws Exception { YamlConfiguration configuration = new YamlConfiguration(MetricsFactoryTest.class, "reporters.yaml"); metrics.configure(configuration); metrics.start(); try { metrics.getCounter(MetricsFactoryTest.class, "testConfiguration").inc(); metrics.getCounter(MetricsFactoryTest.class, "testConfiguration").inc(); MetricsFactory.getMetrics("test", MetricsFactoryTest.class) .getCounter("testConfigurationMetric") .inc(); metrics.report(); Thread.sleep(1000); } finally { metrics.stop(); } // Delete the directory of CSV tests TestingUtils.deleteDirectory("test_csvmetrics"); } }