From 9c6f75b633094ad017303a0015ac897cc0eaaf43 Mon Sep 17 00:00:00 2001 From: Athou Date: Thu, 27 Jun 2013 09:50:11 +0200 Subject: [PATCH] added metric for pubsub --- .../com/commafeed/backend/MetricsBean.java | 27 +++++++++++++++++++ .../resources/PubSubHubbubCallbackREST.java | 13 ++++++--- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/commafeed/backend/MetricsBean.java b/src/main/java/com/commafeed/backend/MetricsBean.java index 0ff007ce..ca630da9 100644 --- a/src/main/java/com/commafeed/backend/MetricsBean.java +++ b/src/main/java/com/commafeed/backend/MetricsBean.java @@ -57,6 +57,15 @@ public class MetricsBean { thisMinute.statusesInserted += statusesCount; } + public void pushReceived(int feedCount) { + + thisHour.pushNotificationsReceived++; + thisMinute.pushNotificationsReceived++; + + thisHour.pushFeedsQueued += feedCount; + thisMinute.pushFeedsQueued += feedCount; + } + public void threadWaited() { thisHour.threadWaited++; thisMinute.threadWaited++; @@ -83,6 +92,8 @@ public class MetricsBean { private int entriesInserted; private int statusesInserted; private int threadWaited; + private int pushNotificationsReceived; + private int pushFeedsQueued; public int getFeedsRefreshed() { return feedsRefreshed; @@ -124,5 +135,21 @@ public class MetricsBean { this.threadWaited = threadWaited; } + public int getPushNotificationsReceived() { + return pushNotificationsReceived; + } + + public void setPushNotificationsReceived(int pushNotificationsReceived) { + this.pushNotificationsReceived = pushNotificationsReceived; + } + + public int getPushFeedsQueued() { + return pushFeedsQueued; + } + + public void setPushFeedsQueued(int pushFeedsQueued) { + this.pushFeedsQueued = pushFeedsQueued; + } + } } diff --git a/src/main/java/com/commafeed/frontend/rest/resources/PubSubHubbubCallbackREST.java b/src/main/java/com/commafeed/frontend/rest/resources/PubSubHubbubCallbackREST.java index 38b557b9..25d000dc 100644 --- a/src/main/java/com/commafeed/frontend/rest/resources/PubSubHubbubCallbackREST.java +++ b/src/main/java/com/commafeed/frontend/rest/resources/PubSubHubbubCallbackREST.java @@ -21,6 +21,7 @@ import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.commafeed.backend.MetricsBean; import com.commafeed.backend.dao.FeedDAO; import com.commafeed.backend.feeds.FeedParser; import com.commafeed.backend.feeds.FeedRefreshTaskGiver; @@ -50,6 +51,9 @@ public class PubSubHubbubCallbackREST { @Inject ApplicationSettingsService applicationSettingsService; + @Inject + MetricsBean metricsBean; + @Path("/callback") @GET @Produces(MediaType.TEXT_PLAIN) @@ -58,8 +62,9 @@ public class PubSubHubbubCallbackREST { @QueryParam("hub.challenge") String challenge, @QueryParam("hub.lease_seconds") String leaseSeconds, @QueryParam("hub.verify_token") String verifyToken) { - Preconditions.checkState(applicationSettingsService.get().isPubsubhubbub()); - + Preconditions.checkState(applicationSettingsService.get() + .isPubsubhubbub()); + Preconditions.checkArgument(StringUtils.isNotEmpty(topic)); Preconditions.checkArgument("subscribe".equals(mode)); @@ -85,7 +90,8 @@ public class PubSubHubbubCallbackREST { @POST @Consumes({ MediaType.APPLICATION_ATOM_XML, "application/rss+xml" }) public Response callback() { - Preconditions.checkState(applicationSettingsService.get().isPubsubhubbub()); + Preconditions.checkState(applicationSettingsService.get() + .isPubsubhubbub()); try { byte[] bytes = IOUtils.toByteArray(request.getInputStream()); FetchedFeed fetchedFeed = parser.parse(null, bytes); @@ -97,6 +103,7 @@ public class PubSubHubbubCallbackREST { log.debug("pushing content to queue for {}", feed.getUrl()); taskGiver.add(feed); } + metricsBean.pushReceived(feeds.size()); } } catch (Exception e) { log.error("Could not parse pubsub callback: " + e.getMessage());