Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
6d5663ec
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,发现更多精彩内容 >>
提交
6d5663ec
编写于
7月 13, 2013
作者:
A
Alessio Sergi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
flake8 fixes
上级
4355f405
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
50 addition
and
53 deletion
+50
-53
glances/glances.py
glances/glances.py
+50
-53
未找到文件。
glances/glances.py
浏览文件 @
6d5663ec
...
...
@@ -89,7 +89,7 @@ if not is_Windows:
sys
.
exit
(
1
)
try
:
#
PSUtil is the main lib
used to grab stats
#
psutil is the main library
used to grab stats
import
psutil
except
ImportError
:
print
(
_
(
'PsUtil module not found. Glances cannot start.'
))
...
...
@@ -102,7 +102,7 @@ if psutil_version < (0, 4, 1):
sys
.
exit
(
1
)
try
:
# virtual_memory() only available
with PsUtil 0.6+
# virtual_memory() only available
from psutil >= 0.6
psutil
.
virtual_memory
()
except
Exception
:
psutil_mem_vm
=
False
...
...
@@ -115,7 +115,7 @@ else:
# get_io_counters() not available on OS X
psutil_get_io_counter_tag
=
False
#
Sensors (optional; only available on Linux
)
#
sensors library (optional; Linux-only
)
if
is_Linux
:
try
:
import
sensors
...
...
@@ -126,6 +126,15 @@ if is_Linux:
else
:
sensors_lib_tag
=
False
# batinfo library (optional; Linux-only)
if
is_Linux
:
try
:
import
batinfo
except
ImportError
:
batinfo_lib_tag
=
False
else
:
batinfo_lib_tag
=
True
try
:
# HTML output (optional)
import
jinja2
...
...
@@ -142,15 +151,6 @@ except ImportError:
else
:
csv_lib_tag
=
True
if
(
is_Linux
):
try
:
# Import the batinfo lib (optionnal)
import
batinfo
except
ImportError
:
batinfo_lib_tag
=
False
else
:
batinfo_lib_tag
=
True
# Default tag
sensors_tag
=
False
hddtemp_tag
=
False
...
...
@@ -712,6 +712,7 @@ class glancesGrabSensors:
if
self
.
initok
:
sensors
.
cleanup
()
class
glancesGrabHDDTemp
:
"""
Get hddtemp stats using a socket connection
...
...
@@ -899,15 +900,14 @@ class glancesGrabBat:
"""
Init batteries stats
"""
if
(
batinfo_lib_tag
):
try
:
self
.
bat
=
batinfo
.
batteries
()
except
:
self
.
initok
=
False
else
:
self
.
initok
=
True
self
.
__update__
()
if
batinfo_lib_tag
:
try
:
self
.
bat
=
batinfo
.
batteries
()
except
:
self
.
initok
=
False
else
:
self
.
initok
=
True
self
.
__update__
()
def
__update__
(
self
):
"""
...
...
@@ -918,25 +918,24 @@ class glancesGrabBat:
self
.
bat
.
update
()
self
.
bat_list
=
self
.
bat
.
stat
else
:
self
.
bat_list
=
[]
self
.
bat_list
=
[]
def
get
(
self
):
# Update the stats
# Update the stats
self
.
__update__
()
return
self
.
bat_list
def
getcapacitypercent
(
self
):
if
not
self
.
initok
or
self
.
bat_list
==
[]:
return
[]
# Init the bsum (sum of percent) and bcpt (number of batteries)
# and Loop over batteries (yes a computer could have more than 1 battery)
bsum
=
0
for
bcpt
in
range
(
len
(
self
.
get
())):
bsum
=
bsum
+
int
(
self
.
bat_list
[
bcpt
].
capacity
)
bcpt
=
bcpt
+
1
# Return the global percent
return
int
(
bsum
/
bcpt
)
if
not
self
.
initok
or
self
.
bat_list
==
[]:
return
[]
# Init the bsum (sum of percent) and bcpt (number of batteries)
# and Loop over batteries (yes a computer could have more than 1 battery)
bsum
=
0
for
bcpt
in
range
(
len
(
self
.
get
())):
bsum
=
bsum
+
int
(
self
.
bat_list
[
bcpt
].
capacity
)
bcpt
=
bcpt
+
1
# Return the global percent
return
int
(
bsum
/
bcpt
)
class
GlancesStats
:
...
...
@@ -978,7 +977,7 @@ class GlancesStats:
self
.
hddtemp_tag
=
False
if
batinfo_lib_tag
:
self
.
glancesgrabbat
=
glancesGrabBat
()
self
.
glancesgrabbat
=
glancesGrabBat
()
# Init the process list
self
.
process_list_refresh
=
True
...
...
@@ -1246,7 +1245,7 @@ class GlancesStats:
# BATERRIES INFORMATION
if
batinfo_lib_tag
:
self
.
batpercent
=
self
.
glancesgrabbat
.
getcapacitypercent
()
self
.
batpercent
=
self
.
glancesgrabbat
.
getcapacitypercent
()
# DISK I/O
if
diskio_tag
and
not
self
.
diskio_error_tag
:
...
...
@@ -1355,10 +1354,10 @@ class GlancesStats:
return
[]
def
getBatPercent
(
self
):
if
batinfo_lib_tag
:
return
self
.
batpercent
else
:
return
[]
if
batinfo_lib_tag
:
return
self
.
batpercent
else
:
return
[]
def
getDiskIO
(
self
):
if
diskio_tag
:
...
...
@@ -2045,15 +2044,15 @@ class glancesScreen:
cpu_offset
=
self
.
displayCpu
(
stats
.
getCpu
(),
stats
.
getPerCpu
(),
processlist
)
load_offset
=
self
.
displayLoad
(
stats
.
getLoad
(),
stats
.
getCore
(),
processlist
,
cpu_offset
)
self
.
displayMem
(
stats
.
getMem
(),
stats
.
getMemSwap
(),
processlist
,
load_offset
)
network_count
=
self
.
displayNetwork
(
stats
.
getNetwork
(),
error
=
stats
.
network_error_tag
)
network_count
=
self
.
displayNetwork
(
stats
.
getNetwork
(),
error
=
stats
.
network_error_tag
)
sensors_count
=
self
.
displaySensors
(
stats
.
getSensors
(),
self
.
network_y
+
network_count
)
hddtemp_count
=
self
.
displayHDDTemp
(
stats
.
getHDDTemp
(),
self
.
network_y
+
network_count
+
sensors_count
)
diskio_count
=
self
.
displayDiskIO
(
stats
.
getDiskIO
(),
offset_y
=
self
.
network_y
+
sensors_count
+
offset_y
=
self
.
network_y
+
sensors_count
+
network_count
+
hddtemp_count
,
error
=
stats
.
diskio_error_tag
)
error
=
stats
.
diskio_error_tag
)
fs_count
=
self
.
displayFs
(
stats
.
getFs
(),
self
.
network_y
+
sensors_count
+
network_count
+
diskio_count
+
...
...
@@ -2476,7 +2475,7 @@ class glancesScreen:
self
.
mem_y
+
3
,
self
.
mem_x
+
offset_x
+
39
,
format
(
self
.
__autoUnit
(
memswap
[
'free'
]),
'>5'
),
8
)
def
displayNetwork
(
self
,
network
,
error
=
False
):
def
displayNetwork
(
self
,
network
,
error
=
False
):
"""
Display the network interface bitrate
If error = True, then display a grab error message
...
...
@@ -2506,7 +2505,7 @@ class glancesScreen:
self
.
term_window
.
addnstr
(
self
.
network_y
,
self
.
network_x
+
10
,
format
(
_
(
rx_column_name
),
'>5'
),
5
)
self
.
term_window
.
addnstr
(
self
.
network_y
,
self
.
network_x
+
18
,
format
(
_
(
tx_column_name
),
'>5'
),
5
)
format
(
_
(
tx_column_name
),
'>5'
),
5
)
if
error
:
# If there is a grab error
...
...
@@ -2652,7 +2651,7 @@ class glancesScreen:
return
ret
return
0
def
displayDiskIO
(
self
,
diskio
,
offset_y
=
0
,
error
=
False
):
def
displayDiskIO
(
self
,
diskio
,
offset_y
=
0
,
error
=
False
):
# Disk input/output rate
if
not
self
.
diskio_tag
:
return
0
...
...
@@ -3036,9 +3035,9 @@ class glancesScreen:
tag_proc_time
=
False
else
:
dtime
=
"{0}:{1}.{2}"
.
format
(
str
(
dtime
.
seconds
//
60
%
60
),
str
(
dtime
.
seconds
%
60
).
zfill
(
2
),
str
(
dtime
.
microseconds
)[:
2
].
zfill
(
2
))
str
(
dtime
.
seconds
//
60
%
60
),
str
(
dtime
.
seconds
%
60
).
zfill
(
2
),
str
(
dtime
.
microseconds
)[:
2
].
zfill
(
2
))
self
.
term_window
.
addnstr
(
self
.
process_y
+
3
+
processes
,
process_x
+
47
,
format
(
dtime
,
'>8'
),
8
)
...
...
@@ -3269,7 +3268,6 @@ class glancesScreen:
'{0:{width}}{1}'
.
format
(
*
key
,
width
=
width
),
38
)
key_table_y
+=
1
def
displayBat
(
self
,
batpercent
):
# Display the current batteries capacities % - Center
if
not
batinfo_lib_tag
or
batpercent
==
[]:
...
...
@@ -3279,15 +3277,14 @@ class glancesScreen:
# Build the message to display
bat_msg
=
"%d%%"
%
batpercent
# Display the message (if possible)
if
(
screen_y
>
self
.
bat_y
and
screen_x
>
self
.
bat_x
+
len
(
bat_msg
)):
if
(
screen_y
>
self
.
bat_y
and
screen_x
>
self
.
bat_x
+
len
(
bat_msg
)):
center
=
(
screen_x
//
2
)
-
len
(
bat_msg
)
//
2
self
.
term_window
.
addnstr
(
max
(
self
.
bat_y
,
screen_y
-
1
),
self
.
bat_x
+
center
,
bat_msg
,
len
(
bat_msg
))
def
displayNow
(
self
,
now
):
# Display the current date and time (now...) - Right
if
not
now
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录