Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
ops
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhangwei
ops
Commits
a498c5d6
Commit
a498c5d6
authored
Aug 15, 2017
by
zhangwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加docker监控程序
parent
fffcc82b
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
102 additions
and
1 deletions
+102
-1
ops.iml
.idea/ops.iml
+2
-1
check_container_info.py
docker/check_container_info.py
+69
-0
docker_low_discovery.sh
docker/docker_low_discovery.sh
+31
-0
No files found.
.idea/ops.iml
View file @
a498c5d6
...
...
@@ -2,7 +2,7 @@
<module
type=
"PYTHON_MODULE"
version=
"4"
>
<component
name=
"NewModuleRootManager"
>
<content
url=
"file://$MODULE_DIR$"
/>
<orderEntry
type=
"
inheritedJdk
"
/>
<orderEntry
type=
"
jdk"
jdkName=
"Python 2.7.13 (D:\Python27\python.exe)"
jdkType=
"Python SDK
"
/>
<orderEntry
type=
"sourceFolder"
forTests=
"false"
/>
</component>
</module>
\ No newline at end of file
docker/check_container_info.py
0 → 100644
View file @
a498c5d6
#!/usr/bin/python
# coding:utf-8
import
os
import
sys
import
subprocess
import
docker
def
check_container_info
(
container_name
,
container_item
):
null
=
''
get_container_info
=
docker_client
.
stats
(
container_name
)
old_result
=
eval
(
get_container_info
.
next
())
new_result
=
eval
(
get_container_info
.
next
())
get_container_info
.
close
()
if
container_item
==
"cpu_total_usage"
:
result
=
new_result
[
'cpu_stats'
][
'cpu_usage'
][
'total_usage'
]
-
old_result
[
'cpu_stats'
][
'cpu_usage'
][
'total_usage'
]
elif
container_item
==
"system_cpu_usage"
:
result
=
new_result
[
'cpu_stats'
][
'system_cpu_usage'
]
-
old_result
[
'cpu_stats'
][
'system_cpu_usage'
]
elif
container_item
==
"cpu_percent"
:
total_cpu_usage
=
new_result
[
'cpu_stats'
][
'cpu_usage'
][
'total_usage'
]
-
old_result
[
'cpu_stats'
][
'cpu_usage'
][
'total_usage'
]
sys_cpu_usage
=
new_result
[
'cpu_stats'
][
'system_cpu_usage'
]
-
old_result
[
'cpu_stats'
][
'system_cpu_usage'
]
cpu_num
=
len
(
old_result
[
'cpu_stats'
][
'cpu_usage'
][
'percpu_usage'
])
result
=
round
(
float
(
total_cpu_usage
)
/
float
(
sys_cpu_usage
)
*
cpu_num
*
100.0
,
2
)
elif
container_item
==
"mem_usage"
:
result
=
new_result
[
'memory_stats'
][
'usage'
]
elif
container_item
==
"mem_limit"
:
result
=
new_result
[
'memory_stats'
][
'limit'
]
elif
container_item
==
"total_cache"
:
result
=
new_result
[
'memory_stats'
][
'stats'
][
'total_cache'
]
elif
container_item
==
"total_swap"
:
result
=
new_result
[
'memory_stats'
][
'stats'
][
'total_swap'
]
elif
container_item
==
"mem_percent"
:
mem_usage
=
new_result
[
'memory_stats'
][
'usage'
]
mem_limit
=
new_result
[
'memory_stats'
][
'limit'
]
result
=
round
(
float
(
mem_usage
)
/
float
(
mem_limit
)
*
100.0
,
2
)
elif
container_item
==
"eth0_rx_byte"
:
result
=
new_result
[
'networks'
][
'eth0'
][
'rx_bytes'
]
-
old_result
[
'networks'
][
'eth0'
][
'rx_bytes'
]
elif
container_item
==
"eth0_tx_byte"
:
result
=
new_result
[
'networks'
][
'eth0'
][
'tx_bytes'
]
-
old_result
[
'networks'
][
'eth0'
][
'tx_bytes'
]
elif
container_item
==
"blk_io_read"
:
r_list
=
new_result
[
'blkio_stats'
][
'io_service_bytes_recursive'
]
for
r_dict
in
r_list
:
if
r_dict
[
'major'
]
==
253
and
r_dict
[
'op'
]
==
"Read"
and
r_dict
[
'minor'
]
==
0
:
result
=
r_dict
[
'value'
]
elif
container_item
==
"blk_io_write"
:
w_list
=
new_result
[
'blkio_stats'
][
'io_service_bytes_recursive'
]
for
w_dict
in
w_list
:
if
w_dict
[
'major'
]
==
253
and
w_dict
[
'op'
]
==
"Write"
and
w_dict
[
'minor'
]
==
0
:
result
=
w_dict
[
'value'
]
# block io queue ,目前没有使用,因为获取出来的值为空“[]”
elif
container_item
==
"blk_io_queue"
:
result
=
new_result
[
'blkio_stats'
][
'io_queue_recursive'
]
# block io wait time,目前没有使用,因为获取出来的值为空“[]”
elif
container_item
==
"blk_io_wait"
:
result
=
new_result
[
'blkio_stats'
][
'io_wait_time_recursive'
]
return
result
if
__name__
==
"__main__"
:
docker_client
=
docker
.
Client
(
base_url
=
'unix://var/run/docker.sock'
,
version
=
'1.23'
)
container_name
=
sys
.
argv
[
1
]
container_item
=
sys
.
argv
[
2
]
global
result
print
check_container_info
(
container_name
,
container_item
)
\ No newline at end of file
docker/docker_low_discovery.sh
0 → 100644
View file @
a498c5d6
#!/bin/bash
#docker low-level discovery
docker
()
{
port
=(
$(
sudo
docker ps |grep
-v
"CONTAINER ID"
|awk
'{print $NF}'
)
)
printf
'{\n'
printf
'\t"data":[\n'
for
key
in
${
!port[@]
}
do
if
[[
"
${#
port
[@]
}
"
-gt
1
&&
"
${
key
}
"
-ne
"
$((${#
port
[@]
}
-
1
))
"
]]
;
then
printf
'\t {\n'
printf
"
\t\t\t\"
{#CONTAINERNAME}
\"
:
\"
${
port
[
${
key
}
]
}
\"
},
\n
"
else
[[
"
${
key
}
"
-eq
"((
${#
port
[@]
}
-1))"
]]
printf
'\t {\n'
printf
"
\t\t\t\"
{#CONTAINERNAME}
\"
:
\"
${
port
[
${
key
}
]
}
\"
}
\n
"
fi
done
printf
'\t ]\n'
printf
'}\n'
}
case
$1
in
docker
)
docker
;;
*
)
echo
"Usage:
`
basename
$0
`
{docker}"
;;
esac
\ No newline at end of file
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