@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = new PrintWriter(response.getOutputStream()); String format = request.getParameter("format"); Collection<MetricsContext> allContexts = ContextFactory.getFactory().getAllContexts(); if ("json".equals(format)) { // Uses Jetty's built-in JSON support to convert the map into JSON. out.print(new JSON().toJSON(makeMap(allContexts))); } else { printMap(out, makeMap(allContexts)); } out.close(); }
/** * Utility method to return the named context. * If the desired context cannot be created for any reason, the exception * is logged, and a null context is returned. */ public static MetricsContext getContext(String refName, String contextName) { MetricsContext metricsContext; try { metricsContext = ContextFactory.getFactory().getContext(refName, contextName); if (!metricsContext.isMonitoring()) { metricsContext.startMonitoring(); } } catch (Exception ex) { LOG.error("Unable to create metrics context " + contextName, ex); metricsContext = ContextFactory.getNullContext(contextName); } return metricsContext; }
/** * Utility method to return the named context. * If the desired context cannot be created for any reason, the exception * is logged, and a null context is returned. */ public static MetricsContext getContext(String refName, String contextName) { MetricsContext metricsContext; try { metricsContext = ContextFactory.getFactory().getContext(refName, contextName); if (!metricsContext.isMonitoring()) { metricsContext.startMonitoring(); } } catch (Exception ex) { LOG.error("Unable to create metrics context " + contextName, ex); metricsContext = ContextFactory.getNullContext(contextName); } return metricsContext; }
/** * Utility method to return the named context. * If the desired context cannot be created for any reason, the exception * is logged, and a null context is returned. */ public static MetricsContext getContext(String contextName) { MetricsContext metricsContext; try { metricsContext = ContextFactory.getFactory().getContext(contextName); if (!metricsContext.isMonitoring()) { metricsContext.startMonitoring(); } } catch (Exception ex) { LOG.error("Unable to create metrics context " + contextName, ex); metricsContext = ContextFactory.getNullContext(contextName); } return metricsContext; }
/** * Utility method to return the named context. * If the desired context cannot be created for any reason, the exception * is logged, and a null context is returned. */ public static MetricsContext getContext(String refName, String contextName) { MetricsContext metricsContext; try { metricsContext = ContextFactory.getFactory().getContext(refName, contextName); if (!metricsContext.isMonitoring()) { metricsContext.startMonitoring(); } } catch (Exception ex) { LOG.error("Unable to create metrics context " + contextName, ex); metricsContext = ContextFactory.getNullContext(contextName); } return metricsContext; }
/** * Utility method to return the named context. * If the desired context cannot be created for any reason, the exception * is logged, and a null context is returned. */ public static MetricsContext getContext(String refName, String contextName) { MetricsContext metricsContext; try { metricsContext = ContextFactory.getFactory().getContext(refName, contextName); if (!metricsContext.isMonitoring()) { metricsContext.startMonitoring(); } } catch (Exception ex) { LOG.error("Unable to create metrics context " + contextName, ex); metricsContext = ContextFactory.getNullContext(contextName); } return metricsContext; }
public MasterMetrics(final String name) { MetricsContext context = MetricsUtil.getContext("hbase"); metricsRecord = MetricsUtil.createRecord(context, "master"); metricsRecord.setTag("Master", name); context.registerUpdater(this); JvmMetrics.init("Master", name); HBaseInfo.init(); // expose the MBean for metrics masterStatistics = new MasterStatistics(this.registry); // get custom attributes try { Object m = ContextFactory.getFactory().getAttribute("hbase.extendedperiod"); if (m instanceof String) { this.extendedPeriod = Long.parseLong((String) m)*1000; } } catch (IOException ioe) { LOG.info("Couldn't load ContextFactory for Metrics config info"); } LOG.info("Initialized"); }
/** * Utility method to return the named context. * If the desired context cannot be created for any reason, the exception * is logged, and a null context is returned. */ public static MetricsContext getContext(String refName, String contextName) { MetricsContext metricsContext; try { metricsContext = ContextFactory.getFactory().getContext(refName, contextName); if (!metricsContext.isMonitoring()) { metricsContext.startMonitoring(); } } catch (Exception ex) { LOG.error("Unable to create metrics context " + contextName, ex); metricsContext = ContextFactory.getNullContext(contextName); } return metricsContext; }
@Test public void testCloseShouldCloseTheSocketWhichIsCreatedByInit() throws Exception { AbstractMetricsContext context=new GangliaContext(); context.init("gangliaContext", ContextFactory.getFactory()); GangliaContext gangliaContext =(GangliaContext) context; assertFalse("Socket already closed",gangliaContext.datagramSocket.isClosed()); context.close(); assertTrue("Socket not closed",gangliaContext.datagramSocket.isClosed()); } }
public Metrics(Conf conf) throws IOException { ContextFactory contextFactory = ContextFactory.getFactory(); for (Conf attr : conf.getChild("hadoopMetricsAttributes").getChildren("attribute")) { contextFactory.setAttribute(attr.getAttribute("name"), attr.getAttribute(("value"))); } boolean enableJvmMetrics = conf.getChild("enableJvmMetrics").getValueAsBoolean(); if (enableJvmMetrics) { JvmMetrics.init("lily", "aLilySession"); } } }
@Test public void testShouldCreateDatagramSocketByDefault() throws Exception { GangliaContext context = new GangliaContext(); context.init("gangliaContext", ContextFactory.getFactory()); assertFalse("Created MulticastSocket", context.datagramSocket instanceof MulticastSocket); }
@Test public void testShouldCreateDatagramSocketByDefault() throws Exception { GangliaContext context = new GangliaContext(); context.init("gangliaContext", ContextFactory.getFactory()); assertFalse("Created MulticastSocket", context.datagramSocket instanceof MulticastSocket); }
@Test public void testShouldCreateDatagramSocketIfMulticastIsDisabled() throws Exception { GangliaContext context = new GangliaContext(); ContextFactory factory = ContextFactory.getFactory(); factory.setAttribute("gangliaContext.multicast", "false"); context.init("gangliaContext", factory); assertFalse("Created MulticastSocket", context.datagramSocket instanceof MulticastSocket); }
@Test public void testShouldCreateDatagramSocketIfMulticastIsDisabled() throws Exception { GangliaContext context = new GangliaContext(); ContextFactory factory = ContextFactory.getFactory(); factory.setAttribute("gangliaContext.multicast", "false"); context.init("gangliaContext", factory); assertFalse("Created MulticastSocket", context.datagramSocket instanceof MulticastSocket); }
@Test public void testShouldSetMulticastSocketTtl() throws Exception { GangliaContext context = new GangliaContext(); ContextFactory factory = ContextFactory.getFactory(); factory.setAttribute("gangliaContext.multicast", "true"); factory.setAttribute("gangliaContext.multicast.ttl", "10"); context.init("gangliaContext", factory); MulticastSocket multicastSocket = (MulticastSocket) context.datagramSocket; assertEquals("Did not set TTL", multicastSocket.getTimeToLive(), 10); }
@Test public void testShouldCreateMulticastSocket() throws Exception { GangliaContext context = new GangliaContext(); ContextFactory factory = ContextFactory.getFactory(); factory.setAttribute("gangliaContext.multicast", "true"); context.init("gangliaContext", factory); assertTrue("Did not create MulticastSocket", context.datagramSocket instanceof MulticastSocket); MulticastSocket multicastSocket = (MulticastSocket) context.datagramSocket; assertEquals("Did not set default TTL", multicastSocket.getTimeToLive(), 1); }
@Test public void testShouldSetMulticastSocketTtl() throws Exception { GangliaContext context = new GangliaContext(); ContextFactory factory = ContextFactory.getFactory(); factory.setAttribute("gangliaContext.multicast", "true"); factory.setAttribute("gangliaContext.multicast.ttl", "10"); context.init("gangliaContext", factory); MulticastSocket multicastSocket = (MulticastSocket) context.datagramSocket; assertEquals("Did not set TTL", multicastSocket.getTimeToLive(), 10); }
@Test public void testShouldCreateMulticastSocket() throws Exception { GangliaContext context = new GangliaContext(); ContextFactory factory = ContextFactory.getFactory(); factory.setAttribute("gangliaContext.multicast", "true"); context.init("gangliaContext", factory); assertTrue("Did not create MulticastSocket", context.datagramSocket instanceof MulticastSocket); MulticastSocket multicastSocket = (MulticastSocket) context.datagramSocket; assertEquals("Did not set default TTL", multicastSocket.getTimeToLive(), 1); }
@Test public void testCloseShouldCloseTheSocketWhichIsCreatedByInit() throws Exception { AbstractMetricsContext context=new GangliaContext(); context.init("gangliaContext", ContextFactory.getFactory()); GangliaContext gangliaContext =(GangliaContext) context; assertFalse("Socket already closed",gangliaContext.datagramSocket.isClosed()); context.close(); assertTrue("Socket not closed",gangliaContext.datagramSocket.isClosed()); } }
@Test public void testCloseShouldCloseTheSocketWhichIsCreatedByInit() throws Exception { AbstractMetricsContext context=new GangliaContext(); context.init("gangliaContext", ContextFactory.getFactory()); GangliaContext gangliaContext =(GangliaContext) context; assertFalse("Socket already closed",gangliaContext.datagramSocket.isClosed()); context.close(); assertTrue("Socket not closed",gangliaContext.datagramSocket.isClosed()); } }