Search in sources :

Example 1 with MetricRegistryBindings

use of io.engineblock.metrics.MetricRegistryBindings in project engineblock by engineblock.

the class MetricsMapper method metricsDetail.

public static String metricsDetail(String activitySpec) {
    // StringBuilder metricsDetail = new StringBuilder();
    List<String> metricsDetails = new ArrayList<String>();
    ActivityDef activityDef = ActivityDef.parseActivityDef(activitySpec);
    logger.info("introspecting metric names for " + activitySpec);
    Optional<ActivityType> activityType = ActivityType.FINDER.get(activityDef.getActivityType());
    if (!activityType.isPresent()) {
        throw new RuntimeException("Activity type '" + activityDef.getActivityType() + "' does not exist in this runtime.");
    }
    Activity activity = activityType.get().getAssembledActivity(activityDef, new HashMap<>());
    MetricRegistryBindings metricRegistryBindings = new MetricRegistryBindings(ActivityMetrics.getMetricRegistry());
    activity.initActivity();
    activity.getInputDispenserDelegate().getInput(0);
    activity.getActionDispenserDelegate().getAction(0);
    activity.getMotorDispenserDelegate().getMotor(activityDef, 0);
    Map<String, Metric> metricMap = metricRegistryBindings.getMetrics();
    for (Map.Entry<String, Metric> metricEntry : metricMap.entrySet()) {
        String metricName = metricEntry.getKey();
        Metric metricValue = metricEntry.getValue();
        Map<String, String> getterSummary = getGetterSummary(metricValue);
        // details.put(metricName,getterSummary);
        List<String> methodDetails = getterSummary.entrySet().stream().map(es -> metricName + es.getKey() + "  " + es.getValue()).collect(Collectors.toList());
        methodDetails.sort(String::compareTo);
        String getterText = methodDetails.stream().collect(Collectors.joining("\n"));
        metricsDetails.add(metricName + "\n" + getterText);
    }
    return metricsDetails.stream().collect(Collectors.joining("\n"));
}
Also used : ActivityType(io.engineblock.activityapi.core.ActivityType) java.util(java.util) Logger(org.slf4j.Logger) Predicate(java.util.function.Predicate) LoggerFactory(org.slf4j.LoggerFactory) ActivityDef(io.engineblock.activityimpl.ActivityDef) Timer(java.util.Timer) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ActivityMetrics(io.engineblock.metrics.ActivityMetrics) Activity(io.engineblock.activityapi.core.Activity) com.codahale.metrics(com.codahale.metrics) MetricRegistryBindings(io.engineblock.metrics.MetricRegistryBindings) Method(java.lang.reflect.Method) ActivityType(io.engineblock.activityapi.core.ActivityType) Activity(io.engineblock.activityapi.core.Activity) ActivityDef(io.engineblock.activityimpl.ActivityDef) MetricRegistryBindings(io.engineblock.metrics.MetricRegistryBindings)

Example 2 with MetricRegistryBindings

use of io.engineblock.metrics.MetricRegistryBindings in project engineblock by engineblock.

the class Scenario method init.

private void init() {
    MetricRegistry metricRegistry = ActivityMetrics.getMetricRegistry();
    scriptEngine = engineManager.getEngineByName("nashorn");
    scriptEnv = new ScenarioContext(scenarioController);
    scriptEngine.setContext(scriptEnv);
    scenarioController = new ScenarioController();
    progressIndicator = new ProgressIndicator(scenarioController, progressInterval);
    scriptEngine.put("scenario", scenarioController);
    scriptEngine.put("activities", new ScenarioBindings(scenarioController));
    scriptEngine.put("metrics", new MetricRegistryBindings(metricRegistry));
    for (ScriptingPluginInfo extensionDescriptor : SandboxExtensionFinder.findAll()) {
        if (!extensionDescriptor.isAutoLoading()) {
            logger.info("Not loading " + extensionDescriptor + ", autoloading is false");
            continue;
        }
        org.slf4j.Logger extensionLogger = LoggerFactory.getLogger("extensions." + extensionDescriptor.getBaseVariableName());
        Object extensionObject = extensionDescriptor.getExtensionObject(extensionLogger, metricRegistry, scriptEnv);
        logger.debug("Adding extension object:  name=" + extensionDescriptor.getBaseVariableName() + " class=" + extensionObject.getClass().getSimpleName());
        scriptEngine.put(extensionDescriptor.getBaseVariableName(), extensionObject);
    }
}
Also used : MetricRegistryBindings(io.engineblock.metrics.MetricRegistryBindings) ScenarioController(io.engineblock.core.ScenarioController) ProgressIndicator(io.engineblock.activitycore.ProgressIndicator) MetricRegistry(com.codahale.metrics.MetricRegistry) ScriptingPluginInfo(io.engineblock.extensions.ScriptingPluginInfo)

Aggregations

MetricRegistryBindings (io.engineblock.metrics.MetricRegistryBindings)2 com.codahale.metrics (com.codahale.metrics)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1 Activity (io.engineblock.activityapi.core.Activity)1 ActivityType (io.engineblock.activityapi.core.ActivityType)1 ProgressIndicator (io.engineblock.activitycore.ProgressIndicator)1 ActivityDef (io.engineblock.activityimpl.ActivityDef)1 ScenarioController (io.engineblock.core.ScenarioController)1 ScriptingPluginInfo (io.engineblock.extensions.ScriptingPluginInfo)1 ActivityMetrics (io.engineblock.metrics.ActivityMetrics)1 Method (java.lang.reflect.Method)1 java.util (java.util)1 Timer (java.util.Timer)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1