NewsBlur/utils/munin/newsblur_tasks_times.py

63 lines
1.7 KiB
Python
Raw Normal View History

2020-12-03 14:05:32 -05:00
#!/srv/newsblur/venv/newsblur3/bin/python
2020-12-10 12:40:12 -05:00
import os
2024-04-24 09:43:56 -04:00
2024-04-24 09:50:42 -04:00
from utils.munin.base import MuninGraph
os.environ["DJANGO_SETTINGS_MODULE"] = "newsblur_web.settings"
2020-12-10 12:42:12 -05:00
import django
2024-04-24 09:43:56 -04:00
2020-12-10 12:42:12 -05:00
django.setup()
2024-04-24 09:43:56 -04:00
class NBMuninGraph(MuninGraph):
@property
def graph_config(self):
graph = {
2024-04-24 09:43:56 -04:00
"graph_category": "NewsBlur",
"graph_title": "NewsBlur Task Server Times",
"graph_vlabel": "Feed fetch time / server",
"graph_args": "-l 0",
}
2012-09-27 16:51:52 -07:00
stats = self.stats
2024-04-24 09:43:56 -04:00
graph.update(dict((("%s.label" % s["_id"].replace("-", ""), s["_id"]) for s in stats)))
graph.update(dict((("%s.draw" % s["_id"].replace("-", ""), "LINE1") for s in stats)))
graph["graph_order"] = " ".join(sorted(s["_id"].replace("-", "") for s in stats))
2012-09-27 16:51:52 -07:00
return graph
def calculate_metrics(self):
2024-04-24 09:43:56 -04:00
servers = dict((("%s" % s["_id"].replace("-", ""), s["total"]) for s in self.stats))
return servers
2024-04-24 09:43:56 -04:00
@property
def stats(self):
import datetime
2024-04-24 09:50:42 -04:00
from django.conf import settings
2024-04-24 09:43:56 -04:00
stats = settings.MONGOANALYTICSDB.nbanalytics.feed_fetches.aggregate(
[
{
"$match": {
"date": {
"$gt": datetime.datetime.now() - datetime.timedelta(minutes=5),
},
},
},
{
"$group": {
"_id": "$server",
"total": {"$avg": "$total"},
},
},
2024-04-24 09:43:56 -04:00
]
)
return list(stats)
2024-04-24 09:43:56 -04:00
if __name__ == "__main__":
NBMuninGraph().run()