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
|
return prom
|
||||||
|
|
||||||
def uptime_extractor(uptime):
|
def uptime_extractor(uptime):
|
||||||
|
# extract day
|
||||||
|
try:
|
||||||
|
day = re.findall("(^|\D)(\d+)d",uptime)[0][1]
|
||||||
|
day = int(day)
|
||||||
|
except:
|
||||||
|
hour = 0
|
||||||
|
|
||||||
# extract hour
|
# extract hour
|
||||||
try:
|
try:
|
||||||
re_h = re.compile("(\d)h")
|
hour = re.findall("(^|\D)(\d+)h",uptime)[0][1]
|
||||||
hour = re_h.match(uptime).group(1)
|
|
||||||
hour = int(hour)
|
hour = int(hour)
|
||||||
except:
|
except:
|
||||||
hour = 0
|
hour = 0
|
||||||
|
|
||||||
# extract minute
|
# extract minute
|
||||||
try:
|
try:
|
||||||
re_m = re.compile("(\d)m")
|
minute = re.findall("(^|\D)(\d+)m",uptime)[0][1]
|
||||||
minute = re_m.match(uptime).group(1)
|
|
||||||
minute = int(minute)
|
minute = int(minute)
|
||||||
except:
|
except:
|
||||||
minute = 0
|
minute = 0
|
||||||
|
|
||||||
# extract second
|
# extract second
|
||||||
try:
|
try:
|
||||||
re_s = re.compile("(\d)s")
|
second = re.findall("(^|\D)(\d+)s",uptime)[0][1]
|
||||||
second = re_s.match(uptime).group(1)
|
|
||||||
second = int(second)
|
second = int(second)
|
||||||
except:
|
except:
|
||||||
second = 0
|
second = 0
|
||||||
|
|
||||||
# remove all value extracted
|
# remove all value extracted
|
||||||
uptime = 3600 * hour - minute * 60 - second
|
uptime = 86400 * day + 3600 * hour + minute * 60 + second
|
||||||
|
|
||||||
return uptime
|
return uptime
|
||||||
|
|
||||||
|
|
||||||
def prom_resource_request(data,prom,routerip):
|
def prom_resource_request(data,prom,routerip):
|
||||||
print(data)
|
|
||||||
name = 'routeros_resource_version'
|
name = 'routeros_resource_version'
|
||||||
version = data['version']
|
version = data['version']
|
||||||
value = 1
|
value = 1
|
||||||
|
@ -157,7 +159,6 @@ if __name__ == '__main__':
|
||||||
prom_cpu = init_prometheus_cpu_metrics(data_cpu,router_ip)
|
prom_cpu = init_prometheus_cpu_metrics(data_cpu,router_ip)
|
||||||
|
|
||||||
# system/resource
|
# system/resource
|
||||||
print("resource")
|
|
||||||
data_resource = mkt_restapi(router_ip,router_username,router_password,'system/resource')
|
data_resource = mkt_restapi(router_ip,router_username,router_password,'system/resource')
|
||||||
prom_resource = init_prometheus_resource(data_resource,router_ip)
|
prom_resource = init_prometheus_resource(data_resource,router_ip)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue