Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
docker_health_check
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
jithu.tagore
docker_health_check
Commits
7e9c0bb2
Commit
7e9c0bb2
authored
Nov 18, 2022
by
jithu.tagore
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update infra_as_service_monitor.py
parent
e0242f5a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
37 deletions
+16
-37
infra_as_service_monitor.py
infra_as_service_monitor.py
+16
-37
No files found.
infra_as_service_monitor.py
View file @
7e9c0bb2
...
...
@@ -187,25 +187,14 @@ def docker_container():
except
docker
.
errors
.
NotFound
as
exc
:
print
(
f
"Check container name!
\n
{exc.explanation}"
)
else
:
if
container
.
attrs
[
"State"
][
"Status"
]
==
"restarting"
or
container
.
attrs
[
"State"
][
"Status"
]
==
"exited"
:
if
container
.
attrs
[
"State"
][
"Status"
]
==
"restarting"
or
container
.
attrs
[
"State"
][
"Status"
]
==
\
"exited"
:
container_restart
.
append
(
container
)
end
=
container
.
attrs
[
"State"
][
"FinishedAt"
]
start_date
=
dateutil
.
parser
.
isoparse
(
end
)
end_date
=
datetime
.
datetime
.
now
(
tz
=
datetime
.
timezone
.
utc
)
calculated_time
=
(
end_date
.
astimezone
(
datetime
.
timezone
.
utc
)
-
start_date
.
astimezone
(
datetime
.
timezone
.
utc
))
.
total_seconds
()
if
container
not
in
df
[
"service"
]
.
values
:
df
.
loc
[
len
(
df
.
index
)]
=
[
container
,
datetime
.
now
(),
0
]
if
len
(
df
[
df
[
"Ago"
]
<
3600
]
.
index
)
>
0
:
found
=
list
(
df
[
df
[
'service'
]
==
container
][
"Time"
])
timer
=
datetime
.
datetime
.
now
()
-
found
[
0
]
timer
=
timer
.
total_seconds
()
df
.
loc
[
df
[
'service'
]
==
container
,
"Ago"
]
=
timer
else
:
container_restart
.
append
(
container
)
df
.
loc
[
df
[
'service'
]
==
container
,
"Ago"
]
=
0
df
.
loc
[
df
[
'service'
]
==
container
,
"Time"
]
=
datetime
.
datetime
.
now
()
if
container
.
attrs
[
"State"
][
"Status"
]
==
"running"
:
start
=
container
.
attrs
[
"State"
][
"StartedAt"
]
start_date
=
dateutil
.
parser
.
isoparse
(
start
)
...
...
@@ -220,23 +209,23 @@ def docker_container():
elif
calculated_time
>
3600
:
calculated_time
=
calculated_time
/
calculated_time
if
round
(
calculated_time
)
>
1
:
timing
=
str
(
round
(
calculated_time
))
+
" Hours
Ago
"
timing
=
str
(
round
(
calculated_time
))
+
" Hours"
else
:
timing
=
str
(
round
(
calculated_time
))
+
" Hour
Ago
"
timing
=
str
(
round
(
calculated_time
))
+
" Hour"
elif
round
(
calculated_time
)
<
60
:
if
round
(
calculated_time
)
>
1
:
timing
=
str
(
round
(
calculated_time
))
+
" Seconds
Ago
"
timing
=
str
(
round
(
calculated_time
))
+
" Seconds"
else
:
timing
=
str
(
round
(
calculated_time
))
+
" Second
Ago
"
timing
=
str
(
round
(
calculated_time
))
+
" Second"
elif
calculated_time
>
60
:
calculated_time
=
calculated_time
/
60
if
round
(
calculated_time
)
>
1
:
timing
=
str
(
round
(
calculated_time
))
+
" Minutes
Ago
"
timing
=
str
(
round
(
calculated_time
))
+
" Minutes"
else
:
timing
=
str
(
round
(
calculated_time
))
+
" Minutes
Ago
"
timing
=
str
(
round
(
calculated_time
))
+
" Minutes"
data
.
append
([
container
.
name
,
container
.
id
,
container
.
attrs
[
"State"
][
"Status"
],
timing
])
...
...
@@ -244,22 +233,12 @@ def docker_container():
containers
=
docker_client
.
containers
.
list
(
all
=
True
)
for
each
in
containers
:
if
each
.
attrs
[
"State"
][
"Status"
]
==
"restarting"
or
each
.
attrs
[
"State"
][
"Status"
]
==
"exited"
:
container_restart
.
append
(
each
)
end
=
each
.
attrs
[
"State"
][
"FinishedAt"
]
start_date
=
dateutil
.
parser
.
isoparse
(
end
)
end_date
=
datetime
.
datetime
.
now
(
tz
=
datetime
.
timezone
.
utc
)
calculated_time
=
(
end_date
.
astimezone
(
datetime
.
timezone
.
utc
)
-
start_date
.
astimezone
(
datetime
.
timezone
.
utc
))
.
total_seconds
()
if
each
not
in
df
[
"service"
]
.
values
:
df
.
loc
[
len
(
df
.
index
)]
=
[
each
,
datetime
.
now
(),
0
]
if
len
(
df
[
df
[
"Ago"
]
<
3600
]
.
index
)
>
0
:
found
=
list
(
df
[
df
[
'service'
]
==
each
][
"Time"
])
timer
=
datetime
.
datetime
.
now
()
-
found
[
0
]
timer
=
timer
.
total_seconds
()
df
.
loc
[
df
[
'service'
]
==
each
,
"Ago"
]
=
timer
else
:
container_restart
.
append
(
each
)
df
.
loc
[
df
[
'service'
]
==
each
,
"Ago"
]
=
0
df
.
loc
[
df
[
'service'
]
==
each
,
"Time"
]
=
datetime
.
datetime
.
now
()
if
each
.
attrs
[
"State"
][
"Status"
]
==
"running"
:
start
=
each
.
attrs
[
"State"
][
"StartedAt"
]
start_date
=
dateutil
.
parser
.
isoparse
(
start
)
...
...
@@ -273,23 +252,23 @@ def docker_container():
elif
calculated_time
>
3600
:
calculated_time
=
calculated_time
/
3600
if
round
(
calculated_time
)
>
1
:
timing
=
str
(
round
(
calculated_time
))
+
" Hours
Ago
"
timing
=
str
(
round
(
calculated_time
))
+
" Hours"
else
:
timing
=
str
(
round
(
calculated_time
))
+
" Hour
Ago
"
timing
=
str
(
round
(
calculated_time
))
+
" Hour"
elif
round
(
calculated_time
)
<
60
:
if
round
(
calculated_time
)
>
1
:
timing
=
str
(
round
(
calculated_time
))
+
" Seconds
Ago
"
timing
=
str
(
round
(
calculated_time
))
+
" Seconds"
else
:
timing
=
str
(
round
(
calculated_time
))
+
" Second
Ago
"
timing
=
str
(
round
(
calculated_time
))
+
" Second"
elif
calculated_time
>
60
:
calculated_time
=
calculated_time
/
60
if
round
(
calculated_time
)
>
1
:
timing
=
str
(
round
(
calculated_time
))
+
" Minutes
Ago
"
timing
=
str
(
round
(
calculated_time
))
+
" Minutes"
else
:
timing
=
str
(
round
(
calculated_time
))
+
" Minutes
Ago
"
timing
=
str
(
round
(
calculated_time
))
+
" Minutes"
data
.
append
([
each
.
name
,
each
.
id
,
each
.
attrs
[
"State"
][
"Status"
],
timing
])
except
Exception
as
e
:
logger
.
info
(
e
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment