Search in sources :

Example 1 with MetricConfig

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();
            }
        }
    });
}
Also used : MetricConfig(org.platformlayer.ops.model.metrics.MetricConfig) ItemBase(org.platformlayer.core.model.ItemBase) ServiceProvider(org.platformlayer.xaas.services.ServiceProvider) MetricInfoCollection(org.platformlayer.metrics.model.MetricInfoCollection) OpsContext(org.platformlayer.ops.OpsContext) RepositoryException(org.platformlayer.RepositoryException) OpsException(org.platformlayer.ops.OpsException) OpsContextBuilder(org.platformlayer.ops.tasks.OpsContextBuilder) BindingScope(org.platformlayer.ops.BindingScope) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with MetricConfig

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;
}
Also used : MetricConfig(org.platformlayer.ops.model.metrics.MetricConfig)

Example 3 with 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);
        }
    }
}
Also used : MetricConfig(org.platformlayer.ops.model.metrics.MetricConfig) MetricInfo(org.platformlayer.metrics.model.MetricInfo) Metric(org.platformlayer.ops.model.metrics.Metric)

Example 4 with MetricConfig

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);
        }
    }
}
Also used : MetricConfig(org.platformlayer.ops.model.metrics.MetricConfig) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 5 with 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;
    }
}
Also used : MetricConfig(org.platformlayer.ops.model.metrics.MetricConfig) Metric(org.platformlayer.ops.model.metrics.Metric)

Aggregations

MetricConfig (org.platformlayer.ops.model.metrics.MetricConfig)5 Metric (org.platformlayer.ops.model.metrics.Metric)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 RepositoryException (org.platformlayer.RepositoryException)1 ItemBase (org.platformlayer.core.model.ItemBase)1 MetricInfo (org.platformlayer.metrics.model.MetricInfo)1 MetricInfoCollection (org.platformlayer.metrics.model.MetricInfoCollection)1 BindingScope (org.platformlayer.ops.BindingScope)1 OpsContext (org.platformlayer.ops.OpsContext)1 OpsException (org.platformlayer.ops.OpsException)1 OpsContextBuilder (org.platformlayer.ops.tasks.OpsContextBuilder)1 ServiceProvider (org.platformlayer.xaas.services.ServiceProvider)1