From 4b9a11c85494d3003213cce1657fa0c82a5fe4d4 Mon Sep 17 00:00:00 2001 From: Doctor Date: Wed, 31 May 2023 18:30:12 +0200 Subject: [PATCH] make gunicorn_memory_status and gunicorn_status python3 compatible --- plugins/gunicorn/gunicorn_memory_status | 16 ++++++++-------- plugins/gunicorn/gunicorn_status | 21 +++++++++++---------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/plugins/gunicorn/gunicorn_memory_status b/plugins/gunicorn/gunicorn_memory_status index b8948e35..38f08af0 100755 --- a/plugins/gunicorn/gunicorn_memory_status +++ b/plugins/gunicorn/gunicorn_memory_status @@ -45,7 +45,7 @@ class GunicornMemoryStatus(): raise Exception("Couldn't read gunicorn pid information") def print_total_memory(self): - print ('total_memory.value %d' % self._get_total_memory()) + print('total_memory.value %d' % self._get_total_memory()) def _get_master_pid(self): master_pid_file = open(GUNICORN_PID_PATH) @@ -83,11 +83,11 @@ def print_config(): 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 appserver" - print "total_memory.label Total Memory" + print(graph_title) + print("graph_args --base 1024 -l 0") + print("graph_vlabel Megabytes") + print("graph_category appserver") + print("total_memory.label Total Memory") if __name__ == "__main__": if len(sys.argv) == 2 and sys.argv[1] == 'config': @@ -95,9 +95,9 @@ if __name__ == "__main__": elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': try: open(GUNICORN_PID_PATH).close() - print "yes" + print("yes") except: - print "no" + print("no") # Some docs say it'll be called with fetch, some say no arg at all elif len(sys.argv) == 1 or (len(sys.argv) == 2 and sys.argv[1] == 'fetch'): try: diff --git a/plugins/gunicorn/gunicorn_status b/plugins/gunicorn/gunicorn_status index 1d19179a..ac6f648c 100755 --- a/plugins/gunicorn/gunicorn_status +++ b/plugins/gunicorn/gunicorn_status @@ -50,10 +50,10 @@ class GunicornStatus(): sys.exit("Couldn't read gunicorn pid") def print_total_workers(self): - print ('total_workers.value %d' % self._worker_count()) + print('total_workers.value %d' % self._worker_count()) def print_idle_workers(self): - print ('idle_workers.value %d' % self._idle_worker_count()) + print('idle_workers.value %d' % self._idle_worker_count()) def _get_master_pid(self): @@ -72,6 +72,7 @@ class GunicornStatus(): def _idle_worker_count(self): idle_workers = 0 for pid in self.worker_pids: + pid = int(pid) before = self._cpu_time(pid) sleep(0.50) after = self._cpu_time(pid) @@ -98,12 +99,12 @@ def print_config(): graph_title = "graph_title Gunicorn - Status" if instance: graph_title = "%s - %s" % (graph_title, instance) - print graph_title - print "graph_args -l 0" - print "graph_vlabel Number of workers" - print "graph_category appserver" - print "total_workers.label Total Workers" - print "idle_workers.label Idle Workers" + print(graph_title) + print("graph_args -l 0") + print("graph_vlabel Number of workers") + print("graph_category appserver") + print("total_workers.label Total Workers") + print("idle_workers.label Idle Workers") if __name__ == "__main__": if len(sys.argv) == 2 and sys.argv[1] == 'config': @@ -111,9 +112,9 @@ if __name__ == "__main__": elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': try: open(GUNICORN_PID_PATH).close() - print "yes" + print("yes") except: - print "no" + print("no") # Some docs say it'll be called with fetch, some say no arg at all elif len(sys.argv) == 1 or (len(sys.argv) == 2 and sys.argv[1] == 'fetch'): status = GunicornStatus()