Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
3d593f63
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 搜索 >>
提交
3d593f63
编写于
2月 25, 2018
作者:
N
nicolargo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Gzip ==> Defalte
上级
f5fbd659
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
26 addition
and
28 deletion
+26
-28
NEWS
NEWS
+1
-1
glances/outputs/glances_bottle.py
glances/outputs/glances_bottle.py
+25
-27
未找到文件。
NEWS
浏览文件 @
3d593f63
...
...
@@ -14,7 +14,7 @@ Enhancements and new features:
* Make plugins disable and export CLI option dynamical #1173
* Add a light mode for the console UI #1165
* Refactor InfluxDB (API is now stable) #1166
* Add
Gzip
compression support to the RestAPI #1182
* Add
deflate
compression support to the RestAPI #1182
* Remove graph export from Glances #1206
* Add a code of conduct for Glances project's participants #1211
* Context switches bottleneck identification #1212
...
...
glances/outputs/glances_bottle.py
浏览文件 @
3d593f63
...
...
@@ -26,10 +26,8 @@ import tempfile
from
io
import
open
import
webbrowser
import
zlib
import
struct
import
time
from
glances.compat
import
nativestr
,
u
,
b
,
long
from
glances.compat
import
b
from
glances.timer
import
Timer
from
glances.logger
import
logger
...
...
@@ -40,24 +38,24 @@ except ImportError:
sys
.
exit
(
2
)
def
gzip_
compress
(
func
):
"""Compress result with
Gzip
algorithm if the client ask for it."""
def
compress
(
func
):
"""Compress result with
deflate
algorithm if the client ask for it."""
def
wrapper
(
*
args
,
**
kwargs
):
"""Wrapper that take one function and return the
result Gzipped
."""
"""Wrapper that take one function and return the
compressed result
."""
ret
=
func
(
*
args
,
**
kwargs
)
logger
.
debug
(
'Receive {} {} request with header: {}'
.
format
(
request
.
method
,
request
.
url
,
[
'{}: {}'
.
format
(
h
,
request
.
headers
.
get
(
h
))
for
h
in
request
.
headers
.
keys
()]
))
if
'
gzip
'
in
request
.
headers
.
get
(
'Accept-Encoding'
,
''
):
response
.
headers
[
'Content-Encoding'
]
=
'
gzip
'
ret
=
compress
(
ret
)
if
'
deflate
'
in
request
.
headers
.
get
(
'Accept-Encoding'
,
''
):
response
.
headers
[
'Content-Encoding'
]
=
'
deflate
'
ret
=
deflate_
compress
(
ret
)
else
:
response
.
headers
[
'Content-Encoding'
]
=
'identity'
return
ret
def
compress
(
data
,
compress_level
=
6
):
def
deflate_
compress
(
data
,
compress_level
=
6
):
"""Compress given data using the DEFLATE algorithm"""
# Init compression
zobj
=
zlib
.
compressobj
(
compress_level
,
...
...
@@ -240,7 +238,7 @@ class GlancesBottle(object):
# Return the static file
return
static_file
(
filepath
,
root
=
self
.
STATIC_PATH
)
@
gzip_
compress
@
compress
def
_api_help
(
self
):
"""Glances API RESTful implementation.
...
...
@@ -256,7 +254,7 @@ class GlancesBottle(object):
abort
(
404
,
"Cannot get help view data (%s)"
%
str
(
e
))
return
plist
@
gzip_
compress
@
compress
def
_api_plugins
(
self
):
"""Glances API RESTFul implementation.
...
...
@@ -294,7 +292,7 @@ class GlancesBottle(object):
abort
(
404
,
"Cannot get plugin list (%s)"
%
str
(
e
))
return
plist
@
gzip_
compress
@
compress
def
_api_all
(
self
):
"""Glances API RESTful implementation.
...
...
@@ -324,7 +322,7 @@ class GlancesBottle(object):
return
statval
@
gzip_
compress
@
compress
def
_api_all_limits
(
self
):
"""Glances API RESTful implementation.
...
...
@@ -342,7 +340,7 @@ class GlancesBottle(object):
abort
(
404
,
"Cannot get limits (%s)"
%
(
str
(
e
)))
return
limits
@
gzip_
compress
@
compress
def
_api_all_views
(
self
):
"""Glances API RESTful implementation.
...
...
@@ -360,7 +358,7 @@ class GlancesBottle(object):
abort
(
404
,
"Cannot get views (%s)"
%
(
str
(
e
)))
return
limits
@
gzip_
compress
@
compress
def
_api
(
self
,
plugin
):
"""Glances API RESTful implementation.
...
...
@@ -384,7 +382,7 @@ class GlancesBottle(object):
abort
(
404
,
"Cannot get plugin %s (%s)"
%
(
plugin
,
str
(
e
)))
return
statval
@
gzip_
compress
@
compress
def
_api_history
(
self
,
plugin
,
nb
=
0
):
"""Glances API RESTful implementation.
...
...
@@ -409,7 +407,7 @@ class GlancesBottle(object):
abort
(
404
,
"Cannot get plugin history %s (%s)"
%
(
plugin
,
str
(
e
)))
return
statval
@
gzip_
compress
@
compress
def
_api_limits
(
self
,
plugin
):
"""Glances API RESTful implementation.
...
...
@@ -433,7 +431,7 @@ class GlancesBottle(object):
abort
(
404
,
"Cannot get limits for plugin %s (%s)"
%
(
plugin
,
str
(
e
)))
return
ret
@
gzip_
compress
@
compress
def
_api_views
(
self
,
plugin
):
"""Glances API RESTful implementation.
...
...
@@ -457,7 +455,7 @@ class GlancesBottle(object):
abort
(
404
,
"Cannot get views for plugin %s (%s)"
%
(
plugin
,
str
(
e
)))
return
ret
@
gzip_
compress
@
compress
def
_api_itemvalue
(
self
,
plugin
,
item
,
value
=
None
,
history
=
False
,
nb
=
0
):
"""Father method for _api_item and _api_value."""
response
.
content_type
=
'application/json'
...
...
@@ -488,7 +486,7 @@ class GlancesBottle(object):
return
ret
@
gzip_
compress
@
compress
def
_api_item
(
self
,
plugin
,
item
):
"""Glances API RESTful implementation.
...
...
@@ -500,7 +498,7 @@ class GlancesBottle(object):
"""
return
self
.
_api_itemvalue
(
plugin
,
item
)
@
gzip_
compress
@
compress
def
_api_item_history
(
self
,
plugin
,
item
,
nb
=
0
):
"""Glances API RESTful implementation.
...
...
@@ -512,7 +510,7 @@ class GlancesBottle(object):
"""
return
self
.
_api_itemvalue
(
plugin
,
item
,
history
=
True
,
nb
=
int
(
nb
))
@
gzip_
compress
@
compress
def
_api_value
(
self
,
plugin
,
item
,
value
):
"""Glances API RESTful implementation.
...
...
@@ -523,7 +521,7 @@ class GlancesBottle(object):
"""
return
self
.
_api_itemvalue
(
plugin
,
item
,
value
)
@
gzip_
compress
@
compress
def
_api_config
(
self
):
"""Glances API RESTful implementation.
...
...
@@ -540,7 +538,7 @@ class GlancesBottle(object):
abort
(
404
,
"Cannot get config (%s)"
%
str
(
e
))
return
args_json
@
gzip_
compress
@
compress
def
_api_config_item
(
self
,
item
):
"""Glances API RESTful implementation.
...
...
@@ -562,7 +560,7 @@ class GlancesBottle(object):
abort
(
404
,
"Cannot get config item (%s)"
%
str
(
e
))
return
args_json
@
gzip_
compress
@
compress
def
_api_args
(
self
):
"""Glances API RESTful implementation.
...
...
@@ -581,7 +579,7 @@ class GlancesBottle(object):
abort
(
404
,
"Cannot get args (%s)"
%
str
(
e
))
return
args_json
@
gzip_
compress
@
compress
def
_api_args_item
(
self
,
item
):
"""Glances API RESTful implementation.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录