public static void decrementMetric(String name, long count) { Metrics metrics = MetricsFactory.getInstance(); if (metrics != null) { metrics.decrementCounter(name, count); } }
private void endMetrics(String method) { Metrics metrics = MetricsFactory.getInstance(); if (metrics != null) { MetricsScope scope = openScopes.remove(method); if (scope != null) { metrics.endScope(scope); } } }
private void closeConnection() { Metrics metrics = MetricsFactory.getInstance(); if (metrics != null) { try { metrics.decrementCounter(MetricsConstant.OPEN_CONNECTIONS); } catch (Exception e) { LOG.warn("Error reporting HS2 close connection operation to Metrics system", e); } } }
private void beginMetrics(String method) { Metrics metrics = MetricsFactory.getInstance(); if (metrics != null) { MetricsScope scope = metrics.createScope(MetricsConstant.API_PREFIX + method); openScopes.put(method, scope); } }
private void incrementMetricsCounter(String name, long count) { Metrics metrics = MetricsFactory.getInstance(); if (metrics != null) { try { metrics.incrementCounter(name, count); } catch (Exception e) { LOG.warn("Error Reporting JvmPauseMonitor to Metrics system", e); } } } }
public static void incrementMetric(String name, long count) { Metrics metrics = MetricsFactory.getInstance(); if (metrics != null) { metrics.incrementCounter(name, count); } }
private void openConnection() { Metrics metrics = MetricsFactory.getInstance(); if (metrics != null) { try { metrics.incrementCounter(MetricsConstant.OPEN_CONNECTIONS); metrics.incrementCounter(MetricsConstant.CUMULATIVE_CONNECTION_COUNT); } catch (Exception e) { LOG.warn("Error reporting HS2 open connection operation to Metrics system", e); } } }
public void destroy() { ms.unregisterSource(sourceName); ms = null; if (codahaleGaugeNames != null) { Metrics metrics = MetricsFactory.getInstance(); for (String chgName : codahaleGaugeNames) { metrics.removeGauge(chgName); } codahaleGaugeNames = null; } }
public void run() throws HiveSQLException { beforeRun(); try { Metrics metrics = MetricsFactory.getInstance(); if (metrics != null) { metrics.incrementCounter(MetricsConstant.OPEN_OPERATIONS); } runInternal(); } finally { afterRun(); } }
@Test public void testMeter() throws Exception { String json = ((CodahaleMetrics) MetricsFactory.getInstance()).dumpJson(); MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.METER, "meter", ""); MetricsFactory.getInstance().markMeter("meter"); json = ((CodahaleMetrics) MetricsFactory.getInstance()).dumpJson(); MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.METER, "meter", "1"); MetricsFactory.getInstance().markMeter("meter"); json = ((CodahaleMetrics) MetricsFactory.getInstance()).dumpJson(); MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.METER, "meter", "2"); }
private Counter getCounter(String counter) { CodahaleMetrics metrics = (CodahaleMetrics) MetricsFactory.getInstance(); SortedMap<String, Counter> counters = metrics.getMetricRegistry().getCounters(); assertNotNull(counters); return counters.get(counter); }
@Test public void testCount() throws Exception { int runs = 5; for (int i = 0; i < runs; i++) { MetricsFactory.getInstance().incrementCounter("count1"); Counter counter = metricRegistry.getCounters().get("count1"); Assert.assertEquals(i + 1, counter.getCount()); } }
@Test public void testRatioIsCalculated() throws Exception { NumericVariable num = new NumericVariable(10); NumericVariable ord = new NumericVariable(5); MetricsFactory.getInstance().addRatio("rat", num, ord); String json = ((CodahaleMetrics) MetricsFactory.getInstance()).dumpJson(); MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.GAUGE, "rat", 2d); }
@Test public void testZeroRatio() throws Exception { NumericVariable num = new NumericVariable(10); NumericVariable ord = new NumericVariable(0); MetricsFactory.getInstance().addRatio("rat", num, ord); String json = ((CodahaleMetrics) MetricsFactory.getInstance()).dumpJson(); MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.GAUGE, "rat", "NaN"); }
@Test public void testRatioIsCalculatedNonExact() throws Exception { NumericVariable num = new NumericVariable(20); NumericVariable ord = new NumericVariable(3); MetricsFactory.getInstance().addRatio("rat", num, ord); String json = ((CodahaleMetrics) MetricsFactory.getInstance()).dumpJson(); MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.GAUGE, "rat", 6.6666d, 1e-4); }
@Test public void testEmptyRatio() throws Exception { NumericVariable num = new NumericVariable(null); NumericVariable ord = new NumericVariable(null); MetricsFactory.getInstance().addRatio("rat", num, ord); String json = ((CodahaleMetrics) MetricsFactory.getInstance()).dumpJson(); MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.GAUGE, "rat", "NaN"); }
@Test public void testScope() throws Exception { int runs = 5; for (int i = 0; i < runs; i++) { MetricsFactory.getInstance().startStoredScope("method1"); MetricsFactory.getInstance().endStoredScope("method1"); Timer timer = metricRegistry.getTimers().get("method1"); Assert.assertEquals(i + 1, timer.getCount()); } Timer timer = metricRegistry.getTimers().get("method1"); Assert.assertTrue(timer.getMeanRate() > 0); }
@Test public void testGauge() throws Exception { TestMetricsVariable testVar = new TestMetricsVariable(); testVar.setValue(20); MetricsFactory.getInstance().addGauge("gauge1", testVar); String json = ((CodahaleMetrics) MetricsFactory.getInstance()).dumpJson(); MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.GAUGE, "gauge1", testVar.getValue()); testVar.setValue(40); json = ((CodahaleMetrics) MetricsFactory.getInstance()).dumpJson(); MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.GAUGE, "gauge1", testVar.getValue()); }
@Before public void before() throws Exception { MetricsFactory.close(); HiveConf conf = new HiveConf(); conf.setVar(HiveConf.ConfVars.HIVE_METRICS_CLASS, LegacyMetrics.class.getCanonicalName()); MetricsFactory.init(conf); metrics = (LegacyMetrics) MetricsFactory.getInstance(); }
@Before public void before() throws Exception { HiveConf conf = new HiveConf(); conf.setVar(HiveConf.ConfVars.HIVE_METRICS_CLASS, CodahaleMetrics.class.getCanonicalName()); // disable json file writing conf.setVar(HiveConf.ConfVars.HIVE_METRICS_JSON_FILE_INTERVAL, "60000m"); MetricsFactory.init(conf); metricRegistry = ((CodahaleMetrics) MetricsFactory.getInstance()).getMetricRegistry(); }