aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorCédric Bonhomme <kimble.mandel+bitbucket@gmail.com>2015-08-03 23:55:46 +0200
committerCédric Bonhomme <kimble.mandel+bitbucket@gmail.com>2015-08-03 23:55:46 +0200
commitcdbd573500a365e290e88b50d7b0c2355b7f7e19 (patch)
tree25ede52ae4b02a2377ae40d2c146c7ed2e9abe2a /scripts
parentThe numver ov values of the splited string is variable (sometimes the charset... (diff)
parentsqlalchemy was requesting icons everytime feed where listed (diff)
downloadnewspipe-cdbd573500a365e290e88b50d7b0c2355b7f7e19.tar.gz
newspipe-cdbd573500a365e290e88b50d7b0c2355b7f7e19.tar.bz2
newspipe-cdbd573500a365e290e88b50d7b0c2355b7f7e19.zip
Merged in jaesivsm/pyaggr3g470r (pull request #20)
perf improvement
Diffstat (limited to 'scripts')
-rw-r--r--scripts/__init__.py0
-rw-r--r--scripts/probes.py74
2 files changed, 74 insertions, 0 deletions
diff --git a/scripts/__init__.py b/scripts/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/scripts/__init__.py
diff --git a/scripts/probes.py b/scripts/probes.py
new file mode 100644
index 00000000..4c632184
--- /dev/null
+++ b/scripts/probes.py
@@ -0,0 +1,74 @@
+#!/usr/bin/python3
+import sys
+from datetime import datetime, timedelta
+from flask.ext.script import Command, Option
+
+from pyaggr3g470r.controllers \
+ import UserController, FeedController, ArticleController
+DEFAULT_HEADERS = {'Content-Type': 'application/json', 'User-Agent': 'munin'}
+LATE_AFTER = 60
+FETCH_RATE = 3
+
+
+class AbstractMuninPlugin(Command):
+ urn = None
+
+ def execute(self):
+ raise NotImplementedError()
+
+ def config(self):
+ raise NotImplementedError()
+
+ def get_options(self):
+ if sys.argv[-1] == 'config':
+ return [Option(dest='config', default=sys.argv[-1] == 'config')]
+ return []
+
+ def run(self, config=False):
+ if config:
+ self.config()
+ else:
+ self.execute()
+
+
+class FeedProbe(AbstractMuninPlugin):
+
+ def config(self):
+ print("graph_title PyAgg - Feeds counts")
+ print("graph_vlabel feeds")
+ print("feeds.label Late feeds")
+ print("feeds_total.label Total feeds")
+ print("feeds.warning 15")
+ print("feeds.critical 30")
+ print("graph_category web")
+ print("graph_scale yes")
+
+ def execute(self):
+ delta = datetime.now() - timedelta(minutes=LATE_AFTER + FETCH_RATE + 1)
+ total = FeedController().read().count()
+
+ print("feeds.value %d"
+ % len(FeedController().list_late(delta, limit=total)))
+ print("feeds_total.value %d" % FeedController().read().count())
+
+
+class ArticleProbe(AbstractMuninPlugin):
+
+ def config(self):
+ print("graph_title Pyagg - Articles adding rate")
+ print("graph_vlabel Articles per sec")
+ print("articles.label Overall rate")
+ print("articles.type DERIVE")
+ print("articles.min 0")
+ for id_ in sorted(user.id for user in UserController().read()):
+ print("articles_user_%s.label Rate for user %s" % (id_, id_))
+ print("articles_user_%s.type DERIVE" % id_)
+ print("articles_user_%s.min 0" % id_)
+ print("graph_category web")
+ print("graph_scale yes")
+
+ def execute(self):
+ counts = ArticleController().count_by_user_id()
+ print("articles.value %s" % sum(counts.values()))
+ for user, count in counts.items():
+ print("articles_user_%s.value %s" % (user, count))
bgstack15