private static void registerMetrics(Metrics metrics, final QueryResultsCache cache) { MetricsVariable<Long> maxCacheSize = new MetricsVariable<Long>() { @Override public Long getValue() { return cache.maxCacheSize; } }; MetricsVariable<Long> curCacheSize = new MetricsVariable<Long>() { @Override public Long getValue() { return cache.cacheSize; } }; metrics.addGauge(MetricsConstant.QC_MAX_SIZE, maxCacheSize); metrics.addGauge(MetricsConstant.QC_CURRENT_SIZE, curCacheSize); }
private void registerOpenSesssionMetrics(Metrics metrics) { MetricsVariable<Integer> openSessionCnt = new MetricsVariable<Integer>() { @Override public Integer getValue() { return getSessions().size(); } }; MetricsVariable<Integer> openSessionTime = new MetricsVariable<Integer>() { @Override public Integer getValue() { long sum = 0; long currentTime = System.currentTimeMillis(); for (HiveSession s : getSessions()) { sum += currentTime - s.getCreationTime(); } // in case of an overflow return -1 return (int) sum != sum ? -1 : (int) sum; } }; metrics.addGauge(MetricsConstant.HS2_OPEN_SESSIONS, openSessionCnt); metrics.addRatio(MetricsConstant.HS2_AVG_OPEN_SESSION_TIME, openSessionTime, openSessionCnt); }
private void registerActiveSesssionMetrics(Metrics metrics) { MetricsVariable<Integer> activeSessionCnt = new MetricsVariable<Integer>() { @Override public Integer getValue() { Iterable<HiveSession> filtered = Iterables.filter(getSessions(), new Predicate<HiveSession>() { @Override public boolean apply(HiveSession hiveSession) { return hiveSession.getNoOperationTime() == 0L; } }); return Iterables.size(filtered); } }; MetricsVariable<Integer> activeSessionTime = new MetricsVariable<Integer>() { @Override public Integer getValue() { long sum = 0; long currentTime = System.currentTimeMillis(); for (HiveSession s : getSessions()) { if (s.getNoOperationTime() == 0L) { sum += currentTime - s.getLastAccessTime(); } } // in case of an overflow return -1 return (int) sum != sum ? -1 : (int) sum; } }; metrics.addGauge(MetricsConstant.HS2_ACTIVE_SESSIONS, activeSessionCnt); metrics.addRatio(MetricsConstant.HS2_AVG_ACTIVE_SESSION_TIME, activeSessionTime, activeSessionCnt); }
String name = "WM_" + poolName + "_" + e.getKey(); codahaleNames.add(name); chMetrics.addGauge(name, var);
@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()); }
private void registerOpenSesssionMetrics(Metrics metrics) { MetricsVariable<Integer> openSessionCnt = new MetricsVariable<Integer>() { @Override public Integer getValue() { return getSessions().size(); } }; MetricsVariable<Integer> openSessionTime = new MetricsVariable<Integer>() { @Override public Integer getValue() { long sum = 0; long currentTime = System.currentTimeMillis(); for (HiveSession s : getSessions()) { sum += currentTime - s.getCreationTime(); } // in case of an overflow return -1 return (int) sum != sum ? -1 : (int) sum; } }; metrics.addGauge(MetricsConstant.HS2_OPEN_SESSIONS, openSessionCnt); metrics.addRatio(MetricsConstant.HS2_AVG_OPEN_SESSION_TIME, openSessionTime, openSessionCnt); }
private void registerActiveSesssionMetrics(Metrics metrics) { MetricsVariable<Integer> activeSessionCnt = new MetricsVariable<Integer>() { @Override public Integer getValue() { Iterable<HiveSession> filtered = Iterables.filter(getSessions(), new Predicate<HiveSession>() { @Override public boolean apply(HiveSession hiveSession) { return hiveSession.getNoOperationTime() == 0L; } }); return Iterables.size(filtered); } }; MetricsVariable<Integer> activeSessionTime = new MetricsVariable<Integer>() { @Override public Integer getValue() { long sum = 0; long currentTime = System.currentTimeMillis(); for (HiveSession s : getSessions()) { if (s.getNoOperationTime() == 0L) { sum += currentTime - s.getLastAccessTime(); } } // in case of an overflow return -1 return (int) sum != sum ? -1 : (int) sum; } }; metrics.addGauge(MetricsConstant.HS2_ACTIVE_SESSIONS, activeSessionCnt); metrics.addRatio(MetricsConstant.HS2_AVG_ACTIVE_SESSION_TIME, activeSessionTime, activeSessionCnt); }