Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
05c675d7
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,发现更多精彩内容 >>
提交
05c675d7
编写于
1月 26, 2014
作者:
N
Nicolas Hennion
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add Uptime and Now plugin. First step for processes plugins. Had to be optimezd
上级
311ba7ce
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
429 addition
and
19 deletion
+429
-19
glances/core/glances_server.py
glances/core/glances_server.py
+2
-1
glances/plugins/glances_core.py
glances/plugins/glances_core.py
+17
-17
glances/plugins/glances_fs.py
glances/plugins/glances_fs.py
+1
-1
glances/plugins/glances_now.py
glances/plugins/glances_now.py
+45
-0
glances/plugins/glances_processcount.py
glances/plugins/glances_processcount.py
+236
-0
glances/plugins/glances_processlist.py
glances/plugins/glances_processlist.py
+70
-0
glances/plugins/glances_uptime.py
glances/plugins/glances_uptime.py
+58
-0
未找到文件。
glances/core/glances_server.py
浏览文件 @
05c675d7
...
...
@@ -176,7 +176,8 @@ class GlancesInstance():
# Check if the attribute starts with 'get'
if
(
item
.
startswith
(
header
)):
try
:
# !!! Update the stat
# Update the stat
# !!! All the stat are updated before one grab (not optimized)
self
.
stats
.
update
()
# Return the attribute
return
getattr
(
self
.
stats
,
item
)
...
...
glances/plugins/glances_core.py
浏览文件 @
05c675d7
...
...
@@ -26,25 +26,25 @@ from psutil import NUM_CPUS
from
glances_plugin
import
GlancesPlugin
class
Plugin
(
GlancesPlugin
):
"""
Glances' Core Plugin
Get stats about CPU core number
"""
Glances' Core Plugin
Get stats about CPU core number
stats is integer (number of core)
"""
stats is integer (number of core)
"""
def
__init__
(
self
):
GlancesPlugin
.
__init__
(
self
)
def
__init__
(
self
):
GlancesPlugin
.
__init__
(
self
)
def
update
(
self
):
"""
Update core stats
"""
def
update
(
self
):
"""
Update core stats
"""
# !!! Note: The PSUtil 2.0 include psutil.cpu_count() and psutil.cpu_count(logical=False)
# !!! TODO: We had to return a dict (with both hys and log cpu number) instead of a integer
try
:
self
.
stats
=
NUM_CPUS
except
Exception
,
e
:
self
.
stats
=
None
# !!! Note: The PSUtil 2.0 include psutil.cpu_count() and psutil.cpu_count(logical=False)
# !!! TODO: We had to return a dict (with both hys and log cpu number) instead of a integer
try
:
self
.
stats
=
NUM_CPUS
except
Exception
,
e
:
self
.
stats
=
None
glances/plugins/glances_fs.py
浏览文件 @
05c675d7
...
...
@@ -19,7 +19,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from
psutil
import
disk_partitions
,
disk_usage
from
glances_plugin
import
GlancesPlugin
,
getTimeSinceLastUpdate
from
glances_plugin
import
GlancesPlugin
class
Plugin
(
GlancesPlugin
):
...
...
glances/plugins/glances_now.py
0 → 100644
浏览文件 @
05c675d7
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Glances - An eye on your system
#
# Copyright (C) 2014 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/>.
# Import system libs
from
datetime
import
datetime
# from ..plugins.glances_plugin import GlancesPlugin
from
glances_plugin
import
GlancesPlugin
class
Plugin
(
GlancesPlugin
):
"""
Glances' Core Plugin
Get current date/time
stats is date (string)
"""
def
__init__
(
self
):
GlancesPlugin
.
__init__
(
self
)
def
update
(
self
):
"""
Update current date/time
"""
# Now
self
.
stats
=
datetime
.
now
()
glances/plugins/glances_processcount.py
0 → 100644
浏览文件 @
05c675d7
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Glances - An eye on your system
#
# Copyright (C) 2014 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/>.
# !!! Not optimized because both processcount and processlist
# !!! grab all processes.
# !!! Action: create a new file globalprocesses.py with a global
# !!! variable instance of GlancesGrabProcesses classes and share
# !!! it between the two plugins
from
psutil
import
process_iter
,
AccessDenied
,
NoSuchProcess
from
glances.core.glances_globals
import
is_BSD
,
is_Mac
,
is_Windows
from
glances.core.glances_timer
import
Timer
from
glances_plugin
import
GlancesPlugin
,
getTimeSinceLastUpdate
class
Plugin
(
GlancesPlugin
):
"""
Glances's processes Plugin
stats is a list
"""
def
__init__
(
self
):
GlancesPlugin
.
__init__
(
self
)
# Init the process class
self
.
glancesgrabprocesses
=
GlancesGrabProcesses
()
def
update
(
self
):
"""
Update processes stats
"""
self
.
glancesgrabprocesses
.
update
()
self
.
stats
=
self
.
glancesgrabprocesses
.
getcount
()
# processcount = self.glancesgrabprocesses.getcount()
# process = self.glancesgrabprocesses.getlist()
# if not hasattr(self, 'process'):
# self.processcount = {}
# self.process = []
# else:
# self.processcount = processcount
# self.process = process
def
get_stats
(
self
):
# Return the stats object for the RPC API
# Sort it by mount name
# Convert it to string
return
str
(
self
.
stats
)
class
GlancesGrabProcesses
:
"""
Get processed stats using the PsUtil lib
"""
def
__init__
(
self
,
cache_timeout
=
60
):
"""
Init the class to collect stats about processes
"""
# Add internals caches because PSUtil do not cache all the stats
# See: https://code.google.com/p/psutil/issues/detail?id=462
self
.
username_cache
=
{}
self
.
cmdline_cache
=
{}
# The internals caches will be cleaned each 'cache_timeout' seconds
self
.
cache_timeout
=
cache_timeout
self
.
cache_timer
=
Timer
(
self
.
cache_timeout
)
# Init the io dict
# key = pid
# value = [ read_bytes_old, write_bytes_old ]
self
.
io_old
=
{}
def
__get_process_stats
(
self
,
proc
):
"""
Get process statistics
"""
procstat
=
{}
# Process ID
procstat
[
'pid'
]
=
proc
.
pid
# Process name (cached by PSUtil)
procstat
[
'name'
]
=
proc
.
name
# Process username (cached with internal cache)
try
:
self
.
username_cache
[
procstat
[
'pid'
]]
except
:
try
:
self
.
username_cache
[
procstat
[
'pid'
]]
=
proc
.
username
except
KeyError
:
try
:
self
.
username_cache
[
procstat
[
'pid'
]]
=
proc
.
uids
.
real
except
KeyError
:
self
.
username_cache
[
procstat
[
'pid'
]]
=
"?"
procstat
[
'username'
]
=
self
.
username_cache
[
procstat
[
'pid'
]]
# Process command line (cached with internal cache)
try
:
self
.
cmdline_cache
[
procstat
[
'pid'
]]
except
:
self
.
cmdline_cache
[
procstat
[
'pid'
]]
=
' '
.
join
(
proc
.
cmdline
)
procstat
[
'cmdline'
]
=
self
.
cmdline_cache
[
procstat
[
'pid'
]]
# Process status
procstat
[
'status'
]
=
str
(
proc
.
status
)[:
1
].
upper
()
# Process nice
procstat
[
'nice'
]
=
proc
.
get_nice
()
# Process memory
procstat
[
'memory_info'
]
=
proc
.
get_memory_info
()
procstat
[
'memory_percent'
]
=
proc
.
get_memory_percent
()
# Process CPU
procstat
[
'cpu_times'
]
=
proc
.
get_cpu_times
()
procstat
[
'cpu_percent'
]
=
proc
.
get_cpu_percent
(
interval
=
0
)
# Process network connections (TCP and UDP) (Experimental)
# !!! High CPU consumption
# try:
# procstat['tcp'] = len(proc.get_connections(kind="tcp"))
# procstat['udp'] = len(proc.get_connections(kind="udp"))
# except:
# procstat['tcp'] = 0
# procstat['udp'] = 0
# Process IO
# procstat['io_counters'] is a list:
# [read_bytes, write_bytes, read_bytes_old, write_bytes_old, io_tag]
# If io_tag = 0 > Access denied (display "?")
# If io_tag = 1 > No access denied (display the IO rate)
# Note Disk IO stat not available on Mac OS
if
not
is_Mac
:
try
:
# Get the process IO counters
proc_io
=
proc
.
get_io_counters
()
io_new
=
[
proc_io
.
read_bytes
,
proc_io
.
write_bytes
]
except
AccessDenied
:
# Access denied to process IO (no root account)
# Put 0 in all values (for sort) and io_tag = 0 (for display)
procstat
[
'io_counters'
]
=
[
0
,
0
]
+
[
0
,
0
]
io_tag
=
0
else
:
# For IO rate computation
# Append saved IO r/w bytes
try
:
procstat
[
'io_counters'
]
=
io_new
+
self
.
io_old
[
procstat
[
'pid'
]]
except
KeyError
:
procstat
[
'io_counters'
]
=
io_new
+
[
0
,
0
]
# then save the IO r/w bytes
self
.
io_old
[
procstat
[
'pid'
]]
=
io_new
io_tag
=
1
# Append the IO tag (for display)
procstat
[
'io_counters'
]
+=
[
io_tag
]
return
procstat
def
update
(
self
):
self
.
processlist
=
[]
self
.
processcount
=
{
'total'
:
0
,
'running'
:
0
,
'sleeping'
:
0
,
'thread'
:
0
}
# Get the time since last update
time_since_update
=
getTimeSinceLastUpdate
(
'process_disk'
)
# For each existing process...
for
proc
in
process_iter
():
try
:
# Get stats using the PSUtil
procstat
=
self
.
__get_process_stats
(
proc
)
# Add a specific time_since_update stats for bitrate
procstat
[
'time_since_update'
]
=
time_since_update
# ignore the 'idle' process on Windows and *BSD
# ignore the 'kernel_task' process on OS X
# waiting for upstream patch from psutil
if
(
is_BSD
and
procstat
[
'name'
]
==
'idle'
or
is_Windows
and
procstat
[
'name'
]
==
'System Idle Process'
or
is_Mac
and
procstat
[
'name'
]
==
'kernel_task'
):
continue
# Update processcount (global statistics)
try
:
self
.
processcount
[
str
(
proc
.
status
)]
+=
1
except
KeyError
:
# Key did not exist, create it
self
.
processcount
[
str
(
proc
.
status
)]
=
1
else
:
self
.
processcount
[
'total'
]
+=
1
# Update thread number (global statistics)
try
:
self
.
processcount
[
'thread'
]
+=
proc
.
get_num_threads
()
except
:
pass
except
(
NoSuchProcess
,
AccessDenied
):
continue
else
:
# Update processlist
self
.
processlist
.
append
(
procstat
)
# Clean internals caches if timeout is reached
if
(
self
.
cache_timer
.
finished
()):
self
.
username_cache
=
{}
self
.
cmdline_cache
=
{}
# Restart the timer
self
.
cache_timer
.
reset
()
def
getcount
(
self
):
return
self
.
processcount
def
getlist
(
self
):
return
self
.
processlist
glances/plugins/glances_processlist.py
0 → 100644
浏览文件 @
05c675d7
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Glances - An eye on your system
#
# Copyright (C) 2014 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/>.
# !!! Not optimized because both processcount and processlist
# !!! grab all processes.
# !!! Action: create a new file globalprocesses.py with a global
# !!! variable instance of GlancesGrabProcesses classes and share
# !!! it between the two plugins
from
psutil
import
process_iter
,
AccessDenied
,
NoSuchProcess
from
glances.core.glances_globals
import
is_BSD
,
is_Mac
,
is_Windows
from
glances.core.glances_timer
import
Timer
from
glances_plugin
import
GlancesPlugin
,
getTimeSinceLastUpdate
from
glances_processcount
import
GlancesGrabProcesses
class
Plugin
(
GlancesPlugin
):
"""
Glances's processes Plugin
stats is a list
"""
def
__init__
(
self
):
GlancesPlugin
.
__init__
(
self
)
# Init the process class
self
.
glancesgrabprocesses
=
GlancesGrabProcesses
()
def
update
(
self
):
"""
Update processes stats
"""
self
.
glancesgrabprocesses
.
update
()
self
.
stats
=
self
.
glancesgrabprocesses
.
getlist
()
# processcount = self.glancesgrabprocesses.getcount()
# process = self.glancesgrabprocesses.getlist()
# if not hasattr(self, 'process'):
# self.processcount = {}
# self.process = []
# else:
# self.processcount = processcount
# self.process = process
def
get_stats
(
self
):
# Return the stats object for the RPC API
# Convert it to string
return
str
(
self
.
stats
)
glances/plugins/glances_uptime.py
0 → 100644
浏览文件 @
05c675d7
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Glances - An eye on your system
#
# Copyright (C) 2014 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/>.
# Import system libs
# Check for PSUtil already done in the glances_core script
try
:
from
psutil
import
get_boot_time
except
:
from
putil
import
BOOT_TIME
from
datetime
import
datetime
# from ..plugins.glances_plugin import GlancesPlugin
from
glances_plugin
import
GlancesPlugin
class
Plugin
(
GlancesPlugin
):
"""
Glances' Core Plugin
Get stats about uptime
stats is date (string)
"""
def
__init__
(
self
):
GlancesPlugin
.
__init__
(
self
)
def
update
(
self
):
"""
Update uptime stat
"""
# Uptime
try
:
# For PsUtil >= 0.7.0
self
.
uptime
=
datetime
.
now
()
-
datetime
.
fromtimestamp
(
get_boot_time
())
except
:
self
.
uptime
=
datetime
.
now
()
-
datetime
.
fromtimestamp
(
BOOT_TIME
)
# Convert uptime to string (because datetime is not JSONifi)
self
.
stats
=
str
(
self
.
uptime
).
split
(
'.'
)[
0
]
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录