use of org.platformlayer.ops.model.metrics.MetricConfig in project platformlayer by platformlayer.
the class MetricsResource method listMetrics.
@GET
@Produces({ XML, JSON })
public MetricInfoCollection listMetrics() throws OpsException, RepositoryException {
final ItemBase managedItem = getManagedItem();
final ServiceProvider serviceProvider = getServiceProvider();
OpsContextBuilder opsContextBuilder = objectInjector.getInstance(OpsContextBuilder.class);
final OpsContext opsContext = opsContextBuilder.buildTemporaryOpsContext(getServiceType(), getProjectAuthorization());
return OpsContext.runInContext(opsContext, new CheckedCallable<MetricInfoCollection, Exception>() {
@Override
public MetricInfoCollection call() throws Exception {
BindingScope bindingScope = BindingScope.push(managedItem, managedItem);
try {
Object controller = serviceProvider.getController(managedItem);
MetricConfig metricConfig = opsContext.getMetricInfo(controller);
return MetricCollector.toMetricInfo(metricConfig);
} finally {
bindingScope.pop();
}
}
});
}
use of org.platformlayer.ops.model.metrics.MetricConfig in project platformlayer by platformlayer.
the class MetricCollector method getMetricInfo.
public MetricConfig getMetricInfo(Object target) throws OpsException {
visit(target);
MetricConfig metricConfig = new MetricConfig();
metricConfig.metrics = metricConfigs;
return metricConfig;
}
use of org.platformlayer.ops.model.metrics.MetricConfig in project platformlayer by platformlayer.
the class MetricCollector method populateMetricInfo.
static void populateMetricInfo(MetricInfoCollection metricInfoCollection, String prefix, MetricConfig metrics) {
if (metrics.metric != null) {
for (Metric metric : metrics.metric) {
MetricInfo metricInfo = new MetricInfo();
metricInfo.key = (prefix + metric.key);
metricInfoCollection.metricInfoList.add(metricInfo);
}
}
if (metrics.metrics != null) {
for (MetricConfig subtree : metrics.metrics) {
String childPrefix = prefix + subtree.key + "/";
populateMetricInfo(metricInfoCollection, childPrefix, subtree);
}
}
}
use of org.platformlayer.ops.model.metrics.MetricConfig in project platformlayer by platformlayer.
the class MetricCollector method visitMethods.
void visitMethods(Object target) throws OpsException {
for (Method method : target.getClass().getMethods()) {
Class<?> returnType = method.getReturnType();
if (returnType.equals(MetricConfig.class)) {
MetricConfig metricConfig;
try {
metricConfig = (MetricConfig) method.invoke(target, (Object[]) null);
} catch (IllegalArgumentException e) {
throw new OpsException("Error invoking method: " + method, e);
} catch (IllegalAccessException e) {
throw new OpsException("Error invoking method: " + method, e);
} catch (InvocationTargetException e) {
throw new OpsException("Error invoking method: " + method, e);
}
metricConfigs.add(metricConfig);
}
}
}
use of org.platformlayer.ops.model.metrics.MetricConfig in project platformlayer by platformlayer.
the class CollectdMetricFetcher method getMetricConfig.
private Metric getMetricConfig(MetricConfig metricConfig, String metricKey) throws OpsException {
String[] components = metricKey.split("\\.");
if (components.length == 0) {
throw new IllegalArgumentException();
}
int position = 0;
while (true) {
String component = components[position];
if ((position + 1) == components.length) {
if (metricConfig.metric != null) {
for (Metric metric : metricConfig.metric) {
if (Objects.equal(metric.key, component)) {
return metric;
}
}
}
} else {
boolean found = false;
if (metricConfig.metrics != null) {
for (MetricConfig tree : metricConfig.metrics) {
if (Objects.equal(tree.key, component)) {
position++;
metricConfig = tree;
found = true;
break;
}
}
}
if (found) {
continue;
}
}
return null;
}
}
Aggregations