Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
86d8e0ba
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,发现更多精彩内容 >>
提交
86d8e0ba
编写于
3月 13, 2012
作者:
N
nicolargo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
HTML Output
上级
edee0205
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
181 addition
and
6 deletion
+181
-6
README
README
+15
-2
README.md
README.md
+16
-2
src/glances.py
src/glances.py
+150
-2
未找到文件。
README
浏览文件 @
86d8e0ba
...
...
@@ -18,7 +18,20 @@ It is developed in Python.
### From package manager (very easy way)
Packages exist for Arch, Fedora, Redhat, Ubuntu (with PPA), FreeBSD...
Packages exist for Arch, Fedora, Redhat, FreeBSD...
### From PPA (easy way for Ubuntu/Mint...)
Arnaud Hartmann (thanks to him !) maintains a PPA with the latest Glances version:
To install the PPA just enter:
$ sudo add-apt-repository ppa:arnaud-hartmann/glances-dev
$ sudo apt-get update
Then install Glances:
$ sudo apt-get install glances
### From PyPi (easy way)
...
...
@@ -56,7 +69,7 @@ The officials repos only include the psutil version 0.2.1.
You had to install the version 0.4.1 using the following commands:
$ sudo apt-get install python-dev python-pip
$ sudo pip install psutil
$ sudo pip install
--upgrade
psutil
## Running
...
...
README.md
浏览文件 @
86d8e0ba
...
...
@@ -9,6 +9,7 @@ Glances -- Eye on your system
Glances is a CLI curses based monitoring tool for GNU/Linux and BSD OS.
Glances uses the PsUtil library to get information from your system.
It is developed in Python.
![
screenshot
](
https://github.com/nicolargo/glances/raw/master/screenshot.png
)
...
...
@@ -17,7 +18,20 @@ It is developed in Python.
### From package manager (very easy way)
Packages exist for Arch, Fedora, Redhat, Ubuntu (with PPA), FreeBSD...
Packages exist for Arch, Fedora, Redhat, FreeBSD...
### From PPA (easy way for Ubuntu/Mint...)
Arnaud Hartmann (thanks to him !) maintains a PPA with the latest Glances version:
To install the PPA just enter:
$ sudo add-apt-repository ppa:arnaud-hartmann/glances-dev
$ sudo apt-get update
Then install Glances:
$ sudo apt-get install glances
### From PyPi (easy way)
...
...
@@ -55,7 +69,7 @@ The officials repos only include the psutil version 0.2.1.
You had to install the version 0.4.1 using the following commands:
$ sudo apt-get install python-dev python-pip
$ sudo pip install psutil
$ sudo pip install
--upgrade
psutil
## Running
...
...
src/glances.py
浏览文件 @
86d8e0ba
...
...
@@ -22,7 +22,7 @@
from
__future__
import
generators
__appname__
=
'glances'
__version__
=
"1.4b1
2
"
__version__
=
"1.4b1
3
"
__author__
=
"Nicolas Hennion <nicolas@nicolargo.com>"
__licence__
=
"LGPL"
...
...
@@ -114,6 +114,14 @@ except:
else
:
psutil_network_io_tag
=
True
try
:
# HTML output
import
jinja2
except
:
jinja_tag
=
False
else
:
jinja_tag
=
True
# Classes
#========
...
...
@@ -1285,6 +1293,140 @@ class glancesScreen():
now_msg
=
now
.
strftime
(
_
(
"%Y-%m-%d %H:%M:%S"
))
self
.
term_window
.
addnstr
(
max
(
self
.
now_y
,
screen_y
-
1
),
max
(
self
.
now_x
,
screen_x
-
1
)
-
len
(
now_msg
),
now_msg
,
len
(
now_msg
))
class
glancesHtml
():
"""
This class manages the HTML output
"""
def
__init__
(
self
,
refresh_time
=
1
):
# Global information to display
# Init refresh time
self
.
__refresh_time
=
refresh_time
# Set the templates path
environment
=
jinja2
.
Environment
(
loader
=
jinja2
.
FileSystemLoader
(
'html'
))
# Open the template
self
.
template
=
environment
.
get_template
(
'default.html'
)
# Define the colors list (hash table) for logged stats
self
.
__colors_list
=
{
# CAREFUL WARNING CRITICAL
'DEFAULT'
:
"bgcdefault fgdefault"
,
'OK'
:
"bgcok fgok"
,
'CAREFUL'
:
"bgccareful fgcareful"
,
'WARNING'
:
"bgcwarning fgcwarning"
,
'CRITICAL'
:
"bgcritical fgcritical"
}
def
__getAlert
(
self
,
current
=
0
,
max
=
100
):
# If current < CAREFUL of max then alert = OK
# If current > CAREFUL of max then alert = CAREFUL
# If current > WARNING of max then alert = WARNING
# If current > CRITICAL of max then alert = CRITICAL
try
:
(
current
*
100
)
/
max
except
ZeroDivisionError
:
return
'DEFAULT'
variable
=
(
current
*
100
)
/
max
if
variable
>
limits
.
getSTDCritical
():
return
'CRITICAL'
elif
variable
>
limits
.
getSTDWarning
():
return
'WARNING'
elif
variable
>
limits
.
getSTDCareful
():
return
'CAREFUL'
return
'OK'
def
__getColor
(
self
,
current
=
0
,
max
=
100
):
"""
Return colors for logged stats
"""
return
self
.
__colors_list
[
self
.
__getAlert
(
current
,
max
)]
def
__getCpuColor
(
self
,
cpu
,
max
=
100
):
cpu
[
'user_color'
]
=
self
.
__getColor
(
cpu
[
'user'
],
max
)
cpu
[
'kernel_color'
]
=
self
.
__getColor
(
cpu
[
'kernel'
],
max
)
cpu
[
'nice_color'
]
=
self
.
__getColor
(
cpu
[
'nice'
],
max
)
return
cpu
def
__getLoadAlert
(
self
,
current
=
0
,
core
=
1
):
# If current < CAREFUL*core of max then alert = OK
# If current > CAREFUL*core of max then alert = CAREFUL
# If current > WARNING*core of max then alert = WARNING
# If current > CRITICAL*core of max then alert = CRITICAL
if
current
>
limits
.
getLOADCritical
(
core
):
return
'CRITICAL'
elif
current
>
limits
.
getLOADWarning
(
core
):
return
'WARNING'
elif
current
>
limits
.
getLOADCareful
(
core
):
return
'CAREFUL'
return
'OK'
def
__getLoadColor
(
self
,
load
,
core
=
1
):
load
[
'min1_color'
]
=
self
.
__colors_list
[
self
.
__getLoadAlert
(
load
[
'min1'
],
core
)]
load
[
'min5_color'
]
=
self
.
__colors_list
[
self
.
__getLoadAlert
(
load
[
'min5'
],
core
)]
load
[
'min15_color'
]
=
self
.
__colors_list
[
self
.
__getLoadAlert
(
load
[
'min15'
],
core
)]
return
load
def
__getMemColor
(
self
,
mem
):
mem
[
'used_color'
]
=
self
.
__getColor
(
mem
[
'used'
]
-
mem
[
'cache'
],
mem
[
'total'
])
return
mem
def
__getMemSwapColor
(
self
,
memswap
):
memswap
[
'used_color'
]
=
self
.
__getColor
(
memswap
[
'used'
],
memswap
[
'total'
])
return
memswap
def
update
(
self
,
stats
):
if
(
stats
.
getCpu
()):
# Open the output file
f
=
open
(
'glances.html'
,
'w'
)
# Process color
# Render it
data
=
self
.
template
.
render
(
refresh
=
self
.
__refresh_time
,
host
=
stats
.
getHost
(),
system
=
stats
.
getSystem
(),
cpu
=
self
.
__getCpuColor
(
stats
.
getCpu
()),
load
=
self
.
__getLoadColor
(
stats
.
getLoad
(),
stats
.
getCore
()),
core
=
stats
.
getCore
(),
mem
=
self
.
__getMemColor
(
stats
.
getMem
()),
memswap
=
self
.
__getMemSwapColor
(
stats
.
getMemSwap
())
)
# Write data into the file
f
.
write
(
data
)
# Close the file
f
.
close
()
# Display stats
#~ self.displayHost(stats.getHost())
#~ self.displaySystem(stats.getSystem())
#~ self.displayCpu(stats.getCpu())
#~ self.displayLoad(stats.getLoad(), stats.getCore())
#~ self.displayMem(stats.getMem(), stats.getMemSwap())
#~ network_count = self.displayNetwork(stats.getNetwork())
#~ diskio_count = self.displayDiskIO(stats.getDiskIO(), self.network_y + network_count)
#~ fs_count = self.displayFs(stats.getFs(), self.network_y + network_count + diskio_count)
#~ log_count = self.displayLog(self.network_y + network_count + diskio_count + fs_count)
#~ self.displayProcess(stats.getProcessCount(), stats.getProcessList(screen.getProcessSortedBy()), log_count)
#~ self.displayCaption()
#~ self.displayNow(stats.getNow())
#~ self.displayHelp()
# Global def
#===========
...
...
@@ -1316,7 +1458,7 @@ def printSyntax():
def
init
():
global
limits
,
logs
,
stats
,
screen
global
limits
,
logs
,
stats
,
screen
,
html
global
refresh_time
refresh_time
=
1
...
...
@@ -1357,6 +1499,9 @@ def init():
# Init screen
screen
=
glancesScreen
(
refresh_time
)
# Init HTML output
html
=
glancesHtml
(
refresh_time
)
def
main
():
...
...
@@ -1370,6 +1515,9 @@ def main():
# Update the screen
screen
.
update
(
stats
)
# Update the HTML output
html
.
update
(
stats
)
def
end
():
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录