Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
ac2c1ba9
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 搜索 >>
提交
ac2c1ba9
编写于
2月 01, 2015
作者:
N
Nicolargo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
First try for the quicklook plugin
上级
67e21a60
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
164 addition
and
18 deletion
+164
-18
glances/core/glances_main.py
glances/core/glances_main.py
+2
-0
glances/outputs/glances_bars.py
glances/outputs/glances_bars.py
+10
-3
glances/outputs/glances_curses.py
glances/outputs/glances_curses.py
+47
-14
glances/plugins/glances_cpu.py
glances/plugins/glances_cpu.py
+2
-1
glances/plugins/glances_quicklook.py
glances/plugins/glances_quicklook.py
+103
-0
未找到文件。
glances/core/glances_main.py
浏览文件 @
ac2c1ba9
...
...
@@ -118,6 +118,8 @@ Start the client browser (browser mode):\n\
dest
=
'disable_process'
,
help
=
_
(
'disable process module'
))
parser
.
add_argument
(
'--disable-log'
,
action
=
'store_true'
,
default
=
False
,
dest
=
'disable_log'
,
help
=
_
(
'disable log module'
))
parser
.
add_argument
(
'--disable-quicklook'
,
action
=
'store_true'
,
default
=
False
,
dest
=
'disable_quicklook'
,
help
=
_
(
'disable quicklook module'
))
parser
.
add_argument
(
'--disable-bold'
,
action
=
'store_false'
,
default
=
True
,
dest
=
'disable_bold'
,
help
=
_
(
'disable bold mode in the terminal'
))
parser
.
add_argument
(
'--enable-process-extended'
,
action
=
'store_true'
,
default
=
False
,
...
...
glances/outputs/glances_bars.py
浏览文件 @
ac2c1ba9
...
...
@@ -40,11 +40,18 @@ class Bar(object):
"""
def
__init__
(
self
,
size
):
def
__init__
(
self
,
size
,
pre_char
=
'['
,
post_char
=
']'
,
empty_char
=
'_'
):
# Bar size
self
.
__size
=
size
# Bar current percent
self
.
__percent
=
0
# Char used for the decoration
self
.
__pre_char
=
pre_char
self
.
__post_char
=
post_char
self
.
__empty_char
=
empty_char
def
get_size
(
self
):
return
self
.
__size
...
...
@@ -69,5 +76,5 @@ class Bar(object):
if
frac
>
0
:
ret
+=
curses_bars
[
int
(
frac
*
8
)]
whole
+=
1
ret
+=
'_'
*
int
(
self
.
get_size
()
-
whole
)
return
ret
ret
+=
self
.
__empty_char
*
int
(
self
.
get_size
()
-
whole
)
return
self
.
__pre_char
+
ret
+
self
.
__post_char
glances/outputs/glances_curses.py
浏览文件 @
ac2c1ba9
...
...
@@ -36,7 +36,8 @@ if not is_windows:
import
curses.panel
from
curses.textpad
import
Textbox
except
ImportError
:
logger
.
critical
(
"Curses module not found. Glances cannot start in standalone mode."
)
logger
.
critical
(
"Curses module not found. Glances cannot start in standalone mode."
)
sys
.
exit
(
1
)
else
:
from
glances.outputs.glances_colorconsole
import
WCurseLight
...
...
@@ -472,7 +473,9 @@ class _GlancesCurses(object):
# ... and exit
return
False
# ==================================
# Display first line (system+uptime)
# ==================================
self
.
new_line
()
l
=
self
.
get_stats_display_width
(
stats_system
)
+
self
.
get_stats_display_width
(
stats_uptime
)
+
self
.
space_between_column
...
...
@@ -480,42 +483,68 @@ class _GlancesCurses(object):
self
.
new_column
()
self
.
display_plugin
(
stats_uptime
)
# ========================================================
# Display second line (CPU|PERCPU+LOAD+MEM+SWAP+<SUMMARY>)
#
CPU|PERCPU
#
========================================================
self
.
init_column
()
self
.
new_line
()
# Init quicklook
stats_quicklook
=
{
'msgdict'
:
[]}
# Start with the mandatory stats:
# CPU | PERCPU
if
self
.
args
.
percpu
:
l
=
self
.
get_stats_display_width
(
stats_percpu
)
cpu_width
=
self
.
get_stats_display_width
(
stats_percpu
)
else
:
l
=
self
.
get_stats_display_width
(
stats_cpu
)
l
+=
self
.
get_stats_display_width
(
stats_load
)
+
self
.
get_stats_display_width
(
stats_mem
)
+
self
.
get_stats_display_width
(
stats_memswap
)
# Space between column
space_number
=
int
(
stats_load
[
'msgdict'
]
!=
[
])
+
int
(
stats_mem
[
'msgdict'
]
!=
[])
+
int
(
stats_memswap
[
'msgdict'
]
!=
[])
cpu_width
=
self
.
get_stats_display_width
(
stats_cpu
,
without_option
=
(
screen_x
<
80
))
l
=
cpu_width
# MEM & SWAP & LOAD
mem_width
=
self
.
get_stats_display_width
(
stats_mem
,
without_option
=
(
screen_x
<
100
))
l
+=
mem_width
l
+=
self
.
get_stats_display_width
(
stats_memswap
)
l
+=
self
.
get_stats_display_width
(
stats_load
)
# Quicklook plugin size is dynamic
if
screen_x
>
126
:
# TO be adapted to the screen...
quicklook_width
=
16
try
:
stats_quicklook
=
stats
.
get_plugin
(
'quicklook'
).
get_stats_display
(
max_width
=
quicklook_width
,
args
=
self
.
args
)
except
AttributeError
as
e
:
logger
.
debug
(
"Quicklook plugin not available (%s)"
%
e
)
else
:
l
+=
self
.
get_stats_display_width
(
stats_quicklook
)
# Compute space between column
space_number
=
int
(
stats_quicklook
[
'msgdict'
]
!=
[])
space_number
+=
int
(
stats_mem
[
'msgdict'
]
!=
[])
space_number
+=
int
(
stats_memswap
[
'msgdict'
]
!=
[])
space_number
+=
int
(
stats_load
[
'msgdict'
]
!=
[])
if
space_number
==
0
:
space_number
=
1
if
screen_x
>
(
space_number
*
self
.
space_between_column
+
l
):
self
.
space_between_column
=
int
((
screen_x
-
l
)
/
space_number
)
# Display
# logger.info(">>> Screen X: %s / Stats size: %s / Space size: %s / Nb space: %s" % (screen_x, l, self.space_between_column, space_number))
self
.
display_plugin
(
stats_quicklook
)
self
.
new_column
()
if
self
.
args
.
percpu
:
self
.
display_plugin
(
stats_percpu
)
else
:
self
.
display_plugin
(
stats_cpu
,
display_optional
=
(
screen_x
>=
80
))
self
.
new_column
()
self
.
display_plugin
(
stats_load
)
self
.
new_column
()
self
.
display_plugin
(
stats_mem
,
display_optional
=
(
screen_x
>=
(
space_number
*
self
.
space_between_column
+
l
)))
self
.
display_plugin
(
stats_mem
,
display_optional
=
(
screen_x
>=
100
))
self
.
new_column
()
self
.
display_plugin
(
stats_memswap
)
self
.
new_column
()
self
.
display_plugin
(
stats_load
)
# Space between column
self
.
space_between_column
=
3
# Backup line position
self
.
saved_line
=
self
.
next_line
# =============================================================
# Display left sidebar (NETWORK+DISKIO+FS+SENSORS+Current time)
# =============================================================
self
.
init_column
()
if
(
not
(
self
.
args
.
disable_network
and
self
.
args
.
disable_diskio
and
self
.
args
.
disable_fs
and
self
.
args
.
disable_raid
...
...
@@ -534,6 +563,9 @@ class _GlancesCurses(object):
self
.
new_line
()
self
.
display_plugin
(
stats_now
)
# ====================================
# Display right stats (process and co)
# ====================================
# If space available...
if
screen_x
>
52
:
# Restore line position
...
...
@@ -753,7 +785,8 @@ class _GlancesCurses(object):
x_max
=
x
# Compute the next Glances column/line position
self
.
next_column
=
max
(
self
.
next_column
,
x_max
+
self
.
space_between_column
)
self
.
next_column
=
max
(
self
.
next_column
,
x_max
+
self
.
space_between_column
)
self
.
next_line
=
max
(
self
.
next_line
,
y
+
self
.
space_between_line
)
def
erase
(
self
):
...
...
glances/plugins/glances_cpu.py
浏览文件 @
ac2c1ba9
...
...
@@ -22,6 +22,7 @@
import
psutil
from
glances.plugins.glances_plugin
import
GlancesPlugin
from
glances.core.glances_cpu_percent
import
cpu_percent
# from glances.core.glances_logging import logger
# SNMP OID
...
...
@@ -82,7 +83,7 @@ class Plugin(GlancesPlugin):
# nice (UNIX), iowait (Linux), irq (Linux, FreeBSD), steal (Linux 2.6.11+)
# The following stats are returned by the API but not displayed in the UI:
# softirq (Linux), guest (Linux 2.6.24+), guest_nice (Linux 3.2.0+)
self
.
stats
[
'total'
]
=
psutil
.
cpu_percent
(
interval
=
0.0
)
self
.
stats
[
'total'
]
=
cpu_percent
.
get
(
)
cpu_times_percent
=
psutil
.
cpu_times_percent
(
interval
=
0.0
)
for
stat
in
[
'user'
,
'system'
,
'idle'
,
'nice'
,
'iowait'
,
'irq'
,
'softirq'
,
'steal'
,
'guest'
,
'guest_nice'
]:
...
...
glances/plugins/glances_quicklook.py
0 → 100644
浏览文件 @
ac2c1ba9
# -*- coding: utf-8 -*-
#
# This file is part of Glances.
#
# Copyright (C) 2015 Nicolargo <nicolas@nicolargo.com>
#
# Glances is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Glances is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Quicklook plugin."""
import
psutil
from
glances.plugins.glances_plugin
import
GlancesPlugin
from
glances.core.glances_cpu_percent
import
cpu_percent
from
glances.outputs.glances_bars
import
Bar
from
glances.core.glances_logging
import
logger
class
Plugin
(
GlancesPlugin
):
"""Glances quicklook plugin.
'stats' is a dictionary.
"""
def
__init__
(
self
,
args
=
None
):
"""Init the quicklook plugin."""
GlancesPlugin
.
__init__
(
self
,
args
=
args
)
# We want to display the stat in the curse interface
self
.
display_curse
=
True
# Init stats
self
.
reset
()
def
reset
(
self
):
"""Reset/init the stats."""
self
.
stats
=
{}
@
GlancesPlugin
.
_log_result_decorator
def
update
(
self
):
"""Update quicklook stats using the input method."""
# Reset stats
self
.
reset
()
# Grab quicklook stats: CPU, MEM and SWAP
if
self
.
get_input
()
==
'local'
:
# Get the latest CPU percent value
self
.
stats
[
'cpu'
]
=
cpu_percent
.
get
()
# Use the PsUtil lib for the memory (virtual and swap)
self
.
stats
[
'mem'
]
=
psutil
.
virtual_memory
().
percent
self
.
stats
[
'swap'
]
=
psutil
.
swap_memory
().
percent
elif
self
.
get_input
()
==
'snmp'
:
# Not available
pass
# Update the view
self
.
update_views
()
return
self
.
stats
def
update_views
(
self
):
"""Update stats views"""
# Call the father's method
GlancesPlugin
.
update_views
(
self
)
def
msg_curse
(
self
,
args
=
None
,
max_width
=
10
):
"""Return the list to display in the UI"""
# Init the return message
ret
=
[]
# Only process if stats exist...
if
self
.
stats
==
{}
or
args
.
disable_quicklook
:
return
ret
# Build the string message
bar
=
Bar
(
max_width
,
pre_char
=
'|'
,
post_char
=
'|'
,
empty_char
=
' '
)
bar
.
set_percent
(
self
.
stats
[
'cpu'
])
msg
=
'{0:>4} {1}'
.
format
(
_
(
"CPU"
),
bar
)
ret
.
append
(
self
.
curse_add_line
(
msg
))
ret
.
append
(
self
.
curse_new_line
())
bar
.
set_percent
(
self
.
stats
[
'mem'
])
msg
=
'{0:>4} {1}'
.
format
(
_
(
"MEM"
),
bar
)
ret
.
append
(
self
.
curse_add_line
(
msg
))
ret
.
append
(
self
.
curse_new_line
())
bar
.
set_percent
(
self
.
stats
[
'swap'
])
msg
=
'{0:>4} {1}'
.
format
(
_
(
"SWAP"
),
bar
)
ret
.
append
(
self
.
curse_add_line
(
msg
))
ret
.
append
(
self
.
curse_new_line
())
# Return the message with decoration
return
ret
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录