2021-03-26 13:28:03 -05:00
|
|
|
from django.views import View
|
2021-04-27 07:56:02 -05:00
|
|
|
from django.shortcuts import render
|
2021-03-26 13:28:03 -05:00
|
|
|
|
|
|
|
from apps.rss_feeds.models import Feed
|
|
|
|
from apps.reader.models import UserSubscription
|
|
|
|
from apps.social.models import MSocialProfile, MSocialSubscription
|
|
|
|
from apps.statistics.models import MStatistics
|
|
|
|
|
|
|
|
class Feeds(View):
|
|
|
|
|
|
|
|
def get(self, request):
|
|
|
|
|
|
|
|
feeds_count = MStatistics.get('munin:feeds_count')
|
|
|
|
if not feeds_count:
|
|
|
|
feeds_count = Feed.objects.all().count()
|
|
|
|
MStatistics.set('munin:feeds_count', feeds_count, 60*60*12)
|
|
|
|
|
|
|
|
subscriptions_count = MStatistics.get('munin:subscriptions_count')
|
|
|
|
if not subscriptions_count:
|
|
|
|
subscriptions_count = UserSubscription.objects.all().count()
|
|
|
|
MStatistics.set('munin:subscriptions_count', subscriptions_count, 60*60*12)
|
|
|
|
|
2021-04-27 07:56:02 -05:00
|
|
|
data = {
|
2021-03-26 13:28:03 -05:00
|
|
|
'feeds': feeds_count,
|
|
|
|
'subscriptions': subscriptions_count,
|
2021-05-04 14:36:03 -04:00
|
|
|
'profiles': MSocialProfile.objects._collection.count(),
|
|
|
|
'social_subscriptions': MSocialSubscription.objects._collection.count(),
|
2021-04-27 07:56:02 -05:00
|
|
|
}
|
2021-04-30 13:48:48 -05:00
|
|
|
chart_name = "feeds"
|
2021-05-03 07:56:47 -05:00
|
|
|
chart_type = "counter"
|
2021-05-03 09:27:28 -05:00
|
|
|
formatted_data = {}
|
|
|
|
for k, v in data.items():
|
|
|
|
formatted_data[k] = f'{chart_name}{{category="{k}"}} {v}'
|
|
|
|
|
2021-04-30 13:48:48 -05:00
|
|
|
context = {
|
2021-05-03 09:27:28 -05:00
|
|
|
"data": formatted_data,
|
2021-04-30 13:48:48 -05:00
|
|
|
"chart_name": chart_name,
|
|
|
|
"chart_type": chart_type,
|
|
|
|
}
|
|
|
|
|
2021-05-03 07:56:47 -05:00
|
|
|
return render(request, 'monitor/prometheus_data.html', context, content_type="text/plain")
|
2021-03-26 13:28:03 -05:00
|
|
|
|