java - Codahale metrics counter reset and count everyday -


using codahale metrics there way count last 24 hours(today).

to generate report below:

request count:

lastsec   lastmin    lasthour    today ======================================= 1           5           22        45    

response count:

lastsec   lastmin    lasthour    today ======================================= 1           5           22        45    

there meter methods last second, minute, fifteen rates. how last hour , today count?

below tried:

public class reportmetrics {      static final metricregistry metrics = new metricregistry();     static final counter areqcount = reportmetrics.metrics.counter(name(aprocessor.class, "a-req-count"));     static final counter arescount = reportmetrics.metrics.counter(name(aprocessor.class, "a-res-count"));      private static final aprocessor aprocessor = new aprocessor();      public static void main(string[] args) {         startreport();          for(int i=0; i<=5; i++){             //add             aprocessor.addjob();             wait5seconds();                       //take             arprocessor.takejob();             wait5seconds();                  }      }      static void startreport() {           consolereporter reporter = consolereporter.forregistry(metrics)               .convertratesto(timeunit.seconds)               .convertdurationsto(timeunit.milliseconds)               .build();           reporter.start(1, timeunit.seconds);       }      static void wait5seconds() {           try {               thread.sleep(5*1000);           }           catch(interruptedexception e) {}       }      public long requestcount(){         reportmetrics.metrics.areqcount.getcount();     }      public long responsecount(){         reportmetrics.metrics.arescount.getcount();     }      public long pendingrequestcount(){         return requestcount() - responsecount();     }     }  class aprocessor {      public void addjob(){         reportmetrics.metrics.areqcount.inc();     }      public object takejob(){         reportmetrics.metrics.arescount.inc();     } } 

to sum or calculate count(total) per arbitrary interval counters reported counter.inc:

hitcount(persecond(aprocessor.a-req-count.count), '1hour')  hitcount(persecond(aprocessor.a-res-count.count), '1day') 

afaik black magic inside. including not limited summarize(scaletoseconds(nonnegativederivative(your.count),1), '1day') , there should scaling according carbon's retention periods (one or many) fall chosen aggregation interval.


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -