Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Expand
titleCustom metrics within a computation


Code Block
languagejava
/** */
private static final class TestCustomMetricsComputeTask extends ComputeTaskAdapter<Void, Long> {

    /** */
    private static final class TestComputeJob extends ComputeJobAdapter {
        /** Ignite instance. */
        @IgniteInstanceResource
        private Ignite ignite;
        /** {@inheritDoc} */
        @Override public Long execute() throws IgniteException {
            long val = 0;
            // Some job limit.
            long limit = 300 +

    private static final class TestComputeJob extends ComputeJobAdapter {
        @IgniteInstanceResource
        private Ignite ignite;

        @Override public Long execute() throws IgniteException {
            long val = 0;

            // Some job limit.
            long limit = 300 + ThreadLocalRandom.current().nextLong(700);



           
 
 // Registers metric "custom.task.test.current"

            LongValueMetric metricCur = ignite.metrics().customRegistry("task.test").longMetric("current", null);


           
 
 // Registers metric "custom.task.test.total.sum"

            LongSumMetric metricTotal = ignite.metrics().customRegistry("task.test").longAdderMetric("total.sum", null);


           
 
 // Registers metric "custom.task.test.ticks"           

            LongSumMetric metricTicks = ignite.metrics().customRegistry("task.test").longAdderMetric("ticks", null);



            while (!isCancelled() && val < limit) {


                // Does some job.


                try {


                    U.sleep(ThreadLocalRandom.current().nextInt(50));


                }


                catch (IgniteInterruptedCheckedException ignored) {


                    //No op.


                }



                long increment = ThreadLocalRandom.current().nextLong(100);



                val += increment;



               
 
 metricTicks.increment()

            }



            metricCur.value(val);



            metricTotal.add(val);



            return isCancelled() ? 0 : val;


        }


    }


}


Further Steps

We already have implementations of more complex and useful metrics. We could also store custom metrics. Thus, the development stages might be:

...