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
|
|
|
|
|
2021-01-12 15:52:10 -05:00
|
|
|
os.environ["DJANGO_SETTINGS_MODULE"] = "newsblur_web.settings"
|
2012-09-27 12:12:22 -07:00
|
|
|
|
|
|
|
|
2024-04-24 09:43:56 -04:00
|
|
|
class NBMuninGraph(MuninGraph):
|
2012-09-27 12:12:22 -07:00
|
|
|
@property
|
|
|
|
def graph_config(self):
|
|
|
|
graph = {
|
2024-04-24 09:43:56 -04:00
|
|
|
"graph_category": "NewsBlur",
|
|
|
|
"graph_title": "NewsBlur Task Codes",
|
|
|
|
"graph_vlabel": "Status codes on feed fetch",
|
|
|
|
"graph_args": "-l 0",
|
2012-09-27 12:12:22 -07:00
|
|
|
}
|
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"], s["_id"]) for s in stats)))
|
|
|
|
graph["graph_order"] = " ".join(sorted(("_%s" % s["_id"]) for s in stats))
|
2012-09-27 16:51:52 -07:00
|
|
|
|
2012-09-27 12:12:22 -07:00
|
|
|
return graph
|
|
|
|
|
|
|
|
def calculate_metrics(self):
|
2024-04-24 09:43:56 -04:00
|
|
|
servers = dict((("_%s" % s["_id"], s["feeds"]) for s in self.stats))
|
|
|
|
|
2012-09-27 12:12:22 -07:00
|
|
|
return servers
|
2024-04-24 09:43:56 -04:00
|
|
|
|
2012-09-27 12:12:22 -07:00
|
|
|
@property
|
|
|
|
def stats(self):
|
|
|
|
import datetime
|
2024-04-24 09:50:42 -04:00
|
|
|
|
2012-09-27 12:12:22 -07: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": "$feed_code",
|
|
|
|
"feeds": {"$sum": 1},
|
|
|
|
},
|
2012-09-27 12:12:22 -07:00
|
|
|
},
|
2024-04-24 09:43:56 -04:00
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2016-11-20 13:11:56 -08:00
|
|
|
return list(stats)
|
2012-09-27 12:12:22 -07:00
|
|
|
|
2024-04-24 09:43:56 -04:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2012-09-27 12:12:22 -07:00
|
|
|
NBMuninGraph().run()
|