make gunicorn_memory_status and gunicorn_status python3 compatible
This commit is contained in:
parent
5b7d70510f
commit
4b9a11c854
|
@ -45,7 +45,7 @@ class GunicornMemoryStatus():
|
||||||
raise Exception("Couldn't read gunicorn pid information")
|
raise Exception("Couldn't read gunicorn pid information")
|
||||||
|
|
||||||
def print_total_memory(self):
|
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):
|
def _get_master_pid(self):
|
||||||
master_pid_file = open(GUNICORN_PID_PATH)
|
master_pid_file = open(GUNICORN_PID_PATH)
|
||||||
|
@ -83,11 +83,11 @@ def print_config():
|
||||||
graph_title = "graph_title Gunicorn - Memory Usage"
|
graph_title = "graph_title Gunicorn - Memory Usage"
|
||||||
if instance:
|
if instance:
|
||||||
graph_title = "%s - %s" % (graph_title, instance)
|
graph_title = "%s - %s" % (graph_title, instance)
|
||||||
print graph_title
|
print(graph_title)
|
||||||
print "graph_args --base 1024 -l 0"
|
print("graph_args --base 1024 -l 0")
|
||||||
print "graph_vlabel Megabytes"
|
print("graph_vlabel Megabytes")
|
||||||
print "graph_category appserver"
|
print("graph_category appserver")
|
||||||
print "total_memory.label Total Memory"
|
print("total_memory.label Total Memory")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if len(sys.argv) == 2 and sys.argv[1] == 'config':
|
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':
|
elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf':
|
||||||
try:
|
try:
|
||||||
open(GUNICORN_PID_PATH).close()
|
open(GUNICORN_PID_PATH).close()
|
||||||
print "yes"
|
print("yes")
|
||||||
except:
|
except:
|
||||||
print "no"
|
print("no")
|
||||||
# Some docs say it'll be called with fetch, some say no arg at all
|
# 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'):
|
elif len(sys.argv) == 1 or (len(sys.argv) == 2 and sys.argv[1] == 'fetch'):
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -50,10 +50,10 @@ class GunicornStatus():
|
||||||
sys.exit("Couldn't read gunicorn pid")
|
sys.exit("Couldn't read gunicorn pid")
|
||||||
|
|
||||||
def print_total_workers(self):
|
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):
|
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):
|
def _get_master_pid(self):
|
||||||
|
@ -72,6 +72,7 @@ class GunicornStatus():
|
||||||
def _idle_worker_count(self):
|
def _idle_worker_count(self):
|
||||||
idle_workers = 0
|
idle_workers = 0
|
||||||
for pid in self.worker_pids:
|
for pid in self.worker_pids:
|
||||||
|
pid = int(pid)
|
||||||
before = self._cpu_time(pid)
|
before = self._cpu_time(pid)
|
||||||
sleep(0.50)
|
sleep(0.50)
|
||||||
after = self._cpu_time(pid)
|
after = self._cpu_time(pid)
|
||||||
|
@ -98,12 +99,12 @@ def print_config():
|
||||||
graph_title = "graph_title Gunicorn - Status"
|
graph_title = "graph_title Gunicorn - Status"
|
||||||
if instance:
|
if instance:
|
||||||
graph_title = "%s - %s" % (graph_title, instance)
|
graph_title = "%s - %s" % (graph_title, instance)
|
||||||
print graph_title
|
print(graph_title)
|
||||||
print "graph_args -l 0"
|
print("graph_args -l 0")
|
||||||
print "graph_vlabel Number of workers"
|
print("graph_vlabel Number of workers")
|
||||||
print "graph_category appserver"
|
print("graph_category appserver")
|
||||||
print "total_workers.label Total Workers"
|
print("total_workers.label Total Workers")
|
||||||
print "idle_workers.label Idle Workers"
|
print("idle_workers.label Idle Workers")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if len(sys.argv) == 2 and sys.argv[1] == 'config':
|
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':
|
elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf':
|
||||||
try:
|
try:
|
||||||
open(GUNICORN_PID_PATH).close()
|
open(GUNICORN_PID_PATH).close()
|
||||||
print "yes"
|
print("yes")
|
||||||
except:
|
except:
|
||||||
print "no"
|
print("no")
|
||||||
# Some docs say it'll be called with fetch, some say no arg at all
|
# 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'):
|
elif len(sys.argv) == 1 or (len(sys.argv) == 2 and sys.argv[1] == 'fetch'):
|
||||||
status = GunicornStatus()
|
status = GunicornStatus()
|
||||||
|
|
Loading…
Reference in New Issue