@Override protected MetricsTag newValue(MetricsInfo info, String value) { return new MetricsTag(info, value); } };
/** * Get a metrics tag * * @param info of the tag * @param value of the tag * @return an interned metrics tag */ public static MetricsTag tag(MetricsInfo info, String value) { Map<String, MetricsTag> map = tagCache.getUnchecked(info); MetricsTag tag = map.get(value); if (tag == null) { tag = new MetricsTag(info, value); map.put(value, tag); } return tag; }
@Override protected MetricsTag newValue(MetricsInfo info, String value) { return new MetricsTag(info, value); } };
@Override protected MetricsTag newValue(MetricsInfo info, String value) { return new MetricsTag(info, value); } };
@Override protected MetricsTag newValue(MetricsInfo info, String value) { return new MetricsTag(info, value); } };
@Override protected MetricsTag newValue(MetricsInfo info, String value) { return new MetricsTag(info, value); } };
/** * Get a metrics tag * * @param info of the tag * @param value of the tag * @return an interned metrics tag */ public static MetricsTag tag(MetricsInfo info, String value) { Map<String, MetricsTag> map = tagCache.getUnchecked(info); MetricsTag tag = map.get(value); if (tag == null) { tag = new MetricsTag(info, value); map.put(value, tag); } return tag; }
/** * Get a metrics tag * * @param info of the tag * @param value of the tag * @return an interned metrics tag */ public static MetricsTag tag(MetricsInfo info, String value) { Map<String, MetricsTag> map = tagCache.getUnchecked(info); MetricsTag tag = map.get(value); if (tag == null) { tag = new MetricsTag(info, value); map.put(value, tag); } return tag; }
.addGauge(Interns.info("Remaining", "Total bytes of free storage"), beanClass.getRemaining()) .add(new MetricsTag(Interns.info("StorageInfo", "Storage ID"), beanClass.getStorageInfo())) .addGauge(Interns.info("NumFailedVolumes", "Number of failed Volumes" +
/** * Add a tag to the metrics * @param name of the tag * @param description of the tag * @param value of the tag * @param override existing tag if true * @return the registry (for keep adding tags) */ public DynamicMetricsRegistry tag(String name, String description, String value, boolean override) { MetricsTag tag = new MetricsTag(name, description, value); if (!override) { MetricsTag existing = tagsMap.putIfAbsent(name, tag); if (existing != null) { throw new MetricsException("Tag " + name + " already exists!"); } return this; } tagsMap.put(name, tag); return this; }
private MetricsTag makeTag(String name, String value) { return new MetricsTag(info(name, ""), value); }
private MetricsTag makeTag(String name, String value) { return new MetricsTag(info(name, ""), value); }
tags.add(new MetricsTag(MsInfo.Context, "all")); tags.add(new MetricsTag(MsInfo.NumActiveSources, "foo")); tags.add(new MetricsTag(MsInfo.NumActiveSinks, "bar")); tags.add(new MetricsTag(MsInfo.NumAllSinks, "haa")); tags.add(new MetricsTag(MsInfo.Hostname, "host")); Set<AbstractMetric> metrics = new HashSet<AbstractMetric>(); MetricsRecord record = new MetricsRecordImpl(MsInfo.Context, (long) 1, tags, metrics); assertEquals(".NumActiveSources=foo.NumActiveSinks=bar.NumAllSinks=haa", sb.toString()); tags.set(0, new MetricsTag(MsInfo.Context, "some")); sb = new StringBuilder(); sink.appendPrefix(record, sb); assertEquals(".NumActiveSources=foo.NumActiveSinks=bar", sb.toString()); tags.set(0, new MetricsTag(MsInfo.Context, "none")); sb = new StringBuilder(); sink.appendPrefix(record, sb); assertEquals("", sb.toString()); tags.set(0, new MetricsTag(MsInfo.Context, "nada")); sb = new StringBuilder(); sink.appendPrefix(record, sb);
tags.add(new MetricsTag(MsInfo.Context, "all")); tags.add(new MetricsTag(MsInfo.NumActiveSources, "foo")); tags.add(new MetricsTag(MsInfo.NumActiveSinks, "bar")); tags.add(new MetricsTag(MsInfo.NumAllSinks, "haa")); tags.add(new MetricsTag(MsInfo.Hostname, "host")); Set<AbstractMetric> metrics = new HashSet<AbstractMetric>(); MetricsRecord record = new MetricsRecordImpl(MsInfo.Context, (long) 1, tags, metrics); assertEquals(".NumActiveSources=foo.NumActiveSinks=bar.NumAllSinks=haa", sb.toString()); tags.set(0, new MetricsTag(MsInfo.Context, "some")); sb = new StringBuilder(); sink.appendPrefix(record, sb); assertEquals(".NumActiveSources=foo.NumActiveSinks=bar", sb.toString()); tags.set(0, new MetricsTag(MsInfo.Context, "none")); sb = new StringBuilder(); sink.appendPrefix(record, sb); assertEquals("", sb.toString()); tags.set(0, new MetricsTag(MsInfo.Context, "nada")); sb = new StringBuilder(); sink.appendPrefix(record, sb);
@Test public void testPutMetrics() { GraphiteSink sink = new GraphiteSink(); List<MetricsTag> tags = new ArrayList<MetricsTag>(); tags.add(new MetricsTag(MsInfo.Context, "all")); tags.add(new MetricsTag(MsInfo.Hostname, "host")); Set<AbstractMetric> metrics = new HashSet<AbstractMetric>(); metrics.add(makeMetric("foo1", 1.25)); metrics.add(makeMetric("foo2", 2.25)); MetricsRecord record = new MetricsRecordImpl(MsInfo.Context, (long) 10000, tags, metrics); ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class); final GraphiteSink.Graphite mockGraphite = makeGraphite(); Whitebox.setInternalState(sink, "graphite", mockGraphite); sink.putMetrics(record); try { verify(mockGraphite).write(argument.capture()); } catch (IOException e) { e.printStackTrace(); } String result = argument.getValue(); assertEquals(true, result.equals("null.all.Context.Context=all.Hostname=host.foo1 1.25 10\n" + "null.all.Context.Context=all.Hostname=host.foo2 2.25 10\n") || result.equals("null.all.Context.Context=all.Hostname=host.foo2 2.25 10\n" + "null.all.Context.Context=all.Hostname=host.foo1 1.25 10\n")); }
@Test public void testPutMetrics2() { GraphiteSink sink = new GraphiteSink(); List<MetricsTag> tags = new ArrayList<MetricsTag>(); tags.add(new MetricsTag(MsInfo.Context, "all")); tags.add(new MetricsTag(MsInfo.Hostname, null)); Set<AbstractMetric> metrics = new HashSet<AbstractMetric>(); metrics.add(makeMetric("foo1", 1)); metrics.add(makeMetric("foo2", 2)); MetricsRecord record = new MetricsRecordImpl(MsInfo.Context, (long) 10000, tags, metrics); ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class); final GraphiteSink.Graphite mockGraphite = makeGraphite(); Whitebox.setInternalState(sink, "graphite", mockGraphite); sink.putMetrics(record); try { verify(mockGraphite).write(argument.capture()); } catch (IOException e) { e.printStackTrace(); } String result = argument.getValue(); assertEquals(true, result.equals("null.all.Context.Context=all.foo1 1 10\n" + "null.all.Context.Context=all.foo2 2 10\n") || result.equals("null.all.Context.Context=all.foo2 2 10\n" + "null.all.Context.Context=all.foo1 1 10\n")); }
@Test public void testPutMetrics() { GraphiteSink sink = new GraphiteSink(); List<MetricsTag> tags = new ArrayList<MetricsTag>(); tags.add(new MetricsTag(MsInfo.Context, "all")); tags.add(new MetricsTag(MsInfo.Hostname, "host")); Set<AbstractMetric> metrics = new HashSet<AbstractMetric>(); metrics.add(makeMetric("foo1", 1.25)); metrics.add(makeMetric("foo2", 2.25)); MetricsRecord record = new MetricsRecordImpl(MsInfo.Context, (long) 10000, tags, metrics); ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class); final GraphiteSink.Graphite mockGraphite = makeGraphite(); Whitebox.setInternalState(sink, "graphite", mockGraphite); sink.putMetrics(record); try { verify(mockGraphite).write(argument.capture()); } catch (IOException e) { e.printStackTrace(); } String result = argument.getValue(); assertEquals(true, result.equals("null.all.Context.Context=all.Hostname=host.foo1 1.25 10\n" + "null.all.Context.Context=all.Hostname=host.foo2 2.25 10\n") || result.equals("null.all.Context.Context=all.Hostname=host.foo2 2.25 10\n" + "null.all.Context.Context=all.Hostname=host.foo1 1.25 10\n")); }
@Test public void testPutMetrics2() { GraphiteSink sink = new GraphiteSink(); List<MetricsTag> tags = new ArrayList<MetricsTag>(); tags.add(new MetricsTag(MsInfo.Context, "all")); tags.add(new MetricsTag(MsInfo.Hostname, null)); Set<AbstractMetric> metrics = new HashSet<AbstractMetric>(); metrics.add(makeMetric("foo1", 1)); metrics.add(makeMetric("foo2", 2)); MetricsRecord record = new MetricsRecordImpl(MsInfo.Context, (long) 10000, tags, metrics); ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class); final GraphiteSink.Graphite mockGraphite = makeGraphite(); Whitebox.setInternalState(sink, "graphite", mockGraphite); sink.putMetrics(record); try { verify(mockGraphite).write(argument.capture()); } catch (IOException e) { e.printStackTrace(); } String result = argument.getValue(); assertEquals(true, result.equals("null.all.Context.Context=all.foo1 1 10\n" + "null.all.Context.Context=all.foo2 2 10\n") || result.equals("null.all.Context.Context=all.foo2 2 10\n" + "null.all.Context.Context=all.foo1 1 10\n")); }
@Test public void testFailureAndPutMetrics() throws IOException { GraphiteSink sink = new GraphiteSink(); List<MetricsTag> tags = new ArrayList<MetricsTag>(); tags.add(new MetricsTag(MsInfo.Context, "all")); tags.add(new MetricsTag(MsInfo.Hostname, "host")); Set<AbstractMetric> metrics = new HashSet<AbstractMetric>(); metrics.add(makeMetric("foo1", 1.25)); metrics.add(makeMetric("foo2", 2.25)); MetricsRecord record = new MetricsRecordImpl(MsInfo.Context, (long) 10000, tags, metrics); final GraphiteSink.Graphite mockGraphite = makeGraphite(); Whitebox.setInternalState(sink, "graphite", mockGraphite); // throw exception when first try doThrow(new IOException("IO exception")).when(mockGraphite).write(anyString()); sink.putMetrics(record); verify(mockGraphite).write(anyString()); verify(mockGraphite).close(); // reset mock and try again reset(mockGraphite); when(mockGraphite.isConnected()).thenReturn(false); ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class); sink.putMetrics(record); verify(mockGraphite).write(argument.capture()); String result = argument.getValue(); assertEquals(true, result.equals("null.all.Context.Context=all.Hostname=host.foo1 1.25 10\n" + "null.all.Context.Context=all.Hostname=host.foo2 2.25 10\n") || result.equals("null.all.Context.Context=all.Hostname=host.foo2 2.25 10\n" + "null.all.Context.Context=all.Hostname=host.foo1 1.25 10\n")); }
@Test public void testFailureAndPutMetrics() throws IOException { GraphiteSink sink = new GraphiteSink(); List<MetricsTag> tags = new ArrayList<MetricsTag>(); tags.add(new MetricsTag(MsInfo.Context, "all")); tags.add(new MetricsTag(MsInfo.Hostname, "host")); Set<AbstractMetric> metrics = new HashSet<AbstractMetric>(); metrics.add(makeMetric("foo1", 1.25)); metrics.add(makeMetric("foo2", 2.25)); MetricsRecord record = new MetricsRecordImpl(MsInfo.Context, (long) 10000, tags, metrics); final GraphiteSink.Graphite mockGraphite = makeGraphite(); Whitebox.setInternalState(sink, "graphite", mockGraphite); // throw exception when first try doThrow(new IOException("IO exception")).when(mockGraphite).write(anyString()); sink.putMetrics(record); verify(mockGraphite).write(anyString()); verify(mockGraphite).close(); // reset mock and try again reset(mockGraphite); when(mockGraphite.isConnected()).thenReturn(false); ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class); sink.putMetrics(record); verify(mockGraphite).write(argument.capture()); String result = argument.getValue(); assertEquals(true, result.equals("null.all.Context.Context=all.Hostname=host.foo1 1.25 10\n" + "null.all.Context.Context=all.Hostname=host.foo2 2.25 10\n") || result.equals("null.all.Context.Context=all.Hostname=host.foo2 2.25 10\n" + "null.all.Context.Context=all.Hostname=host.foo1 1.25 10\n")); }