2013-04-16 13:52:20 +02:00
|
|
|
package com.commafeed.backend;
|
|
|
|
|
|
|
|
|
|
import javax.ejb.Singleton;
|
2013-06-05 11:58:35 +02:00
|
|
|
import javax.persistence.EntityManager;
|
|
|
|
|
import javax.persistence.PersistenceContext;
|
|
|
|
|
|
|
|
|
|
import org.hibernate.Session;
|
|
|
|
|
import org.hibernate.SessionFactory;
|
|
|
|
|
import org.hibernate.stat.Statistics;
|
2013-04-16 13:52:20 +02:00
|
|
|
|
|
|
|
|
@Singleton
|
|
|
|
|
public class MetricsBean {
|
|
|
|
|
|
2013-06-05 11:58:35 +02:00
|
|
|
@PersistenceContext
|
|
|
|
|
EntityManager em;
|
|
|
|
|
|
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-22 00:07:13 +02:00
|
|
|
public void feedUpdated() {
|
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
|
|
|
|
2013-05-22 00:07:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void entryUpdated(int statusesCount) {
|
|
|
|
|
|
|
|
|
|
thisHour.entriesInserted++;
|
|
|
|
|
thisMinute.entriesInserted++;
|
|
|
|
|
|
2013-05-18 17:50:38 +02:00
|
|
|
thisHour.statusesInserted += statusesCount;
|
|
|
|
|
thisMinute.statusesInserted += statusesCount;
|
2013-04-16 13:52:20 +02:00
|
|
|
}
|
|
|
|
|
|
2013-05-22 13:07:39 +02:00
|
|
|
public void threadWaited() {
|
|
|
|
|
thisHour.threadWaited++;
|
|
|
|
|
thisMinute.threadWaited++;
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-05 11:58:35 +02:00
|
|
|
public String getCacheStats() {
|
2013-06-07 15:08:10 +02:00
|
|
|
Session session = em.unwrap(Session.class);
|
2013-06-05 11:58:35 +02:00
|
|
|
SessionFactory sessionFactory = session.getSessionFactory();
|
|
|
|
|
Statistics statistics = sessionFactory.getStatistics();
|
|
|
|
|
return statistics.toString();
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-18 00:10:11 +02:00
|
|
|
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-22 13:07:39 +02:00
|
|
|
private int threadWaited;
|
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-05-22 13:07:39 +02:00
|
|
|
public int getThreadWaited() {
|
|
|
|
|
return threadWaited;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setThreadWaited(int threadWaited) {
|
|
|
|
|
this.threadWaited = threadWaited;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-16 13:52:20 +02:00
|
|
|
}
|
|
|
|
|
}
|