Last active
June 9, 2016 21:26
-
-
Save alunux/03c45b0be5ea451ecbe7b33114788ab2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from xmlrpc.server import SimpleXMLRPCServer | |
from shutil import disk_usage | |
from json import dumps | |
kilo_bytes = 1024 | |
mega_bytes = 1024 * 1024 | |
giga_bytes = 1024 * 1024 * 1024 | |
def send_to_client(): | |
(total, used, free) = disk_usage ("/") | |
server_disk_usage = { | |
"Total" : { | |
"kB" : float(total)/kilo_bytes, | |
"MB" : float(total)/mega_bytes, | |
"GB" : float(total)/giga_bytes | |
}, | |
"Used" : { | |
"kB" : float(used)/kilo_bytes, | |
"MB" : float(used)/mega_bytes, | |
"GB" : float(used)/giga_bytes | |
}, | |
"Free" : { | |
"kB" : float(free)/kilo_bytes, | |
"MB" : float(free)/mega_bytes, | |
"GB" : float(free)/giga_bytes | |
} | |
} | |
return dumps(server_disk_usage) | |
def main(): | |
server = SimpleXMLRPCServer(("", 13000)) | |
server.register_function(send_to_client,"server_disk_usage") | |
server.serve_forever() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment