mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
Instrumentation to count feed pushes.
This commit is contained in:
parent
23280a86aa
commit
ee76081cda
5 changed files with 48 additions and 15 deletions
|
@ -8,6 +8,7 @@ from django.shortcuts import get_object_or_404
|
||||||
|
|
||||||
from apps.push.models import PushSubscription
|
from apps.push.models import PushSubscription
|
||||||
from apps.push.signals import verified
|
from apps.push.signals import verified
|
||||||
|
from apps.rss_feeds.models import MFeedPushHistory
|
||||||
|
|
||||||
def push_callback(request, push_id):
|
def push_callback(request, push_id):
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
|
@ -42,6 +43,7 @@ def push_callback(request, push_id):
|
||||||
# Don't give fat ping, just fetch.
|
# Don't give fat ping, just fetch.
|
||||||
# subscription.feed.queue_pushed_feed_xml(request.raw_post_data)
|
# subscription.feed.queue_pushed_feed_xml(request.raw_post_data)
|
||||||
subscription.feed.queue_pushed_feed_xml("Fetch me")
|
subscription.feed.queue_pushed_feed_xml("Fetch me")
|
||||||
|
MFeedPushHistory.objects.create(feed_id=subscription.feed_id)
|
||||||
|
|
||||||
return HttpResponse('')
|
return HttpResponse('')
|
||||||
return Http404
|
return Http404
|
||||||
|
|
|
@ -1306,7 +1306,7 @@ class MFeedFetchHistory(mongo.Document):
|
||||||
for fetch in fetches:
|
for fetch in fetches:
|
||||||
history = {}
|
history = {}
|
||||||
history['message'] = fetch.message
|
history['message'] = fetch.message
|
||||||
history['fetch_date'] = fetch.fetch_date
|
history['fetch_date'] = fetch.fetch_date.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
history['status_code'] = fetch.status_code
|
history['status_code'] = fetch.status_code
|
||||||
history['exception'] = fetch.exception
|
history['exception'] = fetch.exception
|
||||||
fetch_history.append(history)
|
fetch_history.append(history)
|
||||||
|
@ -1339,12 +1339,35 @@ class MPageFetchHistory(mongo.Document):
|
||||||
for fetch in fetches:
|
for fetch in fetches:
|
||||||
history = {}
|
history = {}
|
||||||
history['message'] = fetch.message
|
history['message'] = fetch.message
|
||||||
history['fetch_date'] = fetch.fetch_date
|
history['fetch_date'] = fetch.fetch_date.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
history['status_code'] = fetch.status_code
|
history['status_code'] = fetch.status_code
|
||||||
history['exception'] = fetch.exception
|
history['exception'] = fetch.exception
|
||||||
fetch_history.append(history)
|
fetch_history.append(history)
|
||||||
return fetch_history
|
return fetch_history
|
||||||
|
|
||||||
|
|
||||||
|
class MFeedPushHistory(mongo.Document):
|
||||||
|
feed_id = mongo.IntField()
|
||||||
|
push_date = mongo.DateTimeField(default=datetime.datetime.now)
|
||||||
|
|
||||||
|
meta = {
|
||||||
|
'collection': 'feed_push_history',
|
||||||
|
'allow_inheritance': False,
|
||||||
|
'ordering': ['-push_date'],
|
||||||
|
'indexes': ['feed_id', '-push_date'],
|
||||||
|
}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def feed_history(cls, feed_id):
|
||||||
|
pushes = cls.objects(feed_id=feed_id).order_by('-push_date')[:5]
|
||||||
|
push_history = []
|
||||||
|
for push in pushes:
|
||||||
|
history = {}
|
||||||
|
history['push_date'] = push.push_date.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
push_history.append(history)
|
||||||
|
return push_history
|
||||||
|
|
||||||
|
|
||||||
class FeedLoadtime(models.Model):
|
class FeedLoadtime(models.Model):
|
||||||
feed = models.ForeignKey(Feed)
|
feed = models.ForeignKey(Feed)
|
||||||
date_accessed = models.DateTimeField(auto_now=True)
|
date_accessed = models.DateTimeField(auto_now=True)
|
||||||
|
|
|
@ -7,7 +7,7 @@ from django.contrib.auth.decorators import login_required
|
||||||
from django.template import RequestContext
|
from django.template import RequestContext
|
||||||
# from django.db import IntegrityError
|
# from django.db import IntegrityError
|
||||||
from apps.rss_feeds.models import Feed, merge_feeds
|
from apps.rss_feeds.models import Feed, merge_feeds
|
||||||
from apps.rss_feeds.models import MFeedFetchHistory, MPageFetchHistory
|
from apps.rss_feeds.models import MFeedFetchHistory, MPageFetchHistory, MFeedPushHistory
|
||||||
from apps.analyzer.models import get_classifiers_for_user
|
from apps.analyzer.models import get_classifiers_for_user
|
||||||
from apps.reader.models import UserSubscription
|
from apps.reader.models import UserSubscription
|
||||||
from utils.user_functions import ajax_login_required
|
from utils.user_functions import ajax_login_required
|
||||||
|
@ -125,6 +125,7 @@ def load_feed_statistics(request, feed_id):
|
||||||
# Fetch histories
|
# Fetch histories
|
||||||
stats['feed_fetch_history'] = MFeedFetchHistory.feed_history(feed_id)
|
stats['feed_fetch_history'] = MFeedFetchHistory.feed_history(feed_id)
|
||||||
stats['page_fetch_history'] = MPageFetchHistory.feed_history(feed_id)
|
stats['page_fetch_history'] = MPageFetchHistory.feed_history(feed_id)
|
||||||
|
stats['feed_push_history'] = MFeedPushHistory.feed_history(feed_id)
|
||||||
|
|
||||||
logging.user(request, "~FBStatistics: ~SB%s ~FG(%s/%s/%s subs)" % (feed, feed.num_subscribers, feed.active_subscribers, feed.premium_subscribers,))
|
logging.user(request, "~FBStatistics: ~SB%s ~FG(%s/%s/%s subs)" % (feed, feed.num_subscribers, feed.active_subscribers, feed.premium_subscribers,))
|
||||||
|
|
||||||
|
|
|
@ -4588,8 +4588,11 @@ background: transparent;
|
||||||
|
|
||||||
.NB-modal-statistics .NB-statistics-stat .NB-statistics-fetches-half {
|
.NB-modal-statistics .NB-statistics-stat .NB-statistics-fetches-half {
|
||||||
float: left;
|
float: left;
|
||||||
width: 50%;
|
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
margin-right: 18px;
|
||||||
|
}
|
||||||
|
.NB-modal-statistics .NB-statistics-stat .NB-statistics-fetches-half:last-child {
|
||||||
|
margin-right: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.NB-modal-statistics .NB-statistics-stat .NB-statistics-history-stat {
|
.NB-modal-statistics .NB-statistics-stat .NB-statistics-history-stat {
|
||||||
|
@ -4631,7 +4634,7 @@ background: transparent;
|
||||||
}
|
}
|
||||||
.NB-modal-statistics .NB-statistics-history-fetch .NB-statistics-history-fetch-message {
|
.NB-modal-statistics .NB-statistics-history-fetch .NB-statistics-history-fetch-message {
|
||||||
padding-right: 4px;
|
padding-right: 4px;
|
||||||
margin-left: 120px;
|
margin-left: 110px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
.NB-modal-statistics .NB-statistics-history-fetch .NB-statistics-history-fetch-exception {
|
.NB-modal-statistics .NB-statistics-history-fetch .NB-statistics-history-fetch-exception {
|
||||||
|
|
|
@ -126,13 +126,17 @@ _.extend(NEWSBLUR.ReaderStatistics.prototype, {
|
||||||
])),
|
])),
|
||||||
$.make('div', { className: 'NB-statistics-stat NB-statistics-fetches'}, [
|
$.make('div', { className: 'NB-statistics-stat NB-statistics-fetches'}, [
|
||||||
$.make('div', { className: 'NB-statistics-fetches-half'}, [
|
$.make('div', { className: 'NB-statistics-fetches-half'}, [
|
||||||
$.make('div', { className: 'NB-statistics-label' }, 'Feed'),
|
$.make('div', { className: 'NB-statistics-label' }, 'Feed Fetch'),
|
||||||
$.make('div', this.make_history(data, 'feed'))
|
$.make('div', this.make_history(data, 'feed_fetch'))
|
||||||
]),
|
]),
|
||||||
$.make('div', { className: 'NB-statistics-fetches-half'}, [
|
$.make('div', { className: 'NB-statistics-fetches-half'}, [
|
||||||
$.make('div', { className: 'NB-statistics-label' }, 'Page'),
|
$.make('div', { className: 'NB-statistics-label' }, 'Page Fetch'),
|
||||||
$.make('div', this.make_history(data, 'page'))
|
$.make('div', this.make_history(data, 'page_fetch'))
|
||||||
])
|
]),
|
||||||
|
(this.feed.is_push && $.make('div', { className: 'NB-statistics-fetches-half'}, [
|
||||||
|
$.make('div', { className: 'NB-statistics-label' }, 'Feed Push'),
|
||||||
|
$.make('div', this.make_history(data, 'feed_push'))
|
||||||
|
]))
|
||||||
])
|
])
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -209,17 +213,17 @@ _.extend(NEWSBLUR.ReaderStatistics.prototype, {
|
||||||
},
|
},
|
||||||
|
|
||||||
make_history: function(data, fetch_type) {
|
make_history: function(data, fetch_type) {
|
||||||
var fetches = data[fetch_type+'_fetch_history'];
|
var fetches = data[fetch_type+'_history'];
|
||||||
if (!fetches) return;
|
if (!fetches) return;
|
||||||
|
|
||||||
var $history = _.map(fetches, function(fetch) {
|
var $history = _.map(fetches, function(fetch) {
|
||||||
var feed_ok = _.contains([200, 304], fetch.status_code);
|
var feed_ok = _.contains([200, 304], fetch.status_code) || !fetch.status_code;
|
||||||
var status_class = feed_ok ? ' NB-ok ' : ' NB-errorcode ';
|
var status_class = feed_ok ? ' NB-ok ' : ' NB-errorcode ';
|
||||||
return $.make('div', { className: 'NB-statistics-history-fetch' + status_class, title: feed_ok ? '' : fetch.exception }, [
|
return $.make('div', { className: 'NB-statistics-history-fetch' + status_class, title: feed_ok ? '' : fetch.exception }, [
|
||||||
$.make('div', { className: 'NB-statistics-history-fetch-date' }, fetch.fetch_date),
|
$.make('div', { className: 'NB-statistics-history-fetch-date' }, fetch.fetch_date),
|
||||||
$.make('div', { className: 'NB-statistics-history-fetch-message' }, [
|
$.make('div', { className: 'NB-statistics-history-fetch-message' }, [
|
||||||
fetch.message,
|
fetch.message,
|
||||||
$.make('div', { className: 'NB-statistics-history-fetch-code' }, ' ('+fetch.status_code+')')
|
(fetch.status_code && $.make('div', { className: 'NB-statistics-history-fetch-code' }, ' ('+fetch.status_code+')'))
|
||||||
])
|
])
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue