bridge = new PcpMmvWriter("test", IdentifierSourceSet.DEFAULT_SET); bridge = new PcpMmvWriter(new File(args[0]), IdentifierSourceSet.DEFAULT_SET); bridge.addMetric(MetricName.parse("sheep[baabaablack].bagsfull.count"), Semantics.COUNTER, ONE.multiply(1000), 3); bridge.addMetric(MetricName.parse("sheep[baabaablack].bagsfull.haveany"), Semantics.INSTANT, null, new AtomicBoolean(true)); bridge.addMetric(MetricName.parse("sheep[limpy].bagsfull.haveany"), Semantics.INSTANT, null, new AtomicBoolean(false)); bridge.addMetric(MetricName.parse("sheep[insomniac].jumps"), Semantics.COUNTER, ONE, 12345678901234L); bridge.addMetric(MetricName.parse("sheep[limpy].legs.available"), Semantics.DISCRETE, ONE, 0.75); bridge.addMetric(MetricName.parse("sheep[limpy].jumpitem"), Semantics.DISCRETE, null, "fence"); bridge.addMetric(MetricName.parse("sheep[insomniac].lastjumped"), Semantics.INSTANT, null, new GregorianCalendar(), new AbstractTypeHandler<GregorianCalendar>( MmvMetricType.I32, 4) { bridge.registerType(Date.class, new AbstractTypeHandler<Date>(MmvMetricType.I64, 8) { public void putBytes(ByteBuffer buffer, Date value) { buffer.putLong(value.getTime());
public void start() { PcpMmvWriter writer; writer = new PcpMmvWriter(name, IdentifierSourceSet.DEFAULT_SET); writer.setClusterIdentifier(MonitoringViewProperties.getCluster()); writer.setFlags(EnumSet.of(PcpMmvWriter.MmvFlag.MMV_FLAG_PROCESS)); DynamicMonitoringView view; view = new DynamicMonitoringView(registry, new PcpMonitorBridge(writer), MonitoringViewProperties.getStartup()); view.start(); }
@Test public void ensureSetPerMetricLockIsAllowedAfterResetIsCalled() throws IOException { pcpMmvWriter.start(); pcpMmvWriter.reset(); pcpMmvWriter.setPerMetricLock(true); }
@Test(expected = IllegalStateException.class) public void ensureSetPerMetricLockIsNotAllowedWhenWriterIsStarted() throws IOException { pcpMmvWriter.start(); pcpMmvWriter.setPerMetricLock(true); }
private void runBenchmark() throws InterruptedException { long begin = System.currentTimeMillis(); MonitorableRegistry monitorableRegistry = new MonitorableRegistry(); List<MonitoredCounter> counters = createCounters(numCounters, monitorableRegistry); final PcpMmvWriter mmvWriter = new PcpMmvWriter("parfait-microbenchmark-" + StandardMetricThroughPutBenchmark.class.getSimpleName() + ".mmv", IdentifierSourceSet.DEFAULT_SET); mmvWriter.setPerMetricLock(usePerMetricLock); mmvWriter.setClusterIdentifier(CLUSTER_IDENTIFIER); final PcpMonitorBridge pcpMonitorBridge = new PcpMonitorBridge(mmvWriter, MetricNameMapper.PASSTHROUGH_MAPPER, new MetricDescriptionTextSource(), new EmptyTextSource()); DynamicMonitoringView selfStartingMonitoringView = new DynamicMonitoringView(monitorableRegistry, pcpMonitorBridge, 2000); if (startPcp) { selfStartingMonitoringView.start(); } List<CounterIncrementer> counterIncrementers = executeBenchmark(numThreads, iterations, counters); if (startPcp) { selfStartingMonitoringView.stop(); } long timeTaken = System.currentTimeMillis() - begin; report(startPcp, counters, timeTaken, counterIncrementers); }
@BeforeClass public static void setUp() throws Exception { pcpClient = new PcpClient(); pcpMmvWriterV1 = new PcpMmvWriter("test1", DEFAULT_SET, MMV_VERSION1); pcpMmvWriterV2 = new PcpMmvWriter("test2", DEFAULT_SET, MMV_VERSION2); }
@Test @SuppressWarnings("unchecked") public void ensureUpdatesAreIgnoredAfterResetIsCalled() throws IOException { MetricName metricName = MetricName.parse(SOME_METRIC_NAME); TypeHandler<CustomType> customTypeTypeHandler = mock(TypeHandler.class); PcpMetricInfo pcpMetricInfo = mock(PcpMetricInfo.class); when(customTypeTypeHandler.getMetricType()).thenReturn(MmvMetricType.DOUBLE); when(metricInfoStore.byName(SOME_METRIC_NAME)).thenReturn(pcpMetricInfo); doReturn(customTypeTypeHandler).when(pcpMetricInfo).getTypeHandler(); when(byteBuffer.slice()).thenReturn(mock(ByteBuffer.class)); pcpMmvWriter.registerType(CustomType.class, customTypeTypeHandler); pcpMmvWriter.start(); pcpMmvWriter.reset(); Mockito.reset(customTypeTypeHandler); pcpMmvWriter.addMetric(metricName, Semantics.COUNTER, ONE, new CustomType()); pcpMmvWriter.updateMetric(metricName, new CustomType()); verify(customTypeTypeHandler, never()).putBytes(any(ByteBuffer.class), any(CustomType.class)); }
@Override public ScheduledReporter build(MetricRegistry metricRegistry) { MetricAdapterFactory metricAdapterFactory = new MetricAdapterFactoryImpl( new DefaultMetricDescriptorLookup(), new DefaultMetricNameTranslator(getReplacements())); MonitorableRegistry monitorableRegistry = MonitorableRegistry.getNamedInstance(getRegistryName()); PcpMmvWriter pcpMmvWriter = new PcpMmvWriter(getPcpName(), IdentifierSourceSet.DEFAULT_SET); pcpMmvWriter.setClusterIdentifier(getClusterIdentifier()); MonitoringView monitoringView = new PcpMonitorBridge(pcpMmvWriter); DynamicMonitoringView dynamicMonitoringView = new DynamicMonitoringView(monitorableRegistry, monitoringView, quietPeriod); return new ParfaitReporter(metricRegistry, monitorableRegistry, dynamicMonitoringView, metricAdapterFactory, getRateUnit(), getDurationUnit(), getFilter(), getPrefix()); } }
@Test public void bothMmvVersionsShouldSupportAddingAMetric() throws Exception { pcpMmvWriterV1.reset(); pcpMmvWriterV1.addMetric(MetricName.parse("v1.integer"), Semantics.COUNTER, ONE, 3); pcpMmvWriterV1.start(); pcpMmvWriterV2.reset(); pcpMmvWriterV2.addMetric(MetricName.parse("v2.integer"), Semantics.COUNTER, ONE, 3); pcpMmvWriterV2.start(); waitForReload(); assertMetric("mmv.v1.integer", is("3.000")); assertMetric("mmv.v2.integer", is("3.000")); }
@Test(expected = IllegalArgumentException.class) public void ensureThatClusterIdentifierIsRestrictedTo12BitsOnly() throws Exception { pcpMmvWriter.setClusterIdentifier(1<<13); }
@Test @SuppressWarnings("unchecked") public void shouldBuildAByteBufferOfTheCorrectLength() throws IOException { InstanceDomain instanceDomain = mock(InstanceDomain.class); Instance instance = mock(Instance.class); PcpMetricInfo pcpMetricInfo = mock(PcpMetricInfo.class); when(pcpMetricInfo.getTypeHandler()).thenReturn(mock(TypeHandler.class)); when(pcpMetricInfo.byteSize()).thenReturn(MOCK_PCP_METRIC_INFO_BYTE_SIZE); when(instanceDomain.getInstances()).thenReturn(singletonList(instance)); when(instanceDomain.byteSize()).thenReturn(MOCK_INSTANCE_DOMAIN_BYTE_SIZE); when(instance.byteSize()).thenReturn(MOCK_INSTANCE_BYTE_SIZE); when(metricInfoStore.byName(SOME_METRIC_NAME)).thenReturn(pcpMetricInfo); when(metricInfoStore.all()).thenReturn(singletonList(pcpMetricInfo)); when(instanceDomainStore.all()).thenReturn(singletonList(instanceDomain)); when(byteBuffer.slice()).thenReturn(mock(ByteBuffer.class)); pcpMmvWriter.addMetric(MetricName.parse(SOME_METRIC_NAME), Semantics.COUNTER, null, 1); pcpMmvWriter.setMetricHelpText(SOME_METRIC_NAME, "Short help", "Long help"); pcpMmvWriter.start(); verify(byteBufferFactory).build(EXPECTED_LENGTH); }
public PcpMmvWriter(ByteBufferFactory byteBufferFactory, IdentifierSourceSet identifierSources, MmvVersion mmvVersion) { this.byteBufferFactory = byteBufferFactory; this.metricInfoStore = mmvVersion.createMetricInfoStore(identifierSources, stringStore); this.instanceDomainStore = mmvVersion.createInstanceDomainStore(identifierSources, stringStore); this.mmvVersion = mmvVersion; this.metricNameValidator = mmvVersion.createMetricNameValidator(); registerType(String.class, MMV_STRING_HANDLER); }
@Test public void shouldCreateAMetricInfoStoreWhenConstructed() { MmvVersion mmvVersion = mock(MmvVersion.class); IdentifierSourceSet identifierSourceSet = mock(IdentifierSourceSet.class); new PcpMmvWriter(mock(ByteBufferFactory.class), identifierSourceSet, mmvVersion); verify(mmvVersion).createMetricInfoStore(eq(identifierSourceSet), any(PcpStringStore.class)); }
@Test public void mmvVersion2ShouldSupportMetricNamesOver63Characters() throws Exception { pcpMmvWriterV2.reset(); pcpMmvWriterV2.addMetric(MetricName.parse("v2.metric.that.is.longer.than.63.characters.v2.metric.that.is.longer.than.63.characters"), Semantics.COUNTER, ONE, 10); pcpMmvWriterV2.start(); waitForReload(); assertMetric("mmv.v2.metric.that.is.longer.than.63.characters.v2.metric.that.is.longer.than.63.characters", is("10.000")); }
@Test public void ensureValid12BitIdentifierIsAllowed(){ pcpMmvWriter.setClusterIdentifier(1); }
@Test public void shouldCreateAnInstanceDomainStoreWhenConstructed() { MmvVersion mmvVersion = mock(MmvVersion.class); IdentifierSourceSet identifierSourceSet = mock(IdentifierSourceSet.class); new PcpMmvWriter(mock(ByteBufferFactory.class), identifierSourceSet, mmvVersion); verify(mmvVersion).createInstanceDomainStore(eq(identifierSourceSet), any(PcpStringStore.class)); }
@Test public void mmvVersion2ShouldSupportInstanceNamesOver63Characters() throws Exception { pcpMmvWriterV2.reset(); pcpMmvWriterV2.addMetric(MetricName.parse("v2.integer[instance_name_over_63_characters_instance_name_over_63_characters_instance]"), Semantics.COUNTER, ONE, 11); pcpMmvWriterV2.start(); waitForReload(); assertMetric("mmv.v2.integer[instance_name_over_63_characters_instance_name_over_63_characters_instance]", is("11.000")); }
@Test(expected = IllegalArgumentException.class) public void ensureNegativeClustersAreTreatedWithAppropriateContempt() { pcpMmvWriter.setClusterIdentifier(-1); }
@Test public void shouldCreateAMetricNameValidatorWhenConstructed() { MmvVersion mmvVersion = mock(MmvVersion.class); new PcpMmvWriter(mock(ByteBufferFactory.class), mock(IdentifierSourceSet.class), mmvVersion); verify(mmvVersion).createMetricNameValidator(); }
@Test public void ensureBoundaryCaseOf12thBitIsOk(){ pcpMmvWriter.setClusterIdentifier(1<<11); }