from datetime import datetime

import psutil
import pymongo
import socket

conn = pymongo.MongoClient()
db = conn.myserver

def myapp_isup(name):
    up = 'false'
    if name.startswith('myserver'):
        for conn in psutil.net_connections():
            if conn.laddr.port == 10000:
                up = 'true'
                break
    else:
        up = 'NA'
    return up

def main():
    server_name = socket.gethostname()
    doc = {
        'server': server_name,
        'date' : datetime.now(),
        'cpu' : psutil.cpu_percent(interval=1),
        'disk_app' : psutil.disk_usage('/AppDocs').free,
        'disk_root' : psutil.disk_usage('/').free,
        'phymem' : psutil.virtual_memory().free,
        'myapp': myapp_isup(server_name)
    }
    db.monitor.insert(doc)

if __name__ == '__main__':
    main()

@@ -121,24 +121,19 @@
 er%0A%0Adef 
-myapp_
 is
+_
 up(name)
@@ -147,15 +147,13 @@
 p = 
-'f
+F
 alse
-'
 %0A   
@@ -297,14 +297,12 @@
 p = 
-'t
+T
 rue
-'
 %0A   
@@ -347,12 +347,12 @@
 p = 
-'NA'
+None
 %0A   
@@ -586,11 +586,8 @@
 /App
-Doc
 s').
@@ -656,14 +656,14 @@
    '
-phy
 mem
+ory
 ' : 
@@ -713,16 +713,11 @@
 p': 
-myapp_
 is
+_
 up(s

clean python code