mirror of
https://github.com/KevinMidboe/Node-Com-Handler.git
synced 2025-10-29 17:50:27 +00:00
Re-writing uptime for python3 with more general outputhandling
This commit is contained in:
BIN
__pycache__/ipLookup.cpython-34.pyc
Normal file
BIN
__pycache__/ipLookup.cpython-34.pyc
Normal file
Binary file not shown.
BIN
__pycache__/uptime.cpython-34.pyc
Normal file
BIN
__pycache__/uptime.cpython-34.pyc
Normal file
Binary file not shown.
12
testUptime.py
Executable file
12
testUptime.py
Executable file
@@ -0,0 +1,12 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# @Author: KevinMidboe
|
||||||
|
# @Date: 2016-11-22 16:08:17
|
||||||
|
# @Last Modified by: KevinMidboe
|
||||||
|
# @Last Modified time: 2016-11-22 17:07:52
|
||||||
|
|
||||||
|
import uptime
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
uptimeClass = uptime.uptime()
|
||||||
|
print(uptimeClass)
|
||||||
34
uptime.py
Normal file
34
uptime.py
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# @Author: KevinMidboe
|
||||||
|
# @Date: 2016-11-22 16:05:18
|
||||||
|
# @Last Modified by: KevinMidboe
|
||||||
|
# @Last Modified time: 2016-11-22 17:07:41
|
||||||
|
|
||||||
|
import subprocess, re
|
||||||
|
|
||||||
|
class uptime(object):
|
||||||
|
"""docstring for uptime"""
|
||||||
|
def __init__(self):
|
||||||
|
super(uptime, self).__init__()
|
||||||
|
raw = subprocess.Popen('uptime', stdout=subprocess.PIPE)
|
||||||
|
output, error = raw.communicate()
|
||||||
|
uptimeList = output.decode('utf-8').split(', ')
|
||||||
|
|
||||||
|
self.duration(uptimeList[0])
|
||||||
|
self.users(uptimeList[2])
|
||||||
|
self.load(uptimeList[3])
|
||||||
|
|
||||||
|
def duration(self, outputString):
|
||||||
|
self.duration = re.sub(r'.*up ', '', outputString)
|
||||||
|
|
||||||
|
def users(self, outputString):
|
||||||
|
self.users = outputString
|
||||||
|
|
||||||
|
def load(self, outputString):
|
||||||
|
loadValues = re.sub(r'.*load averages: ', '', outputString)
|
||||||
|
self.load = re.sub(r'\n', '', loadValues)
|
||||||
|
self.load_minute, self.load_fiveminute, self.load_fiftenminute = self.load.split(' ')
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return str(self.__class__) + ": " + str(self.__dict__)
|
||||||
Reference in New Issue
Block a user