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
800c21e4
Commit
800c21e4
authored
Nov 21, 2022
by
jithu.tagore
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update infra_as_service_monitor.py
parent
0512efed
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
5 deletions
+7
-5
infra_as_service_monitor.py
infra_as_service_monitor.py
+7
-5
No files found.
infra_as_service_monitor.py
View file @
800c21e4
...
@@ -43,7 +43,7 @@ restart_status_mail = config.getboolean("service", "include_restart_status")
...
@@ -43,7 +43,7 @@ restart_status_mail = config.getboolean("service", "include_restart_status")
restart_max_count
=
config
.
getint
(
"service"
,
"restart_max_count"
)
restart_max_count
=
config
.
getint
(
"service"
,
"restart_max_count"
)
meta_file_path
=
config
.
get
(
"kafka"
,
"meta_file_path"
)
meta_file_path
=
config
.
get
(
"kafka"
,
"meta_file_path"
)
meta_file_name
=
config
.
get
(
"kafka"
,
"meta_file_name"
)
meta_file_name
=
config
.
get
(
"kafka"
,
"meta_file_name"
)
resent_time
=
config
.
get
(
"mail_configure"
,
"resent_time"
)
resent_time
=
float
(
config
.
get
(
"mail_configure"
,
"resent_time"
)
)
telegram
=
config
.
get
(
"telegram"
,
"enable_alerts"
)
telegram
=
config
.
get
(
"telegram"
,
"enable_alerts"
)
mqtt
=
config
.
get
(
"mqtt"
,
"mqtt_enable"
)
mqtt
=
config
.
get
(
"mqtt"
,
"mqtt_enable"
)
mqtt_broker
=
config
.
get
(
"mqtt"
,
"mqtt_broker"
)
mqtt_broker
=
config
.
get
(
"mqtt"
,
"mqtt_broker"
)
...
@@ -187,6 +187,7 @@ def docker_container():
...
@@ -187,6 +187,7 @@ def docker_container():
for
each
in
container_list
:
for
each
in
container_list
:
try
:
try
:
container
=
docker_client
.
containers
.
get
(
each
)
container
=
docker_client
.
containers
.
get
(
each
)
container_id
=
str
(
container
.
id
)[
0
:
8
]
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
:
...
@@ -196,7 +197,7 @@ def docker_container():
...
@@ -196,7 +197,7 @@ def docker_container():
end_date
=
datetime
.
datetime
.
now
(
tz
=
datetime
.
timezone
.
utc
)
end_date
=
datetime
.
datetime
.
now
(
tz
=
datetime
.
timezone
.
utc
)
calculated_time
=
(
end_date
.
astimezone
(
datetime
.
timezone
.
utc
)
-
start_date
.
astimezone
(
calculated_time
=
(
end_date
.
astimezone
(
datetime
.
timezone
.
utc
)
-
start_date
.
astimezone
(
datetime
.
timezone
.
utc
))
.
total_seconds
()
datetime
.
timezone
.
utc
))
.
total_seconds
()
container_id
=
str
(
container
.
id
)[
0
:
8
]
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"
)
...
@@ -253,12 +254,14 @@ def docker_container():
...
@@ -253,12 +254,14 @@ def docker_container():
timing
=
str
(
round
(
calculated_time
))
+
" Minutes ago"
timing
=
str
(
round
(
calculated_time
))
+
" Minutes ago"
else
:
else
:
timing
=
str
(
round
(
calculated_time
))
+
" Minutes ago"
timing
=
str
(
round
(
calculated_time
))
+
" Minutes ago"
data
.
append
([
container
.
name
,
container
.
id
,
container
.
attrs
[
"State"
][
"Status"
],
timing
])
data
.
append
([
container
.
name
,
container
_
id
,
container
.
attrs
[
"State"
][
"Status"
],
timing
])
else
:
else
:
containers
=
docker_client
.
containers
.
list
(
all
=
True
)
containers
=
docker_client
.
containers
.
list
(
all
=
True
)
for
each
in
containers
:
for
each
in
containers
:
container_id
=
str
(
each
.
id
)[
0
:
8
]
if
each
.
attrs
[
"State"
][
"Status"
]
==
"restarting"
or
each
.
attrs
[
"State"
][
"Status"
]
==
"exited"
:
if
each
.
attrs
[
"State"
][
"Status"
]
==
"restarting"
or
each
.
attrs
[
"State"
][
"Status"
]
==
"exited"
:
end
=
each
.
attrs
[
"State"
][
"FinishedAt"
]
end
=
each
.
attrs
[
"State"
][
"FinishedAt"
]
...
@@ -266,7 +269,6 @@ def docker_container():
...
@@ -266,7 +269,6 @@ def docker_container():
end_date
=
datetime
.
datetime
.
now
(
tz
=
datetime
.
timezone
.
utc
)
end_date
=
datetime
.
datetime
.
now
(
tz
=
datetime
.
timezone
.
utc
)
calculated_time
=
(
end_date
.
astimezone
(
datetime
.
timezone
.
utc
)
-
start_date
.
astimezone
(
calculated_time
=
(
end_date
.
astimezone
(
datetime
.
timezone
.
utc
)
-
start_date
.
astimezone
(
datetime
.
timezone
.
utc
))
.
total_seconds
()
datetime
.
timezone
.
utc
))
.
total_seconds
()
container_id
=
str
(
each
.
id
)[
0
:
8
]
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"
)
...
@@ -325,7 +327,7 @@ def docker_container():
...
@@ -325,7 +327,7 @@ def docker_container():
timing
=
str
(
round
(
calculated_time
))
+
" Minutes ago"
timing
=
str
(
round
(
calculated_time
))
+
" Minutes ago"
else
:
else
:
timing
=
str
(
round
(
calculated_time
))
+
" Minutes ago"
timing
=
str
(
round
(
calculated_time
))
+
" Minutes ago"
data
.
append
([
each
.
name
,
each
.
id
,
each
.
attrs
[
"State"
][
"Status"
],
timing
])
data
.
append
([
each
.
name
,
container_
id
,
each
.
attrs
[
"State"
][
"Status"
],
timing
])
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
info
(
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