mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-04-13 09:42:01 +00:00
45 lines
1.3 KiB
Python
Executable file
45 lines
1.3 KiB
Python
Executable file
import datetime
|
|
|
|
from django.conf import settings
|
|
from django.shortcuts import render
|
|
from django.views import View
|
|
|
|
class TasksPipeline(View):
|
|
|
|
def get(self, request):
|
|
data =self.stats
|
|
chart_name = "task_pipeline"
|
|
chart_type = "histogram"
|
|
|
|
context = {
|
|
"data": data,
|
|
"chart_name": chart_name,
|
|
"chart_type": chart_type,
|
|
}
|
|
return render(request, 'monitor/prometheus_data.html', context)
|
|
|
|
@property
|
|
def stats(self):
|
|
|
|
stats = settings.MONGOANALYTICSDB.nbanalytics.feed_fetches.aggregate([{
|
|
"$match": {
|
|
"date": {
|
|
"$gt": datetime.datetime.now() - datetime.timedelta(minutes=5),
|
|
},
|
|
},
|
|
}, {
|
|
"$group": {
|
|
"_id": 1,
|
|
"feed_fetch": {"$avg": "$feed_fetch"},
|
|
"feed_process": {"$avg": "$feed_process"},
|
|
"page": {"$avg": "$page"},
|
|
"icon": {"$avg": "$icon"},
|
|
"total": {"$avg": "$total"},
|
|
},
|
|
}])
|
|
stats = list(stats)
|
|
if stats:
|
|
print(stats)
|
|
return list(stats)[0]
|
|
else:
|
|
return {}
|