Files
Athou_commafeed/src/main/java/com/commafeed/backend/MetricsBean.java

95 lines
2.0 KiB
Java
Raw Normal View History

2013-04-16 13:52:20 +02:00
package com.commafeed.backend;
import javax.ejb.Singleton;
@Singleton
public class MetricsBean {
2013-05-18 00:10:11 +02:00
private Metric lastMinute = new Metric();
private Metric thisMinute = new Metric();
2013-04-16 13:52:20 +02:00
2013-05-18 00:10:11 +02:00
private Metric lastHour = new Metric();
private Metric thisHour = new Metric();
2013-04-16 13:52:20 +02:00
private long minuteTimestamp;
private long hourTimestamp;
public void feedRefreshed() {
long now = System.currentTimeMillis();
if (now - minuteTimestamp > 60000) {
2013-05-18 00:10:11 +02:00
lastMinute = thisMinute;
thisMinute = new Metric();
2013-04-16 13:52:20 +02:00
minuteTimestamp = now;
}
2013-05-18 00:10:11 +02:00
thisMinute.feedsRefreshed++;
2013-04-16 13:52:20 +02:00
if (now - hourTimestamp > 60000 * 60) {
2013-05-18 00:10:11 +02:00
lastHour = thisHour;
thisHour = new Metric();
2013-04-16 13:52:20 +02:00
hourTimestamp = now;
}
2013-05-18 00:10:11 +02:00
thisHour.feedsRefreshed++;
}
2013-05-18 17:50:38 +02:00
public void feedUpdated(int entriesCount, int statusesCount) {
2013-05-18 14:01:46 +02:00
thisHour.feedsUpdated++;
2013-05-18 00:10:11 +02:00
thisMinute.feedsUpdated++;
2013-05-18 09:38:34 +02:00
thisHour.entriesInserted += entriesCount;
thisMinute.entriesInserted += entriesCount;
2013-05-18 17:50:38 +02:00
thisHour.statusesInserted += statusesCount;
thisMinute.statusesInserted += statusesCount;
2013-04-16 13:52:20 +02:00
}
2013-05-18 00:10:11 +02:00
public Metric getLastMinute() {
return lastMinute;
2013-04-16 13:52:20 +02:00
}
2013-05-18 00:10:11 +02:00
public Metric getLastHour() {
return lastHour;
}
public static class Metric {
private int feedsRefreshed;
private int feedsUpdated;
2013-05-18 09:38:34 +02:00
private int entriesInserted;
2013-05-18 17:50:38 +02:00
private int statusesInserted;
2013-05-18 00:10:11 +02:00
public int getFeedsRefreshed() {
return feedsRefreshed;
}
public void setFeedsRefreshed(int feedsRefreshed) {
this.feedsRefreshed = feedsRefreshed;
}
public int getFeedsUpdated() {
return feedsUpdated;
}
public void setFeedsUpdated(int feedsUpdated) {
this.feedsUpdated = feedsUpdated;
}
2013-05-18 09:38:34 +02:00
public int getEntriesInserted() {
return entriesInserted;
}
public void setEntriesInserted(int entriesInserted) {
this.entriesInserted = entriesInserted;
}
2013-05-18 17:50:38 +02:00
public int getStatusesInserted() {
return statusesInserted;
}
public void setStatusesInserted(int statusesInserted) {
this.statusesInserted = statusesInserted;
}
2013-04-16 13:52:20 +02:00
}
}