Search in sources :

Example 1 with ProgramUserMetrics

use of co.cask.cdap.app.metrics.ProgramUserMetrics in project cdap by caskdata.

the class CustomActionExecutor method createAction.

@SuppressWarnings("unchecked")
@Deprecated
private WorkflowAction createAction(BasicWorkflowContext context, InstantiatorFactory instantiator, ClassLoader classLoader) throws Exception {
    Class<?> clz = Class.forName(context.getSpecification().getClassName(), true, classLoader);
    Preconditions.checkArgument(WorkflowAction.class.isAssignableFrom(clz), "%s is not a WorkflowAction.", clz);
    WorkflowAction action = instantiator.get(TypeToken.of((Class<? extends WorkflowAction>) clz)).create();
    Metrics metrics = new ProgramUserMetrics(context.getProgramMetrics().childContext(Constants.Metrics.Tag.NODE, context.getSpecification().getName()));
    Reflections.visit(action, action.getClass(), new PropertyFieldSetter(context.getSpecification().getProperties()), new DataSetFieldSetter(context), new MetricsFieldSetter(metrics));
    return action;
}
Also used : ProgramUserMetrics(co.cask.cdap.app.metrics.ProgramUserMetrics) Metrics(co.cask.cdap.api.metrics.Metrics) PropertyFieldSetter(co.cask.cdap.common.lang.PropertyFieldSetter) MetricsFieldSetter(co.cask.cdap.internal.app.runtime.MetricsFieldSetter) WorkflowAction(co.cask.cdap.api.workflow.WorkflowAction) ProgramUserMetrics(co.cask.cdap.app.metrics.ProgramUserMetrics) DataSetFieldSetter(co.cask.cdap.internal.app.runtime.DataSetFieldSetter)

Example 2 with ProgramUserMetrics

use of co.cask.cdap.app.metrics.ProgramUserMetrics in project cdap by caskdata.

the class MetricsHandlerTestRun method setupMetrics.

private static void setupMetrics() throws Exception {
    // Adding metrics for app "WordCount1" in namespace "myspace", "WCount1" in "yourspace"
    MetricsContext collector = collectionService.getContext(getFlowletContext("myspace", "WordCount1", "WordCounter", "run1", "splitter"));
    collector.increment("reads", 1);
    collector.increment("writes", 1);
    collector = collectionService.getContext(getFlowletContext("yourspace", "WCount1", "WordCounter", "run1", "splitter"));
    collector.increment("reads", 1);
    collector = collectionService.getContext(getFlowletContext("yourspace", "WCount1", "WCounter", "run1", "splitter"));
    emitTs = System.currentTimeMillis();
    // we want to emit in two different seconds
    // todo : figure out why we need this
    TimeUnit.SECONDS.sleep(1);
    collector.increment("reads", 1);
    TimeUnit.MILLISECONDS.sleep(2000);
    collector.increment("reads", 2);
    collector = collectionService.getContext(getFlowletContext("yourspace", "WCount1", "WCounter", "run1", "counter"));
    collector.increment("reads", 1);
    collector = collectionService.getContext(getMapReduceTaskContext("yourspace", "WCount1", "ClassicWordCount", MapReduceMetrics.TaskType.Mapper, "run1", "task1"));
    collector.increment("reads", 1);
    collector = collectionService.getContext(getMapReduceTaskContext("yourspace", "WCount1", "ClassicWordCount", MapReduceMetrics.TaskType.Reducer, "run1", "task2"));
    collector.increment("reads", 1);
    collector = collectionService.getContext(getFlowletContext("myspace", "WordCount1", "WordCounter", "run1", "splitter"));
    collector.increment("reads", 1);
    collector.increment("writes", 1);
    collector = collectionService.getContext(getFlowletContext("myspace", "WordCount1", "WordCounter", "run1", "collector"));
    collector.increment("aa", 1);
    collector.increment("zz", 1);
    collector.increment("ab", 1);
    collector = collectionService.getContext(getWorkerContext("yourspace", "WCount1", "WorkerWordCount", "run1", "task1"));
    collector.increment("workerreads", 5);
    collector.increment("workerwrites", 6);
    collector = collectionService.getContext(getWorkerContext("yourspace", "WCount1", "WorkerWordCount", "run2", "task1"));
    collector.increment("workerreads", 5);
    collector.increment("workerwrites", 6);
    // also: user metrics
    Metrics userMetrics = new ProgramUserMetrics(collectionService.getContext(getFlowletContext("myspace", "WordCount1", "WordCounter", "run1", "splitter")));
    userMetrics.count("reads", 1);
    userMetrics.count("writes", 2);
    collector = collectionService.getContext(new HashMap<String, String>());
    collector.increment("resources.total.storage", 10);
    // need a better way to do this
    TimeUnit.SECONDS.sleep(2);
}
Also used : MapReduceMetrics(co.cask.cdap.app.metrics.MapReduceMetrics) ProgramUserMetrics(co.cask.cdap.app.metrics.ProgramUserMetrics) Metrics(co.cask.cdap.api.metrics.Metrics) HashMap(java.util.HashMap) MetricsContext(co.cask.cdap.api.metrics.MetricsContext) ProgramUserMetrics(co.cask.cdap.app.metrics.ProgramUserMetrics)

Aggregations

Metrics (co.cask.cdap.api.metrics.Metrics)2 ProgramUserMetrics (co.cask.cdap.app.metrics.ProgramUserMetrics)2 MetricsContext (co.cask.cdap.api.metrics.MetricsContext)1 WorkflowAction (co.cask.cdap.api.workflow.WorkflowAction)1 MapReduceMetrics (co.cask.cdap.app.metrics.MapReduceMetrics)1 PropertyFieldSetter (co.cask.cdap.common.lang.PropertyFieldSetter)1 DataSetFieldSetter (co.cask.cdap.internal.app.runtime.DataSetFieldSetter)1 MetricsFieldSetter (co.cask.cdap.internal.app.runtime.MetricsFieldSetter)1 HashMap (java.util.HashMap)1