.publishing(average) .fromMembers() .computingAverage() .defaultValueForUnreportedSensors(0) .build());
@Test public void testAveragingEnricherWhenNoAndNullSensorValues() { TestEntity producer1 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); entity.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(doubleSensor) .computingAverage() .fromHardcodedProducers(ImmutableList.of(producer1)) .build()); EntityAsserts.assertAttributeEqualsContinually(MutableMap.of("timeout", 50), entity, doubleSensor, null); producer1.sensors().set(intSensor, null); EntityAsserts.assertAttributeEqualsContinually(MutableMap.of("timeout", 50), entity, doubleSensor, null); }
@Test public void testAveragingEnricherWhenNoProducersDefaultsToNull() { entity.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(doubleSensor) .computingAverage() .fromChildren() .build()); EntityAsserts.assertAttributeEqualsContinually(MutableMap.of("timeout", 50), entity, doubleSensor, null); }
.computingAverage() .fromMembers() .publishing(MachineAttributes.AVERAGE_CPU_USAGE)
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override protected void initEnrichers() { super.initEnrichers(); propagateMasterAttribute(MySqlNode.HOSTNAME); propagateMasterAttribute(MySqlNode.ADDRESS); propagateMasterAttribute(MySqlNode.SUBNET_HOSTNAME); propagateMasterAttribute(MySqlNode.SUBNET_ADDRESS); propagateMasterAttribute(MySqlNode.MYSQL_PORT); propagateMasterAttribute(MySqlNode.DATASTORE_URL); enrichers().add(Enrichers.builder() .aggregating(MySqlNode.DATASTORE_URL) .publishing(SLAVE_DATASTORE_URL_LIST) .computing((Function<Collection<String>, List<String>>)(Function)Functions.identity()) .entityFilter(Predicates.not(MySqlClusterUtils.IS_MASTER)) .fromMembers() .build()); enrichers().add(Enrichers.builder() .aggregating(MySqlNode.QUERIES_PER_SECOND_FROM_MYSQL) .publishing(QUERIES_PER_SECOND_FROM_MYSQL_PER_NODE) .fromMembers() .computingAverage() .defaultValueForUnreportedSensors(0d) .build()); }
@Test public void testMultipleProducersAverage() { TestEntity producer1 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); TestEntity producer2 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); TestEntity producer3 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); entity.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(doubleSensor) .computingAverage() .fromHardcodedProducers(ImmutableList.of(producer1, producer2, producer3)) .build()); EntityAsserts.assertAttributeEqualsContinually(MutableMap.of("timeout", 50), entity, doubleSensor, null); producer1.sensors().set(intSensor, 3); EntityAsserts.assertAttributeEqualsEventually(entity, doubleSensor, 3d); producer2.sensors().set(intSensor, 1); EntityAsserts.assertAttributeEqualsEventually(entity, doubleSensor, 2d); producer3.sensors().set(intSensor, 5); EntityAsserts.assertAttributeEqualsEventually(entity, doubleSensor, 3d); producer2.sensors().set(intSensor, 4); EntityAsserts.assertAttributeEqualsEventually(entity, doubleSensor, 4d); }
@Test public void testMultipleProducersAverageDefaultingZero() { TestEntity producer1 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); TestEntity producer2 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); TestEntity producer3 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); entity.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(doubleSensor) .computingAverage() .fromHardcodedProducers(ImmutableList.of(producer1, producer2, producer3)) .defaultValueForUnreportedSensors(0) .valueToReportIfNoSensors(0) .build()); EntityAsserts.assertAttributeEqualsEventually(entity, doubleSensor, 0d); producer1.sensors().set(intSensor, 3); EntityAsserts.assertAttributeEqualsEventually(entity, doubleSensor, 1d); producer2.sensors().set(intSensor, 3); EntityAsserts.assertAttributeEqualsEventually(entity, doubleSensor, 2d); producer3.sensors().set(intSensor, 3); EntityAsserts.assertAttributeEqualsEventually(entity, doubleSensor, 3d); }
@Test public void testAveragingEnricherWhenDefaultValueForUnreportedSensors() { TestEntity producer1 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); entity.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(doubleSensor) .computingAverage() .fromHardcodedProducers(ImmutableList.of(producer1)) .defaultValueForUnreportedSensors(3) .valueToReportIfNoSensors(5) .build()); EntityAsserts.assertAttributeEqualsEventually(entity, doubleSensor, 3d); producer1.sensors().set(intSensor, null); EntityAsserts.assertAttributeEqualsContinually(MutableMap.of("timeout", 50), entity, doubleSensor, 3d); producer1.sensors().set(intSensor, 4); EntityAsserts.assertAttributeEqualsEventually(entity, doubleSensor, 4d); }
@Test public void testAveragingEnricherWhenNoSensors() { entity.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(doubleSensor) .computingAverage() .fromChildren() .defaultValueForUnreportedSensors(3) .valueToReportIfNoSensors(5) .build()); EntityAsserts.assertAttributeEqualsEventually(entity, doubleSensor, 5d); }