Commit 0512efed authored by jithu.tagore's avatar jithu.tagore

Update infra_as_service_monitor.py

parent cb7794a3
...@@ -190,9 +190,7 @@ def docker_container(): ...@@ -190,9 +190,7 @@ def docker_container():
except docker.errors.NotFound as exc: except docker.errors.NotFound as exc:
print(f"Check container name!\n{exc.explanation}") print(f"Check container name!\n{exc.explanation}")
else: else:
if container.attrs["State"]["Status"] == "restarting" or container.attrs["State"]["Status"] == \ if container.attrs["State"]["Status"] == "restarting" or container.attrs["State"]["Status"] == "exited":
"exited":
container_restart.append(container)
end = container.attrs["State"]["FinishedAt"] end = container.attrs["State"]["FinishedAt"]
start_date = dateutil.parser.isoparse(end) start_date = dateutil.parser.isoparse(end)
end_date = datetime.datetime.now(tz=datetime.timezone.utc) end_date = datetime.datetime.now(tz=datetime.timezone.utc)
...@@ -202,6 +200,7 @@ def docker_container(): ...@@ -202,6 +200,7 @@ def docker_container():
if container_id not in df["Services"].values: if container_id not in df["Services"].values:
df.loc[len(df.index)] = [container_id, datetime.datetime.now(), 0] df.loc[len(df.index)] = [container_id, datetime.datetime.now(), 0]
df.to_csv("check_time.csv") df.to_csv("check_time.csv")
container_restart.append(container_id)
else: else:
found = list(df[df['Services'] == container_id]["Time"]) found = list(df[df['Services'] == container_id]["Time"])
timer = datetime.datetime.now() - found[0] timer = datetime.datetime.now() - found[0]
...@@ -211,6 +210,7 @@ def docker_container(): ...@@ -211,6 +210,7 @@ def docker_container():
df.loc[df['Services'] == container_id, "Ago"] = 0 df.loc[df['Services'] == container_id, "Ago"] = 0
df.loc[df['Services'] == container_id, "Time"] = datetime.datetime.now() df.loc[df['Services'] == container_id, "Time"] = datetime.datetime.now()
df.to_csv("check_time.csv") df.to_csv("check_time.csv")
container_restart.append(container_id)
else: else:
df.loc[df['Services'] == container_id, "Ago"] = str(timer) df.loc[df['Services'] == container_id, "Ago"] = str(timer)
df.to_csv("check_time.csv") df.to_csv("check_time.csv")
...@@ -270,6 +270,8 @@ def docker_container(): ...@@ -270,6 +270,8 @@ def docker_container():
if container_id not in df["Services"].values: if container_id not in df["Services"].values:
df.loc[len(df.index)] = [container_id,datetime.datetime.now(),0] df.loc[len(df.index)] = [container_id,datetime.datetime.now(),0]
df.to_csv("check_time.csv") df.to_csv("check_time.csv")
container_restart.append(each)
else: else:
found = list(df[df['Services']==container_id]["Time"]) found = list(df[df['Services']==container_id]["Time"])
timer=datetime.datetime.now()-found[0] timer=datetime.datetime.now()-found[0]
...@@ -649,6 +651,7 @@ if __name__ == '__main__': ...@@ -649,6 +651,7 @@ if __name__ == '__main__':
df.loc[len(df.index)] = [container_id, datetime.datetime.now(), 0] df.loc[len(df.index)] = [container_id, datetime.datetime.now(), 0]
Ram_send_mail=1 Ram_send_mail=1
df.to_csv("check_time.csv") df.to_csv("check_time.csv")
send_mail = True
else: else:
found = list(df[df['Services'] == container_id]["Time"]) found = list(df[df['Services'] == container_id]["Time"])
timer = datetime.datetime.now() - found[0] timer = datetime.datetime.now() - found[0]
...@@ -677,6 +680,7 @@ if __name__ == '__main__': ...@@ -677,6 +680,7 @@ if __name__ == '__main__':
if container_id not in df["Services"].values: if container_id not in df["Services"].values:
df.loc[len(df.index)] = [container_id, datetime.datetime.now(), 0] df.loc[len(df.index)] = [container_id, datetime.datetime.now(), 0]
df.to_csv("check_time.csv") df.to_csv("check_time.csv")
send_mail = True
else: else:
found = list(df[df['Services'] == container_id]["Time"]) found = list(df[df['Services'] == container_id]["Time"])
timer = datetime.datetime.now() - found[0] timer = datetime.datetime.now() - found[0]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment