Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
fec8c8e9
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 搜索 >>
提交
fec8c8e9
编写于
10月 12, 2017
作者:
N
nicolargo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
A way to have only REST API available and disable WEB GUI access #1149
上级
54449653
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
77 addition
and
36 deletion
+77
-36
NEWS
NEWS
+1
-0
glances/main.py
glances/main.py
+9
-3
glances/outputs/glances_bottle.py
glances/outputs/glances_bottle.py
+67
-33
未找到文件。
NEWS
浏览文件 @
fec8c8e9
...
...
@@ -7,6 +7,7 @@ Version 3.0
Enhancements and new features:
* A way to have only REST API available and disable WEB GUI access #1149
* Docker module doesn't export details about stopped containers #1152
Bugs corrected:
...
...
glances/main.py
浏览文件 @
fec8c8e9
...
...
@@ -55,20 +55,24 @@ Examples of use:
Monitor local machine (standalone mode):
$ glances
Monitor local machine with the Web interface
(Web UI)
:
Monitor local machine with the Web interface
and start Restful server
:
$ glances -w
Glances web server started on http://0.0.0.0:61208/
Only start Restful API (without the WebUI):
$ glances -w --disable-webui
Glances API available on http://0.0.0.0:61208/api/
Monitor local machine and export stats to a CSV file (standalone mode):
$ glances --export-csv /tmp/glances.csv
Monitor local machine and export stats to a InfluxDB server with 5s refresh time (standalone mode):
$ glances -t 5 --export-influxdb
Start a Glances server (server mode):
Start a Glances
XML/RCP
server (server mode):
$ glances -s
Connect Glances to a Glances server (client mode):
Connect Glances to a Glances
XML/RCP
server (client mode):
$ glances -c <ip_server>
Connect Glances to a Glances server and export stats to a StatsD server (client mode):
...
...
@@ -138,6 +142,8 @@ Examples of use:
dest
=
'disable_raid'
,
help
=
'disable RAID module'
)
parser
.
add_argument
(
'--disable-sensors'
,
action
=
'store_true'
,
default
=
False
,
dest
=
'disable_sensors'
,
help
=
'disable sensors module'
)
parser
.
add_argument
(
'--disable-webui'
,
action
=
'store_true'
,
default
=
False
,
dest
=
'disable_webui'
,
help
=
'disable the Web Interface'
)
parser
.
add_argument
(
'--disable-wifi'
,
action
=
'store_true'
,
default
=
False
,
dest
=
'disable_wifi'
,
help
=
'disable wifi module'
)
parser
.
add_argument
(
'-0'
,
'--disable-irix'
,
action
=
'store_true'
,
default
=
False
,
...
...
glances/outputs/glances_bottle.py
浏览文件 @
fec8c8e9
...
...
@@ -40,6 +40,8 @@ class GlancesBottle(object):
"""This class manages the Bottle Web server."""
API_VERSION
=
'2'
def
__init__
(
self
,
config
=
None
,
args
=
None
):
# Init config
self
.
config
=
config
...
...
@@ -59,6 +61,10 @@ class GlancesBottle(object):
# Load configuration file
self
.
load_config
(
config
)
# Set the bind URL
self
.
bind_url
=
'http://{}:{}/'
.
format
(
self
.
args
.
bind_address
,
self
.
args
.
port
)
# Init Bottle
self
.
_app
=
Bottle
()
# Enable CORS (issue #479)
...
...
@@ -103,30 +109,58 @@ class GlancesBottle(object):
def
_route
(
self
):
"""Define route."""
self
.
_app
.
route
(
'/'
,
method
=
"GET"
,
callback
=
self
.
_index
)
self
.
_app
.
route
(
'/<refresh_time:int>'
,
method
=
[
"GET"
],
callback
=
self
.
_index
)
# REST API
self
.
_app
.
route
(
'/api/2/config'
,
method
=
"GET"
,
callback
=
self
.
_api_config
)
self
.
_app
.
route
(
'/api/2/config/<item>'
,
method
=
"GET"
,
callback
=
self
.
_api_config_item
)
self
.
_app
.
route
(
'/api/2/args'
,
method
=
"GET"
,
callback
=
self
.
_api_args
)
self
.
_app
.
route
(
'/api/2/args/<item>'
,
method
=
"GET"
,
callback
=
self
.
_api_args_item
)
self
.
_app
.
route
(
'/api/2/help'
,
method
=
"GET"
,
callback
=
self
.
_api_help
)
self
.
_app
.
route
(
'/api/2/pluginslist'
,
method
=
"GET"
,
callback
=
self
.
_api_plugins
)
self
.
_app
.
route
(
'/api/2/all'
,
method
=
"GET"
,
callback
=
self
.
_api_all
)
self
.
_app
.
route
(
'/api/2/all/limits'
,
method
=
"GET"
,
callback
=
self
.
_api_all_limits
)
self
.
_app
.
route
(
'/api/2/all/views'
,
method
=
"GET"
,
callback
=
self
.
_api_all_views
)
self
.
_app
.
route
(
'/api/2/<plugin>'
,
method
=
"GET"
,
callback
=
self
.
_api
)
self
.
_app
.
route
(
'/api/2/<plugin>/history'
,
method
=
"GET"
,
callback
=
self
.
_api_history
)
self
.
_app
.
route
(
'/api/2/<plugin>/history/<nb:int>'
,
method
=
"GET"
,
callback
=
self
.
_api_history
)
self
.
_app
.
route
(
'/api/2/<plugin>/limits'
,
method
=
"GET"
,
callback
=
self
.
_api_limits
)
self
.
_app
.
route
(
'/api/2/<plugin>/views'
,
method
=
"GET"
,
callback
=
self
.
_api_views
)
self
.
_app
.
route
(
'/api/2/<plugin>/<item>'
,
method
=
"GET"
,
callback
=
self
.
_api_item
)
self
.
_app
.
route
(
'/api/2/<plugin>/<item>/history'
,
method
=
"GET"
,
callback
=
self
.
_api_item_history
)
self
.
_app
.
route
(
'/api/2/<plugin>/<item>/history/<nb:int>'
,
method
=
"GET"
,
callback
=
self
.
_api_item_history
)
self
.
_app
.
route
(
'/api/2/<plugin>/<item>/<value>'
,
method
=
"GET"
,
callback
=
self
.
_api_value
)
self
.
_app
.
route
(
'/<filepath:path>'
,
method
=
"GET"
,
callback
=
self
.
_resource
)
self
.
_app
.
route
(
'/api/%s/config'
%
self
.
API_VERSION
,
method
=
"GET"
,
callback
=
self
.
_api_config
)
self
.
_app
.
route
(
'/api/%s/config/<item>'
%
self
.
API_VERSION
,
method
=
"GET"
,
callback
=
self
.
_api_config_item
)
self
.
_app
.
route
(
'/api/%s/args'
%
self
.
API_VERSION
,
method
=
"GET"
,
callback
=
self
.
_api_args
)
self
.
_app
.
route
(
'/api/%s/args/<item>'
%
self
.
API_VERSION
,
method
=
"GET"
,
callback
=
self
.
_api_args_item
)
self
.
_app
.
route
(
'/api/%s/help'
%
self
.
API_VERSION
,
method
=
"GET"
,
callback
=
self
.
_api_help
)
self
.
_app
.
route
(
'/api/%s/pluginslist'
%
self
.
API_VERSION
,
method
=
"GET"
,
callback
=
self
.
_api_plugins
)
self
.
_app
.
route
(
'/api/%s/all'
%
self
.
API_VERSION
,
method
=
"GET"
,
callback
=
self
.
_api_all
)
self
.
_app
.
route
(
'/api/%s/all/limits'
%
self
.
API_VERSION
,
method
=
"GET"
,
callback
=
self
.
_api_all_limits
)
self
.
_app
.
route
(
'/api/%s/all/views'
%
self
.
API_VERSION
,
method
=
"GET"
,
callback
=
self
.
_api_all_views
)
self
.
_app
.
route
(
'/api/%s/<plugin>'
%
self
.
API_VERSION
,
method
=
"GET"
,
callback
=
self
.
_api
)
self
.
_app
.
route
(
'/api/%s/<plugin>/history'
%
self
.
API_VERSION
,
method
=
"GET"
,
callback
=
self
.
_api_history
)
self
.
_app
.
route
(
'/api/%s/<plugin>/history/<nb:int>'
%
self
.
API_VERSION
,
method
=
"GET"
,
callback
=
self
.
_api_history
)
self
.
_app
.
route
(
'/api/%s/<plugin>/limits'
%
self
.
API_VERSION
,
method
=
"GET"
,
callback
=
self
.
_api_limits
)
self
.
_app
.
route
(
'/api/%s/<plugin>/views'
%
self
.
API_VERSION
,
method
=
"GET"
,
callback
=
self
.
_api_views
)
self
.
_app
.
route
(
'/api/%s/<plugin>/<item>'
%
self
.
API_VERSION
,
method
=
"GET"
,
callback
=
self
.
_api_item
)
self
.
_app
.
route
(
'/api/%s/<plugin>/<item>/history'
%
self
.
API_VERSION
,
method
=
"GET"
,
callback
=
self
.
_api_item_history
)
self
.
_app
.
route
(
'/api/%s/<plugin>/<item>/history/<nb:int>'
%
self
.
API_VERSION
,
method
=
"GET"
,
callback
=
self
.
_api_item_history
)
self
.
_app
.
route
(
'/api/%s/<plugin>/<item>/<value>'
%
self
.
API_VERSION
,
method
=
"GET"
,
callback
=
self
.
_api_value
)
bindmsg
=
'Glances Restful API Server started on {}api/{}/'
.
format
(
self
.
bind_url
,
self
.
API_VERSION
)
logger
.
info
(
bindmsg
)
# WEB UI
if
not
self
.
args
.
disable_webui
:
self
.
_app
.
route
(
'/'
,
method
=
"GET"
,
callback
=
self
.
_index
)
self
.
_app
.
route
(
'/<refresh_time:int>'
,
method
=
[
"GET"
],
callback
=
self
.
_index
)
self
.
_app
.
route
(
'/<filepath:path>'
,
method
=
"GET"
,
callback
=
self
.
_resource
)
bindmsg
=
'Glances Web User Interface started on {}'
.
format
(
self
.
bind_url
)
logger
.
info
(
bindmsg
)
else
:
logger
.
info
(
'The WebUI is disable (--disable-webui)'
)
print
(
bindmsg
)
def
start
(
self
,
stats
):
"""Start the bottle."""
...
...
@@ -137,18 +171,18 @@ class GlancesBottle(object):
self
.
plugins_list
=
self
.
stats
.
getAllPlugins
()
# Bind the Bottle TCP address/port
bindurl
=
'http://{}:{}/'
.
format
(
self
.
args
.
bind_address
,
self
.
args
.
port
)
bindmsg
=
'Glances web server started on {}'
.
format
(
bindurl
)
logger
.
info
(
bindmsg
)
print
(
bindmsg
)
if
self
.
args
.
open_web_browser
:
# Implementation of the issue #946
# Try to open the Glances Web UI in the default Web browser if:
# 1) --open-web-browser option is used
# 2) Glances standalone mode is running on Windows OS
webbrowser
.
open
(
bindurl
,
new
=
2
,
autoraise
=
1
)
self
.
_app
.
run
(
host
=
self
.
args
.
bind_address
,
port
=
self
.
args
.
port
,
quiet
=
not
self
.
args
.
debug
)
webbrowser
.
open
(
self
.
bind_url
,
new
=
2
,
autoraise
=
1
)
self
.
_app
.
run
(
host
=
self
.
args
.
bind_address
,
port
=
self
.
args
.
port
,
quiet
=
not
self
.
args
.
debug
)
def
end
(
self
):
"""End the bottle."""
...
...
@@ -188,7 +222,7 @@ class GlancesBottle(object):
def
_api_plugins
(
self
):
"""
@api {get} /api/
2
/pluginslist Get plugins list
@api {get} /api/
%s
/pluginslist Get plugins list
@apiVersion 2.0
@apiName pluginslist
@apiGroup plugin
...
...
@@ -488,7 +522,7 @@ class GlancesBottle(object):
try
:
# Get the JSON value of the args' dict
# Use vars to convert namespace to dict
# Source: https://docs.python.org/
2
/library/functions.html#vars
# Source: https://docs.python.org/
%s
/library/functions.html#vars
args_json
=
json
.
dumps
(
vars
(
self
.
args
))
except
Exception
as
e
:
abort
(
404
,
"Cannot get args (%s)"
%
str
(
e
))
...
...
@@ -510,7 +544,7 @@ class GlancesBottle(object):
try
:
# Get the JSON value of the args' dict
# Use vars to convert namespace to dict
# Source: https://docs.python.org/
2
/library/functions.html#vars
# Source: https://docs.python.org/
%s
/library/functions.html#vars
args_json
=
json
.
dumps
(
vars
(
self
.
args
)[
item
])
except
Exception
as
e
:
abort
(
404
,
"Cannot get args item (%s)"
%
str
(
e
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录