Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
cc1dd36e
G
glances
项目概览
蜕变的菜鸟
/
glances
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
glances
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
cc1dd36e
编写于
3月 05, 2017
作者:
N
nicolargo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add timeout to requests requets...
上级
89e4d1f1
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
24 addition
and
17 deletion
+24
-17
glances/plugins/glances_cloud.py
glances/plugins/glances_cloud.py
+6
-2
glances/plugins/glances_docker.py
glances/plugins/glances_docker.py
+18
-15
未找到文件。
glances/plugins/glances_cloud.py
浏览文件 @
cc1dd36e
...
...
@@ -152,9 +152,13 @@ class ThreadAwsEc2Grabber(threading.Thread):
for
k
,
v
in
iteritems
(
self
.
AWS_EC2_API_METADATA
):
r_url
=
'{}/{}'
.
format
(
self
.
AWS_EC2_API_URL
,
v
)
try
:
r
=
requests
.
get
(
r_url
)
# Local request, a timeout of 3 seconds is OK
r
=
requests
.
get
(
r_url
,
timeout
=
3
)
except
requests
.
exceptions
.
ConnectTimeout
:
logger
.
debug
(
'cloud plugin - Connection to {} timed out'
.
format
(
r_url
))
break
except
Exception
as
e
:
logger
.
debug
(
'Can not connect to the AWS EC2 API {}'
.
format
(
r_url
,
e
))
logger
.
debug
(
'
cloud plugin -
Can not connect to the AWS EC2 API {}'
.
format
(
r_url
,
e
))
break
else
:
if
r
.
ok
:
...
...
glances/plugins/glances_docker.py
浏览文件 @
cc1dd36e
...
...
@@ -92,7 +92,7 @@ class Plugin(GlancesPlugin):
try
:
ret
=
self
.
stats
[
'containers'
]
except
KeyError
as
e
:
logger
.
debug
(
"Docker export error {}"
.
format
(
e
))
logger
.
debug
(
"
docker plugin -
Docker export error {}"
.
format
(
e
))
return
ret
def
__connect_old
(
self
,
version
):
...
...
@@ -107,7 +107,7 @@ class Plugin(GlancesPlugin):
init_docker
=
docker
.
Client
else
:
# Can not found init method (new API version ?)
logger
.
error
(
"Can not found any way to init the Docker API"
)
logger
.
error
(
"
docker plugin -
Can not found any way to init the Docker API"
)
return
None
# Init connection to the Docker API
try
:
...
...
@@ -138,36 +138,39 @@ class Plugin(GlancesPlugin):
# Check the server connection with the version() method
try
:
ret
.
version
()
except
requests
.
exceptions
.
ConnectTimeout
:
logger
.
debug
(
'docker plugin - Connection to {} timed out'
.
format
(
r_url
))
break
except
requests
.
exceptions
.
ConnectionError
as
e
:
# Connexion error (Docker not detected)
# Let this message in debug mode
logger
.
debug
(
"Can't connect to the Docker server (%s)"
%
e
)
logger
.
debug
(
"
docker plugin -
Can't connect to the Docker server (%s)"
%
e
)
return
None
except
docker
.
errors
.
APIError
as
e
:
if
version
is
None
:
# API error (Version mismatch ?)
logger
.
debug
(
"Docker API error (%s)"
%
e
)
logger
.
debug
(
"
docker plugin -
Docker API error (%s)"
%
e
)
# Try the connection with the server version
version
=
re
.
search
(
'(?:server API version|server)\:\ (.*)\)
\"
.*\)'
,
str
(
e
))
if
version
:
logger
.
debug
(
"Try connection with Docker API version %s"
%
version
.
group
(
1
))
logger
.
debug
(
"
docker plugin -
Try connection with Docker API version %s"
%
version
.
group
(
1
))
ret
=
self
.
connect
(
version
=
version
.
group
(
1
))
else
:
logger
.
debug
(
"Can not retreive Docker server version"
)
logger
.
debug
(
"
docker plugin -
Can not retreive Docker server version"
)
ret
=
None
else
:
# API error
logger
.
error
(
"Docker API error (%s)"
%
e
)
logger
.
error
(
"
docker plugin -
Docker API error (%s)"
%
e
)
ret
=
None
except
Exception
as
e
:
# Others exceptions...
# Connexion error (Docker not detected)
logger
.
error
(
"Can't connect to the Docker server (%s)"
%
e
)
logger
.
error
(
"
docker plugin -
Can't connect to the Docker server (%s)"
%
e
)
ret
=
None
# Log an info if Docker plugin is disabled
if
ret
is
None
:
logger
.
debug
(
"Docker plugin is disable because an error has been detected"
)
logger
.
debug
(
"
docker plugin -
Docker plugin is disable because an error has been detected"
)
return
ret
...
...
@@ -296,7 +299,7 @@ class Plugin(GlancesPlugin):
cpu_new
[
'nb_core'
]
=
len
(
all_stats
[
'cpu_stats'
][
'cpu_usage'
][
'percpu_usage'
]
or
[])
except
KeyError
as
e
:
# all_stats do not have CPU information
logger
.
debug
(
"Cannot grab CPU usage for container {} ({})"
.
format
(
container_id
,
e
))
logger
.
debug
(
"
docker plugin -
Cannot grab CPU usage for container {} ({})"
.
format
(
container_id
,
e
))
logger
.
debug
(
all_stats
)
else
:
# Previous CPU stats stored in the cpu_old variable
...
...
@@ -344,7 +347,7 @@ class Plugin(GlancesPlugin):
ret
[
'max_usage'
]
=
all_stats
[
'memory_stats'
][
'max_usage'
]
except
(
KeyError
,
TypeError
)
as
e
:
# all_stats do not have MEM information
logger
.
debug
(
"Cannot grab MEM usage for container {} ({})"
.
format
(
container_id
,
e
))
logger
.
debug
(
"
docker plugin -
Cannot grab MEM usage for container {} ({})"
.
format
(
container_id
,
e
))
logger
.
debug
(
all_stats
)
# Return the stats
return
ret
...
...
@@ -367,7 +370,7 @@ class Plugin(GlancesPlugin):
netcounters
=
all_stats
[
"networks"
]
except
KeyError
as
e
:
# all_stats do not have NETWORK information
logger
.
debug
(
"Cannot grab NET usage for container {} ({})"
.
format
(
container_id
,
e
))
logger
.
debug
(
"
docker plugin -
Cannot grab NET usage for container {} ({})"
.
format
(
container_id
,
e
))
logger
.
debug
(
all_stats
)
# No fallback available...
return
network_new
...
...
@@ -398,7 +401,7 @@ class Plugin(GlancesPlugin):
network_new
[
'cumulative_tx'
]
=
netcounters
[
"eth0"
][
"tx_bytes"
]
except
KeyError
as
e
:
# all_stats do not have INTERFACE information
logger
.
debug
(
"Cannot grab network interface usage for container {} ({})"
.
format
(
container_id
,
e
))
logger
.
debug
(
"
docker plugin -
Cannot grab network interface usage for container {} ({})"
.
format
(
container_id
,
e
))
logger
.
debug
(
all_stats
)
# Save stats to compute next bitrate
...
...
@@ -425,7 +428,7 @@ class Plugin(GlancesPlugin):
iocounters
=
all_stats
[
"blkio_stats"
]
except
KeyError
as
e
:
# all_stats do not have io information
logger
.
debug
(
"Cannot grab block IO usage for container {} ({})"
.
format
(
container_id
,
e
))
logger
.
debug
(
"
docker plugin -
Cannot grab block IO usage for container {} ({})"
.
format
(
container_id
,
e
))
logger
.
debug
(
all_stats
)
# No fallback available...
return
io_new
...
...
@@ -456,7 +459,7 @@ class Plugin(GlancesPlugin):
iow_old
=
[
i
for
i
in
self
.
iocounters_old
[
container_id
][
'io_service_bytes_recursive'
]
if
i
[
'op'
]
==
'Write'
][
0
][
'value'
]
except
(
IndexError
,
KeyError
)
as
e
:
# all_stats do not have io information
logger
.
debug
(
"Cannot grab block IO usage for container {} ({})"
.
format
(
container_id
,
e
))
logger
.
debug
(
"
docker plugin -
Cannot grab block IO usage for container {} ({})"
.
format
(
container_id
,
e
))
else
:
io_new
[
'time_since_update'
]
=
getTimeSinceLastUpdate
(
'docker_io_{}'
.
format
(
container_id
))
io_new
[
'ior'
]
=
ior
-
ior_old
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录