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;
}
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);
}
Aggregations