public static MeasurementDefinition getMeasurementDefinition(ResourceType type, String metricName) { for (MeasurementDefinition metricDefinition : type.getMetricDefinitions()) { if (metricDefinition.getName().equals(metricName)) { return metricDefinition; } } return null; }
/** * Returns the set of MeasurementDefinitions defined by the given Resource type, which are accepted by the specified * filter. If the filter is null, all of the type's MeasurementDefinitions will be returned. * * @param type the Resource type * @param filter the filter; may be null * * @return the set of MeasurementDefinition defined by the given Resource type, which are accepted by the specified * filter, or, if the filter is null, all of the type's MeasurementDefinitions */ public static Set<MeasurementDefinition> getMeasurementDefinitions(ResourceType type, MeasurementDefinitionFilter filter) { if (filter == null) { return type.getMetricDefinitions(); } Set<MeasurementDefinition> acceptedMetricDefs = new LinkedHashSet<MeasurementDefinition>(); for (MeasurementDefinition metricDef : type.getMetricDefinitions()) { if (filter.accept(metricDef)) { acceptedMetricDefs.add(metricDef); } } return acceptedMetricDefs; }
private Integer findScheduleId(int resourceId, String metric) { CacheKey key = new CacheKey("schedulesForResource",resourceId); @SuppressWarnings("unchecked") Map<String,Integer> schedulesForResource = (Map<String, Integer>) cache.get(key); if (schedulesForResource!=null && schedulesForResource.containsKey(metric)) { return schedulesForResource.get(metric); } else { Resource res = fetchResource(resourceId); ResourceType resourceType = res.getResourceType(); int[] definitionIds = new int[resourceType.getMetricDefinitions().size()]; int i = 0; for (MeasurementDefinition def : resourceType.getMetricDefinitions()) { definitionIds[i]=def.getId(); i++; } List<MeasurementSchedule> schedules = scheduleManager.findSchedulesByResourceIdAndDefinitionIds(caller,resourceId,definitionIds); schedulesForResource = new HashMap<String, Integer>(schedules.size()); for (MeasurementSchedule schedule : schedules) { schedulesForResource.put(schedule.getDefinition().getName(),schedule.getId()); } cache.put(key,schedulesForResource); return schedulesForResource.get(metric); } }
Set<MeasurementDefinition> defs = rt.getMetricDefinitions(); if (defs == null || defs.isEmpty()) { System.out.println("Resource has no metrics");
if (resourceType.getMetricDefinitions() != null) { for (MeasurementDefinition def : resourceType.getMetricDefinitions()) { exportWriter.printf("%s <metric>%s</metric>\n", indent, def.getName());
if (resourceType.getMetricDefinitions().isEmpty()) return Collections.emptySet();
private void createSchedules(Resource resource) { ResourceType rt = resource.getResourceType(); Set<MeasurementDefinition> definitions = rt.getMetricDefinitions (); for (MeasurementDefinition definition : definitions) { MeasurementSchedule schedule = new MeasurementSchedule(definition,resource); schedule.setEnabled(definition.isDefaultOn()); schedule.setInterval(definition.getDefaultInterval()); entityManager.persist(schedule); } }
Set<MeasurementDefinition> defs = type.getMetricDefinitions();
@GZIP @GET @Path("data/group/{groupId}") @ApiOperation("Retrieve a list of high/low/average/data aggregates for the group") @ApiError(code = 404, reason = "There is no group with the passed id") public List<MetricDefinitionAggregate> getAggregatesForGroup( @ApiParam("Id of the group to query") @PathParam("groupId") int groupId, @ApiParam(value = "Start time since epoch.", defaultValue="End time - 8h") @QueryParam("startTime") long startTime, @ApiParam(value = "End time since epoch.", defaultValue = "Now") @QueryParam("endTime") long endTime) { long now = System.currentTimeMillis(); if (endTime==0) endTime = now; if (startTime==0) { startTime = endTime - EIGHT_HOURS; } ResourceGroup group = fetchGroup(groupId, true); Set<MeasurementDefinition> definitions = group.getResourceType().getMetricDefinitions(); List<MetricDefinitionAggregate> ret = new ArrayList<MetricDefinitionAggregate>(definitions.size()); for (MeasurementDefinition def : definitions) { if (def.getDataType()==DataType.MEASUREMENT) { MeasurementAggregate aggregate = dataManager.getAggregate(caller, groupId, def.getId(), startTime, endTime); MetricDefinitionAggregate res = new MetricDefinitionAggregate(def.getId(), aggregate.getMin(),aggregate.getAvg(),aggregate.getMax()); ret.add(res); } } return ret; }
Set<MeasurementDefinition> existingDefinitions = existingType.getMetricDefinitions(); if (LOG.isDebugEnabled()) { LOG.debug(existingType + " currently does not define any metric definitions. " + "New metric definitions to be added: " + newType.getMetricDefinitions()); for (MeasurementDefinition newDefinition : newType.getMetricDefinitions()) { if (newDefinition.getDefaultInterval() < MeasurementSchedule.MINIMUM_INTERVAL) { newDefinition.setDefaultInterval(MeasurementSchedule.MINIMUM_INTERVAL); for (MeasurementDefinition newDefinition : newType.getMetricDefinitions()) { boolean found = false; for (MeasurementDefinition existingDefinition : existingDefinitions) { if (!newType.getMetricDefinitions().contains(existingDefinition)) { definitionsToDelete.add(existingDefinition);
private Set<Integer> getPlatformMetricDefIds(ResourceType resourceType) { Set<Integer> metricDefIds = new TreeSet<Integer>(); List<String> metricDefNames = asList(MemoryMetric.Used.getProperty(), MemoryMetric.ActualUsed.getProperty(), MemoryMetric.Free.getProperty(), MemoryMetric.ActualFree.getProperty(), MemoryMetric.Total.getProperty(), CPUMetric.Idle.getProperty(), CPUMetric.System.getProperty(), CPUMetric.User.getProperty(), SwapMetric.Free.getProperty(), SwapMetric.Used.getProperty(), SwapMetric.Total.getProperty()); for (String metricDefName : metricDefNames) { Integer metricDefId = findMetricDefId(resourceType.getMetricDefinitions(), metricDefName); if (metricDefId != null) { metricDefIds.add(metricDefId); } } return metricDefIds; }
ResourceGroup group = fetchGroup(id, true); Set<MeasurementDefinition> definitions = group.getResourceType().getMetricDefinitions(); List<MetricSchedule> schedules = new ArrayList<MetricSchedule>(definitions.size()); for (MeasurementDefinition def : definitions) {
public static Set<MeasurementDefinition> getMetricDefinitions(ResourceType newType) { Set<MeasurementDefinition> result = newType.getMetricDefinitions(); result = (null == result) ? new HashSet<MeasurementDefinition>(1) : result; long period;
+ ResourceComponent.class); if (!resourceType.getMetricDefinitions().isEmpty() && !MeasurementFacet.class.isAssignableFrom(componentClazz)) { success = false;
Set<MeasurementDefinition> definitions = type.getMetricDefinitions(); if (!definitions.contains(md)) { throw new BadArgumentException("MeasurementDefinition does not apply to resource"); Set<MeasurementDefinition> definitions = resourceType.getMetricDefinitions(); if (!definitions.contains(md)) { throw new BadArgumentException("MeasurementDefinition does not apply to resource type");