mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
initial metrics system
This commit is contained in:
43
src/main/java/com/commafeed/backend/MetricsBean.java
Normal file
43
src/main/java/com/commafeed/backend/MetricsBean.java
Normal file
@@ -0,0 +1,43 @@
|
||||
package com.commafeed.backend;
|
||||
|
||||
import javax.ejb.Singleton;
|
||||
|
||||
@Singleton
|
||||
public class MetricsBean {
|
||||
|
||||
private int feedsRefreshedLastMinute;
|
||||
private int feedsRefreshedThisMinute;
|
||||
|
||||
private int feedsRefreshedLastHour;
|
||||
private int feedsRefreshedThisHour;
|
||||
|
||||
private long minuteTimestamp;
|
||||
private long hourTimestamp;
|
||||
|
||||
public void feedRefreshed() {
|
||||
long now = System.currentTimeMillis();
|
||||
if (now - minuteTimestamp > 60000) {
|
||||
feedsRefreshedLastMinute = feedsRefreshedThisMinute;
|
||||
feedsRefreshedThisMinute = 0;
|
||||
minuteTimestamp = now;
|
||||
|
||||
}
|
||||
feedsRefreshedThisMinute++;
|
||||
|
||||
if (now - hourTimestamp > 60000 * 60) {
|
||||
feedsRefreshedLastHour = feedsRefreshedThisHour;
|
||||
feedsRefreshedThisHour = 0;
|
||||
hourTimestamp = now;
|
||||
|
||||
}
|
||||
feedsRefreshedThisHour++;
|
||||
}
|
||||
|
||||
public int getFeedsRefreshedLastMinute() {
|
||||
return feedsRefreshedLastMinute;
|
||||
}
|
||||
|
||||
public int getFeedsRefreshedLastHour() {
|
||||
return feedsRefreshedLastHour;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user