From 7d58abe5c53f41010a78ccbcd2a38978b459cee3 Mon Sep 17 00:00:00 2001 From: Johann Schmitz Date: Wed, 2 Dec 2015 06:31:52 +0100 Subject: [PATCH] Added instance name for gunicorn_memory_status plugin if linked as gunicorn_memory_status_INSTANCE or gunicorn_INSTANCE_memory_status --- plugins/gunicorn/gunicorn_memory_status | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/plugins/gunicorn/gunicorn_memory_status b/plugins/gunicorn/gunicorn_memory_status index 49e8719c..4cdbb58b 100755 --- a/plugins/gunicorn/gunicorn_memory_status +++ b/plugins/gunicorn/gunicorn_memory_status @@ -22,7 +22,7 @@ """ -import sys, os +import sys, os, re from subprocess import check_output # set path to your gunicorn pid @@ -44,11 +44,9 @@ class GunicornMemoryStatus(): except: raise Exception("Couldn't read gunicorn pid information") - def print_total_memory(self): print ('total_memory.value %d' % self._get_total_memory()) - def _get_master_pid(self): master_pid_file = open(GUNICORN_PID_PATH) self.master_pid = master_pid_file.read().rstrip() @@ -74,7 +72,18 @@ class GunicornMemoryStatus(): return worker_memory_usage def print_config(): - print "graph_title Gunicorn - Memory Usage" + instance = None + name = os.path.basename(sys.argv[0]) + if name != "gunicorn_memory_status": + for r in ("^gunicorn_(.*?)_memory_status$", "^gunicorn_memory_status_(.*?)$"): + m = re.match(r, name, re.IGNORECASE) + if m: + instance = m.group(1) + break + graph_title = "graph_title Gunicorn - Memory Usage" + if instance: + graph_title = "%s - %s" % (graph_title, instance) + print graph_title print "graph_args --base 1024 -l 0" print "graph_vlabel Megabytes" print "graph_category gunicorn"