make gunicorn_memory_status and gunicorn_status python3 compatible

This commit is contained in:
Doctor 2023-05-31 18:30:12 +02:00
parent 5b7d70510f
commit 4b9a11c854
2 changed files with 19 additions and 18 deletions

View File

@ -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:

View File

@ -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()