Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
c8fb2f48
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 搜索 >>
提交
c8fb2f48
编写于
11月 07, 2012
作者:
N
Nicolas Hennion
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Re-add the main() function
上级
8f3230a6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
46 addition
and
47 deletion
+46
-47
glances/glances.py
glances/glances.py
+46
-47
未找到文件。
glances/glances.py
浏览文件 @
c8fb2f48
...
...
@@ -26,6 +26,8 @@ __licence__ = "LGPL"
# Libraries
#==========
# Standard lib
import
os
import
sys
import
platform
...
...
@@ -34,19 +36,52 @@ import signal
import
time
from
datetime
import
datetime
,
timedelta
import
gettext
# Selective lib
try
:
# For Python v2.x
from
SimpleXMLRPCServer
import
SimpleXMLRPCRequestHandler
from
SimpleXMLRPCServer
import
SimpleXMLRPCServer
except
:
# For Python v3.x
from
xmlrpc.server
import
SimpleXMLRPCRequestHandler
from
xmlrpc.server
import
SimpleXMLRPCServer
import
json
import
collections
import
xmlrpclib
if
platform
.
system
()
!=
'Windows'
:
# Only import curses for non Windows OS
# Curses did not exist on Windows OS (shame on it)
try
:
import
curses
import
curses.panel
except
ImportError
:
print
(
_
(
'Curses module not found. Glances cannot start.'
))
print
()
sys
.
exit
(
1
)
try
:
import
psutil
except
ImportError
:
print
(
_
(
'PsUtil module not found. Glances cannot start.'
))
print
()
print
(
_
(
'On Ubuntu 12.04 or higher:'
))
print
(
_
(
'$ sudo apt-get install python-psutil'
))
print
()
print
(
_
(
'To install PsUtil using pip (as root):'
))
print
(
_
(
'# pip install psutil'
))
print
()
sys
.
exit
(
1
)
# International
#==============
gettext
.
install
(
__appname__
)
# Classes
#========
...
...
@@ -2354,12 +2389,7 @@ def signal_handler(signal, frame):
end
()
# Main
#=====
if
__name__
==
"__main__"
:
def
main
():
# Glances - Init stuff
######################
...
...
@@ -2367,6 +2397,8 @@ if __name__ == "__main__":
global
limits
,
logs
,
stats
,
screen
global
htmloutput
,
csvoutput
global
html_tag
,
csv_tag
,
server_tag
,
client_tag
global
psutil_get_cpu_percent_tag
,
psutil_get_io_counter_tag
,
psutil_mem_usage_tag
global
psutil_mem_vm
,
psutil_fs_usage_tag
,
psutil_disk_io_tag
,
psutil_network_io_tag
global
refresh_time
,
client
,
server
,
server_port
,
server_ip
# Set default tags
...
...
@@ -2501,19 +2533,6 @@ if __name__ == "__main__":
# Catch CTRL-C
signal
.
signal
(
signal
.
SIGINT
,
signal_handler
)
# Optimization of the import step
# Only usefull lib are imported in order to reduce the memory print
if
not
server_tag
:
# Do not load curses lib for server
try
:
import
curses
import
curses.panel
except
ImportError
:
print
(
_
(
'Curses module not found. Glances cannot start.'
))
print
(
_
(
'Glances requires at least Python 2.6 or higher.'
))
print
()
sys
.
exit
(
1
)
if
client_tag
:
psutil_get_cpu_percent_tag
=
True
psutil_get_io_counter_tag
=
True
...
...
@@ -2523,20 +2542,6 @@ if __name__ == "__main__":
psutil_disk_io_tag
=
True
psutil_network_io_tag
=
True
else
:
# Do not load psutil lib for client
try
:
import
psutil
except
ImportError
:
print
(
_
(
'PsUtil module not found. Glances cannot start.'
))
print
()
print
(
_
(
'On Ubuntu 12.04 or higher:'
))
print
(
_
(
'$ sudo apt-get install python-psutil'
))
print
()
print
(
_
(
'To install PsUtil using pip (as root):'
))
print
(
_
(
'# pip install psutil'
))
print
()
sys
.
exit
(
1
)
try
:
# get_cpu_percent method only available with PsUtil 0.2.0+
psutil
.
Process
(
os
.
getpid
()).
get_cpu_percent
(
interval
=
0
)
...
...
@@ -2601,15 +2606,6 @@ if __name__ == "__main__":
# Init Glances depending of the mode (standalone, client, server)
if
server_tag
:
try
:
# For Python v2.x
from
SimpleXMLRPCServer
import
SimpleXMLRPCServer
except
:
# For Python v3.x
from
xmlrpc.server
import
SimpleXMLRPCServer
import
json
import
collections
# Init the server
print
(
_
(
"Glances server is running on %s:%s"
)
%
(
bind_ip
,
server_port
))
server
=
GlancesServer
(
bind_ip
,
server_port
,
GlancesHandler
,
refresh_time
)
...
...
@@ -2617,10 +2613,6 @@ if __name__ == "__main__":
# Init stats
stats
=
glancesStats
(
server_tag
=
True
)
elif
client_tag
:
import
xmlrpclib
import
json
import
collections
# Init the client (displaying server stat in the CLI)
client
=
GlancesClient
(
server_ip
,
server_port
)
...
...
@@ -2702,4 +2694,11 @@ if __name__ == "__main__":
if
csv_tag
:
csvoutput
.
update
(
stats
)
# Main
#=====
if
__name__
==
"__main__"
:
main
()
# The end...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录