本文整理汇总了Java中monasca.common.model.metric.MetricDefinition类的典型用法代码示例。如果您正苦于以下问题:Java MetricDefinition类的具体用法?Java MetricDefinition怎么用?Java MetricDefinition使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MetricDefinition类属于monasca.common.model.metric包,在下文中一共展示了MetricDefinition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isSuperSet
import monasca.common.model.metric.MetricDefinition; //导入依赖的package包/类
private boolean isSuperSet(MetricDefinition toMatch, MetricDefinition match) {
if (!toMatch.name.equals(match.name)) {
return false;
}
if (match.dimensions == null || match.dimensions.isEmpty()) {
return true;
}
for (final Map.Entry<String, String> entry : toMatch.dimensions.entrySet()) {
final String value = match.dimensions.get(entry.getKey());
if (value != null) {
if (!value.equals(entry.getValue())) {
return false;
}
}
}
return true;
}
示例2: shouldParseExpressionWithoutType
import monasca.common.model.metric.MetricDefinition; //导入依赖的package包/类
public void shouldParseExpressionWithoutType() {
AlarmExpression expr = new AlarmExpression(
"avg(hpcs.compute{instance_id=5,metric_name=cpu,device=1}, 1) > 5 times 3 and avg(hpcs.compute{flavor_id=3,metric_name=mem}, 2) < 4 times 3");
List<AlarmSubExpression> alarms = expr.getSubExpressions();
AlarmSubExpression expected1 = new AlarmSubExpression(AggregateFunction.AVG,
new MetricDefinition("hpcs.compute", ImmutableMap.<String, String>builder()
.put("instance_id", "5")
.put("metric_name", "cpu")
.put("device", "1")
.build()), AlarmOperator.GT, 5, 1, 3);
AlarmSubExpression expected2 = new AlarmSubExpression(AggregateFunction.AVG,
new MetricDefinition("hpcs.compute", ImmutableMap.<String, String>builder()
.put("flavor_id", "3")
.put("metric_name", "mem")
.build()), AlarmOperator.LT, 4, 2, 3);
assertEquals(alarms.get(0), expected1);
assertEquals(alarms.get(1), expected2);
}
示例3: shouldFindById
import monasca.common.model.metric.MetricDefinition; //导入依赖的package包/类
public void shouldFindById() {
final Alarm newAlarm = new Alarm(alarmDef, AlarmState.OK);
assertNull(dao.findById(newAlarm.getId()));
dao.createAlarm(newAlarm);
assertEquals(dao.findById(newAlarm.getId()), newAlarm);
dao.addAlarmedMetric(newAlarm.getId(), newMetric);
newAlarm.addAlarmedMetric(newMetric);
assertEquals(dao.findById(newAlarm.getId()), newAlarm);
// Make sure it can handle MetricDefinition with no dimensions
final MetricDefinitionAndTenantId anotherMetric =
new MetricDefinitionAndTenantId(new MetricDefinition("cpu", new HashMap<String, String>()),
TENANT_ID);
dao.addAlarmedMetric(newAlarm.getId(), anotherMetric);
newAlarm.addAlarmedMetric(anotherMetric);
assertEquals(dao.findById(newAlarm.getId()), newAlarm);
}
示例4: checkComplexMetrics
import monasca.common.model.metric.MetricDefinition; //导入依赖的package包/类
public void checkComplexMetrics() {
final Alarm newAlarm = new Alarm(alarmDef, AlarmState.ALARM);
for (final String hostname : Arrays.asList("vivi", "eleanore")) {
for (final String metricName : Arrays.asList("cpu", "load")) {
final Map<String, String> dimensions = new HashMap<String, String>();
dimensions.put("first", "first_value");
dimensions.put("second", "second_value");
dimensions.put("hostname", hostname);
final MetricDefinition md = new MetricDefinition(metricName, dimensions);
newAlarm.addAlarmedMetric(new MetricDefinitionAndTenantId(md, TENANT_ID));
}
}
dao.createAlarm(newAlarm);
final Alarm found = dao.findById(newAlarm.getId());
// Have to check both ways because there was a bug in AlarmDAOImpl and it showed up if both
// ways were tested
assertTrue(newAlarm.equals(found));
assertTrue(found.equals(newAlarm));
}
示例5: shouldPersistDeterministic
import monasca.common.model.metric.MetricDefinition; //导入依赖的package包/类
public void shouldPersistDeterministic() {
final Alarm alarm1 = new Alarm(this.deterministicAlarmDef);
final MetricDefinition definition = this.deterministicAlarmDef
.getSubExpressions()
.get(0)
.getAlarmSubExpression()
.getMetricDefinition();
final MetricDefinitionAndTenantId mtid = new MetricDefinitionAndTenantId(
definition,
TENANT_ID
);
alarm1.addAlarmedMetric(mtid);
dao.createAlarm(alarm1);
final Alarm byId = dao.findById(alarm1.getId());
assertEquals(byId, alarm1);
assertEquals(1, byId.getDeterministicSubAlarms().size());
}
示例6: checkComplexMetrics
import monasca.common.model.metric.MetricDefinition; //导入依赖的package包/类
@Test(groups = "orm")
public void checkComplexMetrics() {
final Alarm newAlarm = new Alarm(alarmDef, AlarmState.ALARM);
for (final String hostname : Arrays.asList("vivi", "eleanore")) {
for (final String metricName : Arrays.asList("cpu", "load")) {
final Map<String, String> dimensions = Maps.newHashMap();
dimensions.put("first", "first_value");
dimensions.put("second", "second_value");
dimensions.put("hostname", hostname);
final MetricDefinition md = new MetricDefinition(metricName, dimensions);
newAlarm.addAlarmedMetric(new MetricDefinitionAndTenantId(md, TENANT_ID));
}
}
dao.createAlarm(newAlarm);
final Alarm found = dao.findById(newAlarm.getId());
// Have to check both ways because there was a bug in AlarmDAOImpl and it showed up if both
// ways were tested
assertTrue(newAlarm.equals(found));
assertTrue(found.equals(newAlarm));
}
示例7: createMatchingAlarms
import monasca.common.model.metric.MetricDefinition; //导入依赖的package包/类
private List<Alarm> createMatchingAlarms(List<AlarmDefinition> alarmDefinitions) {
final List<Alarm> alarms = new LinkedList<>();
for (final AlarmDefinition alarmDef : alarmDefinitions) {
final Alarm alarm = new Alarm(alarmDef, AlarmState.UNDETERMINED);
for (final AlarmSubExpression subExpr : alarmDef.getAlarmExpression().getSubExpressions()) {
// First do a MetricDefinition that is an exact match
final MetricDefinition metricDefinition = subExpr.getMetricDefinition();
alarm.addAlarmedMetric(new MetricDefinitionAndTenantId(metricDefinition, alarmDef
.getTenantId()));
// Now do a MetricDefinition with an extra dimension that should still match the
// SubExpression
final MetricDefinition inexactMetricDef = addExtraDimension(metricDefinition);
alarm.addAlarmedMetric(new MetricDefinitionAndTenantId(inexactMetricDef, alarmDef
.getTenantId()));
}
alarms.add(alarm);
}
return alarms;
}
示例8: testOldMetric
import monasca.common.model.metric.MetricDefinition; //导入依赖的package包/类
private void testOldMetric(final SubAlarm subAlarm, final MetricDefinition metricDef,
final AlarmState initialState, final double value, final AlarmState expectedState) {
long t1 = 500000;
bolt.setCurrentTime(t1);
subAlarm.setState(initialState);
sendSubAlarmCreated(metricDef, subAlarm);
verify(alarmDao, never()).updateSubAlarmState(eq(subAlarm.getId()), (AlarmState) any());
// Even though this measurement is way outside the window, make sure it gets processed
// anyways
bolt.execute(createMetricTuple(metricDef, new Metric(metricDef, 1000, value, null)));
assertEquals(subAlarm.getState(), expectedState);
if (initialState != expectedState) {
verify(collector, times(1)).emit(new Values(subAlarm.getAlarmId(), subAlarm));
verify(alarmDao, times(1)).updateSubAlarmState(subAlarm.getId(), expectedState);
}
}
示例9: sendAlarmDefinitionDeleted
import monasca.common.model.metric.MetricDefinition; //导入依赖的package包/类
private void sendAlarmDefinitionDeleted(final AlarmDefinition alarmDefinition) {
final Map<String, MetricDefinition> subAlarmMetricDefinitions = new HashMap<>();
for (final AlarmSubExpression subExpr : alarmDefinition.getAlarmExpression().getSubExpressions()) {
subAlarmMetricDefinitions.put(getNextId(), subExpr.getMetricDefinition());
}
// Delete the Alarm Definition
final AlarmDefinitionDeletedEvent event =
new AlarmDefinitionDeletedEvent(alarmDefinition.getId(), subAlarmMetricDefinitions);
final MkTupleParam tupleParam = new MkTupleParam();
tupleParam.setFields(EventProcessingBolt.ALARM_DEFINITION_EVENT_FIELDS);
tupleParam.setStream(EventProcessingBolt.ALARM_DEFINITION_EVENT_STREAM_ID);
final Tuple tuple =
Testing.testTuple(Arrays.asList(EventProcessingBolt.DELETED, event), tupleParam);
bolt.execute(tuple);
}
示例10: shouldThrowOnEvaluateInvalidSubExpressions
import monasca.common.model.metric.MetricDefinition; //导入依赖的package包/类
@Test(expectedExceptions = IllegalArgumentException.class)
public void shouldThrowOnEvaluateInvalidSubExpressions() {
AlarmExpression expr = new AlarmExpression(
"avg(hpcs.compute{instance_id=5,metric_name=cpu,device=2}, 1) > 5 times 3 and avg(hpcs.compute{flavor_id=3,metric_name=mem}, 2) < 4 times 3");
expr.evaluate(ImmutableMap.<AlarmSubExpression, Boolean>builder()
.put(
new AlarmSubExpression(AggregateFunction.AVG,
new MetricDefinition("hpcs.compute",
ImmutableMap
.<String, String>builder()
.put("flavor_id", "3")
.put("metric_name",
"mem")
.build()),
AlarmOperator.LT, 4, 2, 3), true)
.build());
}
示例11: testDimensions
import monasca.common.model.metric.MetricDefinition; //导入依赖的package包/类
/**
* This test is here because this case happened in the Threshold Engine. The AlarmExpression
* resulted in a MetricDefinition with null dimensions and SubAlarm had empty dimensions and that
* didn't match causing an IllegalArgumentException. The AlarmSubExpressionListener has been
* changed to always generate empty dimensions and not null. This test will verify that logic
* is still working.
*/
public void testDimensions() {
final AlarmExpression expression = AlarmExpression.of("max(cpu_system_perc) > 1");
final MetricDefinition metricDefinition =
new MetricDefinition("cpu_system_perc", new HashMap<String, String>());
final AlarmSubExpression ase =
new AlarmSubExpression(AggregateFunction.MAX, metricDefinition, AlarmOperator.GT, 1, 60, 1);
final SubAlarm subAlarm = new SubAlarm("123", "456", new SubExpression(UUID.randomUUID().toString(), ase));
final Map<AlarmSubExpression, Boolean> subExpressionValues =
new HashMap<>();
subExpressionValues.put(subAlarm.getExpression(), true);
assertEquals(expression.getSubExpressions().get(0).getMetricDefinition().hashCode(),
metricDefinition.hashCode());
// Handle ALARM state
assertTrue(expression.evaluate(subExpressionValues));
}
示例12: findSubAlarmMetricDefinitions
import monasca.common.model.metric.MetricDefinition; //导入依赖的package包/类
@Override
public Map<String, MetricDefinition> findSubAlarmMetricDefinitions(String alarmDefId) {
try (Handle h = db.open()) {
List<Map<String, Object>> rows =
h.createQuery(SUB_ALARM_SQL).bind("alarmDefId", alarmDefId).list();
Map<String, MetricDefinition> subAlarmMetricDefs = new HashMap<>();
for (Map<String, Object> row : rows) {
String id = (String) row.get("id");
String metricName = (String) row.get("metric_name");
Map<String, String> dimensions =
DimensionQueries.dimensionsFor((String) row.get("dimensions"));
subAlarmMetricDefs.put(id, new MetricDefinition(metricName, dimensions));
}
return subAlarmMetricDefs;
}
}
示例13: createSubExpressions
import monasca.common.model.metric.MetricDefinition; //导入依赖的package包/类
private void createSubExpressions(Handle handle, String id,
Map<String, AlarmSubExpression> alarmSubExpressions) {
if (alarmSubExpressions != null) {
for (Map.Entry<String, AlarmSubExpression> subEntry : alarmSubExpressions.entrySet()) {
String subAlarmId = subEntry.getKey();
AlarmSubExpression subExpr = subEntry.getValue();
MetricDefinition metricDef = subExpr.getMetricDefinition();
// Persist sub-alarm
handle.insert(CREATE_SUB_EXPRESSION_SQL, subAlarmId, id, subExpr.getFunction().name(),
metricDef.name, subExpr.getOperator().name(), subExpr.getThreshold(),
subExpr.getPeriod(), subExpr.getPeriods(), subExpr.isDeterministic());
// Persist sub-alarm dimensions
if (metricDef.dimensions != null && !metricDef.dimensions.isEmpty())
for (Map.Entry<String, String> dimEntry : metricDef.dimensions.entrySet())
handle.insert("insert into sub_alarm_definition_dimension values (?, ?, ?)", subAlarmId,
dimEntry.getKey(), dimEntry.getValue());
}
}
}
示例14: shouldParseDeterministicExpression
import monasca.common.model.metric.MetricDefinition; //导入依赖的package包/类
public void shouldParseDeterministicExpression() {
final Map<String, String> dimensions = Maps.newHashMap();
final ArrayList<AlarmExpression> expressions = Lists.newArrayList(
new AlarmExpression("count(log.error{},deterministic,20) > 5")
);
final MetricDefinition metricDefinition = new MetricDefinition("log.error", dimensions);
final AlarmSubExpression logErrorExpr = new AlarmSubExpression(
AggregateFunction.COUNT,
metricDefinition,
AlarmOperator.GT,
5,
20,
1,
true // each expression is deterministic
);
for (final AlarmExpression expr : expressions) {
final List<AlarmSubExpression> subExpressions = expr.getSubExpressions();
assertTrue(expr.isDeterministic()); // each expression is deterministic
assertEquals(1, subExpressions.size());
assertEquals(subExpressions.get(0), logErrorExpr);
}
}
示例15: shouldFindSubAlarmMetricDefinitions
import monasca.common.model.metric.MetricDefinition; //导入依赖的package包/类
@Test(groups = "database")
public void shouldFindSubAlarmMetricDefinitions() {
// This test won't work without the real mysql database so use mini-mon.
// Warning, this will truncate your mini-mon database
db = new DBI("jdbc:mysql://192.168.10.4/mon", "monapi", "password");
handle = db.open();
repo = new AlarmDefinitionMySqlRepoImpl(db, new PersistUtils());
beforeMethod();
assertEquals(
repo.findSubAlarmMetricDefinitions("123").get("111"),
new MetricDefinition("hpcs.compute", ImmutableMap.<String, String>builder()
.put("flavor_id", "777").put("image_id", "888").put("metric_name", "cpu")
.put("device", "1").build()));
assertEquals(
repo.findSubAlarmMetricDefinitions("234").get("222"),
new MetricDefinition("hpcs.compute", ImmutableMap.<String, String>builder()
.put("flavor_id", "777").put("image_id", "888").put("metric_name", "mem").build()));
assertTrue(repo.findSubAlarmMetricDefinitions("asdfasdf").isEmpty());
}