fix uptime extractor
This commit is contained in:
parent
95ced1a318
commit
5d89070220
21
main.py
21
main.py
|
@ -78,38 +78,40 @@ def init_prometheus_resource(data,router_ip):
|
|||
return prom
|
||||
|
||||
def uptime_extractor(uptime):
|
||||
# extract day
|
||||
try:
|
||||
day = re.findall("(^|\D)(\d+)d",uptime)[0][1]
|
||||
day = int(day)
|
||||
except:
|
||||
hour = 0
|
||||
|
||||
# extract hour
|
||||
try:
|
||||
re_h = re.compile("(\d)h")
|
||||
hour = re_h.match(uptime).group(1)
|
||||
hour = re.findall("(^|\D)(\d+)h",uptime)[0][1]
|
||||
hour = int(hour)
|
||||
except:
|
||||
hour = 0
|
||||
|
||||
# extract minute
|
||||
try:
|
||||
re_m = re.compile("(\d)m")
|
||||
minute = re_m.match(uptime).group(1)
|
||||
minute = re.findall("(^|\D)(\d+)m",uptime)[0][1]
|
||||
minute = int(minute)
|
||||
except:
|
||||
minute = 0
|
||||
|
||||
# extract second
|
||||
try:
|
||||
re_s = re.compile("(\d)s")
|
||||
second = re_s.match(uptime).group(1)
|
||||
second = re.findall("(^|\D)(\d+)s",uptime)[0][1]
|
||||
second = int(second)
|
||||
except:
|
||||
second = 0
|
||||
|
||||
# remove all value extracted
|
||||
uptime = 3600 * hour - minute * 60 - second
|
||||
uptime = 86400 * day + 3600 * hour + minute * 60 + second
|
||||
|
||||
return uptime
|
||||
|
||||
|
||||
def prom_resource_request(data,prom,routerip):
|
||||
print(data)
|
||||
name = 'routeros_resource_version'
|
||||
version = data['version']
|
||||
value = 1
|
||||
|
@ -157,7 +159,6 @@ if __name__ == '__main__':
|
|||
prom_cpu = init_prometheus_cpu_metrics(data_cpu,router_ip)
|
||||
|
||||
# system/resource
|
||||
print("resource")
|
||||
data_resource = mkt_restapi(router_ip,router_username,router_password,'system/resource')
|
||||
prom_resource = init_prometheus_resource(data_resource,router_ip)
|
||||
|
||||
|
|
Loading…
Reference in a new issue