2021-04-27 07:56:02 -05:00
|
|
|
from django.shortcuts import render
|
2024-04-24 09:50:42 -04:00
|
|
|
from django.views import View
|
2021-03-26 13:28:03 -05:00
|
|
|
|
|
|
|
from apps.reader.models import UserSubscription
|
2024-04-24 09:50:42 -04:00
|
|
|
from apps.rss_feeds.models import Feed
|
2021-03-26 13:28:03 -05:00
|
|
|
from apps.social.models import MSocialProfile, MSocialSubscription
|
|
|
|
from apps.statistics.models import MStatistics
|
|
|
|
|
|
|
|
|
2024-04-24 09:43:56 -04:00
|
|
|
class Feeds(View):
|
2021-03-26 13:28:03 -05:00
|
|
|
def get(self, request):
|
2024-04-24 09:43:56 -04:00
|
|
|
feeds_count = MStatistics.get("munin:feeds_count")
|
2021-03-26 13:28:03 -05:00
|
|
|
if not feeds_count:
|
|
|
|
feeds_count = Feed.objects.all().count()
|
2024-04-24 09:43:56 -04:00
|
|
|
MStatistics.set("munin:feeds_count", feeds_count, 60 * 60 * 12)
|
2021-03-26 13:28:03 -05:00
|
|
|
|
2024-04-24 09:43:56 -04:00
|
|
|
subscriptions_count = MStatistics.get("munin:subscriptions_count")
|
2021-03-26 13:28:03 -05:00
|
|
|
if not subscriptions_count:
|
|
|
|
subscriptions_count = UserSubscription.objects.all().count()
|
2024-04-24 09:43:56 -04:00
|
|
|
MStatistics.set("munin:subscriptions_count", subscriptions_count, 60 * 60 * 12)
|
2021-03-26 13:28:03 -05:00
|
|
|
|
2021-04-27 07:56:02 -05:00
|
|
|
data = {
|
2024-04-24 09:43:56 -04:00
|
|
|
"feeds": feeds_count,
|
|
|
|
"subscriptions": subscriptions_count,
|
|
|
|
"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}'
|
2024-04-24 09:43:56 -04:00
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
|
2024-04-24 09:43:56 -04:00
|
|
|
return render(request, "monitor/prometheus_data.html", context, content_type="text/plain")
|