added metric for pubsub

This commit is contained in:
Athou
2013-06-27 09:50:11 +02:00
parent dbc1e0b538
commit 9c6f75b633
2 changed files with 37 additions and 3 deletions

View File

@@ -57,6 +57,15 @@ public class MetricsBean {
thisMinute.statusesInserted += statusesCount; thisMinute.statusesInserted += statusesCount;
} }
public void pushReceived(int feedCount) {
thisHour.pushNotificationsReceived++;
thisMinute.pushNotificationsReceived++;
thisHour.pushFeedsQueued += feedCount;
thisMinute.pushFeedsQueued += feedCount;
}
public void threadWaited() { public void threadWaited() {
thisHour.threadWaited++; thisHour.threadWaited++;
thisMinute.threadWaited++; thisMinute.threadWaited++;
@@ -83,6 +92,8 @@ public class MetricsBean {
private int entriesInserted; private int entriesInserted;
private int statusesInserted; private int statusesInserted;
private int threadWaited; private int threadWaited;
private int pushNotificationsReceived;
private int pushFeedsQueued;
public int getFeedsRefreshed() { public int getFeedsRefreshed() {
return feedsRefreshed; return feedsRefreshed;
@@ -124,5 +135,21 @@ public class MetricsBean {
this.threadWaited = threadWaited; 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;
}
} }
} }

View File

@@ -21,6 +21,7 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.commafeed.backend.MetricsBean;
import com.commafeed.backend.dao.FeedDAO; import com.commafeed.backend.dao.FeedDAO;
import com.commafeed.backend.feeds.FeedParser; import com.commafeed.backend.feeds.FeedParser;
import com.commafeed.backend.feeds.FeedRefreshTaskGiver; import com.commafeed.backend.feeds.FeedRefreshTaskGiver;
@@ -50,6 +51,9 @@ public class PubSubHubbubCallbackREST {
@Inject @Inject
ApplicationSettingsService applicationSettingsService; ApplicationSettingsService applicationSettingsService;
@Inject
MetricsBean metricsBean;
@Path("/callback") @Path("/callback")
@GET @GET
@Produces(MediaType.TEXT_PLAIN) @Produces(MediaType.TEXT_PLAIN)
@@ -58,8 +62,9 @@ public class PubSubHubbubCallbackREST {
@QueryParam("hub.challenge") String challenge, @QueryParam("hub.challenge") String challenge,
@QueryParam("hub.lease_seconds") String leaseSeconds, @QueryParam("hub.lease_seconds") String leaseSeconds,
@QueryParam("hub.verify_token") String verifyToken) { @QueryParam("hub.verify_token") String verifyToken) {
Preconditions.checkState(applicationSettingsService.get().isPubsubhubbub()); Preconditions.checkState(applicationSettingsService.get()
.isPubsubhubbub());
Preconditions.checkArgument(StringUtils.isNotEmpty(topic)); Preconditions.checkArgument(StringUtils.isNotEmpty(topic));
Preconditions.checkArgument("subscribe".equals(mode)); Preconditions.checkArgument("subscribe".equals(mode));
@@ -85,7 +90,8 @@ public class PubSubHubbubCallbackREST {
@POST @POST
@Consumes({ MediaType.APPLICATION_ATOM_XML, "application/rss+xml" }) @Consumes({ MediaType.APPLICATION_ATOM_XML, "application/rss+xml" })
public Response callback() { public Response callback() {
Preconditions.checkState(applicationSettingsService.get().isPubsubhubbub()); Preconditions.checkState(applicationSettingsService.get()
.isPubsubhubbub());
try { try {
byte[] bytes = IOUtils.toByteArray(request.getInputStream()); byte[] bytes = IOUtils.toByteArray(request.getInputStream());
FetchedFeed fetchedFeed = parser.parse(null, bytes); FetchedFeed fetchedFeed = parser.parse(null, bytes);
@@ -97,6 +103,7 @@ public class PubSubHubbubCallbackREST {
log.debug("pushing content to queue for {}", feed.getUrl()); log.debug("pushing content to queue for {}", feed.getUrl());
taskGiver.add(feed); taskGiver.add(feed);
} }
metricsBean.pushReceived(feeds.size());
} }
} catch (Exception e) { } catch (Exception e) {
log.error("Could not parse pubsub callback: " + e.getMessage()); log.error("Could not parse pubsub callback: " + e.getMessage());