mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
better metrics
This commit is contained in:
@@ -2,19 +2,14 @@ package com.commafeed.backend;
|
||||
|
||||
import javax.ejb.Singleton;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@Singleton
|
||||
public class MetricsBean {
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(MetricsBean.class);
|
||||
private Metric lastMinute = new Metric();
|
||||
private Metric thisMinute = new Metric();
|
||||
|
||||
private int feedsRefreshedLastMinute;
|
||||
private int feedsRefreshedThisMinute;
|
||||
|
||||
private int feedsRefreshedLastHour;
|
||||
private int feedsRefreshedThisHour;
|
||||
private Metric lastHour = new Metric();
|
||||
private Metric thisHour = new Metric();
|
||||
|
||||
private long minuteTimestamp;
|
||||
private long hourTimestamp;
|
||||
@@ -22,28 +17,54 @@ public class MetricsBean {
|
||||
public void feedRefreshed() {
|
||||
long now = System.currentTimeMillis();
|
||||
if (now - minuteTimestamp > 60000) {
|
||||
feedsRefreshedLastMinute = feedsRefreshedThisMinute;
|
||||
feedsRefreshedThisMinute = 0;
|
||||
lastMinute = thisMinute;
|
||||
thisMinute = new Metric();
|
||||
minuteTimestamp = now;
|
||||
log.debug("** feeds per minute: {}", feedsRefreshedLastMinute);
|
||||
|
||||
}
|
||||
feedsRefreshedThisMinute++;
|
||||
thisMinute.feedsRefreshed++;
|
||||
|
||||
if (now - hourTimestamp > 60000 * 60) {
|
||||
feedsRefreshedLastHour = feedsRefreshedThisHour;
|
||||
feedsRefreshedThisHour = 0;
|
||||
lastHour = thisHour;
|
||||
thisHour = new Metric();
|
||||
hourTimestamp = now;
|
||||
|
||||
}
|
||||
feedsRefreshedThisHour++;
|
||||
thisHour.feedsRefreshed++;
|
||||
}
|
||||
|
||||
public int getFeedsRefreshedLastMinute() {
|
||||
return feedsRefreshedLastMinute;
|
||||
public void feedUpdated() {
|
||||
thisHour.feedsRefreshed++;
|
||||
thisMinute.feedsUpdated++;
|
||||
}
|
||||
|
||||
public int getFeedsRefreshedLastHour() {
|
||||
return feedsRefreshedLastHour;
|
||||
public Metric getLastMinute() {
|
||||
return lastMinute;
|
||||
}
|
||||
|
||||
public Metric getLastHour() {
|
||||
return lastHour;
|
||||
}
|
||||
|
||||
public static class Metric {
|
||||
private int feedsRefreshed;
|
||||
private int feedsUpdated;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import javax.inject.Inject;
|
||||
import org.apache.commons.lang.ObjectUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.commafeed.backend.MetricsBean;
|
||||
import com.commafeed.backend.dao.FeedEntryDAO;
|
||||
import com.commafeed.backend.dao.FeedEntryStatusDAO;
|
||||
import com.commafeed.backend.dao.FeedSubscriptionDAO;
|
||||
@@ -36,6 +37,9 @@ public class FeedUpdateService {
|
||||
@Inject
|
||||
FeedEntryStatusDAO feedEntryStatusDAO;
|
||||
|
||||
@Inject
|
||||
MetricsBean metricsBean;
|
||||
|
||||
@Lock(LockType.WRITE)
|
||||
public void updateEntries(Feed feed, Collection<FeedEntry> entries) {
|
||||
|
||||
@@ -91,6 +95,7 @@ public class FeedUpdateService {
|
||||
|
||||
feedEntryDAO.saveOrUpdate(entryUpdateList);
|
||||
feedEntryStatusDAO.saveOrUpdate(statusUpdateList);
|
||||
metricsBean.feedUpdated();
|
||||
}
|
||||
|
||||
private FeedEntry findEntry(List<FeedEntry> existingEntries, FeedEntry entry) {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.commafeed.frontend.rest.resources;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -14,6 +12,7 @@ import javax.ws.rs.core.Response.Status;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.commafeed.backend.MetricsBean.Metric;
|
||||
import com.commafeed.backend.StartupBean;
|
||||
import com.commafeed.backend.model.ApplicationSettings;
|
||||
import com.commafeed.backend.model.User;
|
||||
@@ -23,6 +22,7 @@ import com.commafeed.frontend.SecurityCheck;
|
||||
import com.commafeed.frontend.model.UserModel;
|
||||
import com.commafeed.frontend.model.request.IDRequest;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.wordnik.swagger.annotations.Api;
|
||||
@@ -174,9 +174,9 @@ public class AdminREST extends AbstractResourceREST {
|
||||
@Path("/metrics")
|
||||
@GET
|
||||
public Response getMetrics() {
|
||||
List<Integer> list = Arrays.asList(
|
||||
metricsBean.getFeedsRefreshedLastMinute(),
|
||||
metricsBean.getFeedsRefreshedLastHour());
|
||||
return Response.ok(list).build();
|
||||
Map<String, Metric> map = ImmutableMap.of("lastMinute",
|
||||
metricsBean.getLastMinute(), "lastHour",
|
||||
metricsBean.getLastHour());
|
||||
return Response.ok(map).build();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user