Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
c2da541c
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 搜索 >>
提交
c2da541c
编写于
8月 29, 2021
作者:
N
nicolargo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor Mem + MemSwap Curse
上级
73f091f2
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
103 addition
and
104 deletion
+103
-104
glances/plugins/glances_cpu.py
glances/plugins/glances_cpu.py
+23
-27
glances/plugins/glances_load.py
glances/plugins/glances_load.py
+3
-3
glances/plugins/glances_mem.py
glances/plugins/glances_mem.py
+40
-50
glances/plugins/glances_memswap.py
glances/plugins/glances_memswap.py
+24
-23
glances/plugins/glances_plugin.py
glances/plugins/glances_plugin.py
+13
-1
未找到文件。
glances/plugins/glances_cpu.py
浏览文件 @
c2da541c
...
...
@@ -282,12 +282,12 @@ class Plugin(GlancesPlugin):
if
not
self
.
stats
or
self
.
args
.
percpu
or
self
.
is_disable
():
return
ret
# Build the string message
# If user stat is not here, display only idle / total CPU usage (for
# exemple on Windows OS)
idle_tag
=
'user'
not
in
self
.
stats
# Header
# First line
# Total + (idle) + ctx_sw
msg
=
'{}'
.
format
(
'CPU'
)
ret
.
append
(
self
.
curse_add_line
(
msg
,
"TITLE"
))
trend_user
=
self
.
get_trend
(
'user'
)
...
...
@@ -303,50 +303,46 @@ class Plugin(GlancesPlugin):
ret
.
append
(
self
.
curse_add_line
(
msg
,
self
.
get_views
(
key
=
'total'
,
option
=
'decoration'
)))
# Idle CPU
if
'idle'
in
self
.
stats
and
not
idle_tag
:
if
not
idle_tag
:
ret
.
extend
(
self
.
curse_add_stat
(
'idle'
,
width
=
15
,
header
=
' '
))
# ctx_switches
if
'ctx_switches'
in
self
.
stats
:
ret
.
extend
(
self
.
curse_add_stat
(
'ctx_switches'
,
width
=
15
,
header
=
' '
))
# New line
# Second line
# user|idle + irq + interrupts
ret
.
append
(
self
.
curse_new_line
())
# User CPU
if
'user'
in
self
.
stats
:
if
not
idle_tag
:
ret
.
extend
(
self
.
curse_add_stat
(
'user'
,
width
=
15
))
elif
'idle'
in
self
.
stats
:
ret
.
extend
(
self
.
curse_add_stat
(
'idle'
,
width
=
15
))
# IRQ CPU
if
'irq'
in
self
.
stats
:
ret
.
extend
(
self
.
curse_add_stat
(
'irq'
,
width
=
15
,
header
=
' '
))
# interrupts
if
'interrupts'
in
self
.
stats
:
ret
.
extend
(
self
.
curse_add_stat
(
'interrupts'
,
width
=
15
,
header
=
' '
))
# New line
# Third line
# system|core + nice + sw_int
ret
.
append
(
self
.
curse_new_line
())
# System CPU
if
'system'
in
self
.
stats
and
not
idle_tag
:
if
not
idle_tag
:
ret
.
extend
(
self
.
curse_add_stat
(
'system'
,
width
=
15
))
else
:
ret
.
extend
(
self
.
curse_add_stat
(
'core'
,
width
=
15
))
# Nice CPU
if
'nice'
in
self
.
stats
:
ret
.
extend
(
self
.
curse_add_stat
(
'nice'
,
width
=
15
,
header
=
' '
))
# soft_interrupts
if
'soft_interrupts'
in
self
.
stats
:
ret
.
extend
(
self
.
curse_add_stat
(
'soft_interrupts'
,
width
=
15
,
header
=
' '
))
# New line
# Fourth line
# iowat + steal + syscalls
ret
.
append
(
self
.
curse_new_line
())
# IOWait CPU
if
'iowait'
in
self
.
stats
:
ret
.
extend
(
self
.
curse_add_stat
(
'iowait'
,
width
=
15
))
# Steal CPU usage
if
'steal'
in
self
.
stats
:
ret
.
extend
(
self
.
curse_add_stat
(
'steal'
,
width
=
15
,
header
=
' '
))
# syscalls: number of system calls since boot. Always set to 0 on Linux. (do not display)
if
'syscalls'
in
self
.
stats
and
not
LINUX
:
if
not
LINUX
:
ret
.
extend
(
self
.
curse_add_stat
(
'syscalls'
,
width
=
15
,
header
=
' '
))
# Return the message with decoration
...
...
glances/plugins/glances_load.py
浏览文件 @
c2da541c
...
...
@@ -32,15 +32,15 @@ fields_description = {
'min1'
:
{
'description'
:
'Average sum of the number of processes
\
waiting in the run-queue plus the number currently executing
\
over 1 minute.'
,
'unit'
:
'
number
'
},
'unit'
:
'
float
'
},
'min5'
:
{
'description'
:
'Average sum of the number of processes
\
waiting in the run-queue plus the number currently executing
\
over 5 minutes.'
,
'unit'
:
'
number
'
},
'unit'
:
'
float
'
},
'min15'
:
{
'description'
:
'Average sum of the number of processes
\
waiting in the run-queue plus the number currently executing
\
over 15 minutes.'
,
'unit'
:
'
number
'
},
'unit'
:
'
float
'
},
'cpucore'
:
{
'description'
:
'Total number of CPU core.'
,
'unit'
:
'number'
},
}
...
...
glances/plugins/glances_mem.py
浏览文件 @
c2da541c
...
...
@@ -2,7 +2,7 @@
#
# This file is part of Glances.
#
# Copyright (C) 20
19
Nicolargo <nicolas@nicolargo.com>
# Copyright (C) 20
21
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
...
...
@@ -28,32 +28,42 @@ import psutil
# Fields description
fields_description
=
{
'total'
:
{
'description'
:
'Total physical memory available.'
,
'unit'
:
'bytes'
},
'unit'
:
'bytes'
,
'min_symbol'
:
'K'
},
'available'
:
{
'description'
:
'The actual amount of available memory that can be given instantly
\
to processes that request more memory in bytes; this is calculated by summing
\
different memory values depending on the platform (e.g. free + buffers + cached on Linux)
\
and it is supposed to be used to monitor actual memory usage in a cross platform fashion.'
,
'unit'
:
'bytes'
},
'unit'
:
'bytes'
,
'min_symbol'
:
'K'
},
'percent'
:
{
'description'
:
'The percentage usage calculated as (total - available) / total * 100.'
,
'unit'
:
'percent'
},
'used'
:
{
'description'
:
'Memory used, calculated differently depending on the platform and
\
designed for informational purposes only.'
,
'unit'
:
'bytes'
},
'unit'
:
'bytes'
,
'min_symbol'
:
'K'
},
'free'
:
{
'description'
:
'Memory not being used at all (zeroed) that is readily available;
\
note that this doesn
\'
t reflect the actual memory available (use
\'
available
\'
instead).'
,
'unit'
:
'bytes'
},
'unit'
:
'bytes'
,
'min_symbol'
:
'K'
},
'active'
:
{
'description'
:
'*(UNIX)*: memory currently in use or very recently used, and so it is in RAM.'
,
'unit'
:
'bytes'
},
'unit'
:
'bytes'
,
'min_symbol'
:
'K'
},
'inactive'
:
{
'description'
:
'*(UNIX)*: memory that is marked as not used.'
,
'unit'
:
'bytes'
},
'unit'
:
'bytes'
,
'min_symbol'
:
'K'
},
'buffers'
:
{
'description'
:
'*(Linux, BSD)*: cache for things like file system metadata.'
,
'unit'
:
'bytes'
},
'unit'
:
'bytes'
,
'min_symbol'
:
'K'
},
'cached'
:
{
'description'
:
'*(Linux, BSD)*: cache for various things.'
,
'unit'
:
'bytes'
},
'unit'
:
'bytes'
,
'min_symbol'
:
'K'
},
'wired'
:
{
'description'
:
'*(BSD, macOS)*: memory that is marked to always stay in RAM. It is never moved to disk.'
,
'unit'
:
'bytes'
},
'unit'
:
'bytes'
,
'min_symbol'
:
'K'
},
'shared'
:
{
'description'
:
'*(BSD)*: memory that may be simultaneously accessed by multiple processes.'
,
'unit'
:
'bytes'
},
'unit'
:
'bytes'
,
'min_symbol'
:
'K'
},
}
# SNMP OID
...
...
@@ -214,8 +224,8 @@ class Plugin(GlancesPlugin):
if
not
self
.
stats
or
self
.
is_disable
():
return
ret
#
Build the string messag
e
#
Header
#
First lin
e
#
total% + active
msg
=
'{}'
.
format
(
'MEM'
)
ret
.
append
(
self
.
curse_add_line
(
msg
,
"TITLE"
))
msg
=
' {:2}'
.
format
(
self
.
trend_msg
(
self
.
get_trend
(
'percent'
)))
...
...
@@ -225,50 +235,30 @@ class Plugin(GlancesPlugin):
ret
.
append
(
self
.
curse_add_line
(
msg
,
self
.
get_views
(
key
=
'percent'
,
option
=
'decoration'
)))
# Active memory usage
if
'active'
in
self
.
stats
:
msg
=
' {:9}'
.
format
(
'active:'
)
ret
.
append
(
self
.
curse_add_line
(
msg
,
optional
=
self
.
get_views
(
key
=
'active'
,
option
=
'optional'
)))
msg
=
'{:>7}'
.
format
(
self
.
auto_unit
(
self
.
stats
[
'active'
]))
ret
.
append
(
self
.
curse_add_line
(
msg
,
optional
=
self
.
get_views
(
key
=
'active'
,
option
=
'optional'
)))
# New line
ret
.
extend
(
self
.
curse_add_stat
(
'active'
,
width
=
18
,
header
=
' '
))
# Second line
# total + inactive
ret
.
append
(
self
.
curse_new_line
())
# Total memory usage
msg
=
'{:6}'
.
format
(
'total:'
)
ret
.
append
(
self
.
curse_add_line
(
msg
))
msg
=
'{:>7}'
.
format
(
self
.
auto_unit
(
self
.
stats
[
'total'
]))
ret
.
append
(
self
.
curse_add_line
(
msg
))
ret
.
extend
(
self
.
curse_add_stat
(
'total'
,
width
=
15
))
# Inactive memory usage
if
'inactive'
in
self
.
stats
:
msg
=
' {:9}'
.
format
(
'inactive:'
)
ret
.
append
(
self
.
curse_add_line
(
msg
,
optional
=
self
.
get_views
(
key
=
'inactive'
,
option
=
'optional'
)))
msg
=
'{:>7}'
.
format
(
self
.
auto_unit
(
self
.
stats
[
'inactive'
]))
ret
.
append
(
self
.
curse_add_line
(
msg
,
optional
=
self
.
get_views
(
key
=
'inactive'
,
option
=
'optional'
)))
# New line
ret
.
extend
(
self
.
curse_add_stat
(
'inactive'
,
width
=
18
,
header
=
' '
))
# Third line
# used + buffers
ret
.
append
(
self
.
curse_new_line
())
# Used memory usage
msg
=
'{:6}'
.
format
(
'used:'
)
ret
.
append
(
self
.
curse_add_line
(
msg
))
msg
=
'{:>7}'
.
format
(
self
.
auto_unit
(
self
.
stats
[
'used'
]))
ret
.
append
(
self
.
curse_add_line
(
msg
,
self
.
get_views
(
key
=
'used'
,
option
=
'decoration'
)))
ret
.
extend
(
self
.
curse_add_stat
(
'used'
,
width
=
15
))
# Buffers memory usage
if
'buffers'
in
self
.
stats
:
msg
=
' {:9}'
.
format
(
'buffers:'
)
ret
.
append
(
self
.
curse_add_line
(
msg
,
optional
=
self
.
get_views
(
key
=
'buffers'
,
option
=
'optional'
)))
msg
=
'{:>7}'
.
format
(
self
.
auto_unit
(
self
.
stats
[
'buffers'
]))
ret
.
append
(
self
.
curse_add_line
(
msg
,
optional
=
self
.
get_views
(
key
=
'buffers'
,
option
=
'optional'
)))
# New line
ret
.
extend
(
self
.
curse_add_stat
(
'buffers'
,
width
=
18
,
header
=
' '
))
# Fourth line
# free + cached
ret
.
append
(
self
.
curse_new_line
())
# Free memory usage
msg
=
'{:6}'
.
format
(
'free:'
)
ret
.
append
(
self
.
curse_add_line
(
msg
))
msg
=
'{:>7}'
.
format
(
self
.
auto_unit
(
self
.
stats
[
'free'
]))
ret
.
append
(
self
.
curse_add_line
(
msg
))
ret
.
extend
(
self
.
curse_add_stat
(
'free'
,
width
=
15
))
# Cached memory usage
if
'cached'
in
self
.
stats
:
msg
=
' {:9}'
.
format
(
'cached:'
)
ret
.
append
(
self
.
curse_add_line
(
msg
,
optional
=
self
.
get_views
(
key
=
'cached'
,
option
=
'optional'
)))
msg
=
'{:>7}'
.
format
(
self
.
auto_unit
(
self
.
stats
[
'cached'
]))
ret
.
append
(
self
.
curse_add_line
(
msg
,
optional
=
self
.
get_views
(
key
=
'cached'
,
option
=
'optional'
)))
ret
.
extend
(
self
.
curse_add_stat
(
'cached'
,
width
=
18
,
header
=
' '
))
return
ret
glances/plugins/glances_memswap.py
浏览文件 @
c2da541c
...
...
@@ -28,17 +28,22 @@ import psutil
# Fields description
fields_description
=
{
'total'
:
{
'description'
:
'Total swap memory.'
,
'unit'
:
'bytes'
},
'unit'
:
'bytes'
,
'min_symbol'
:
'K'
},
'used'
:
{
'description'
:
'Used swap memory.'
,
'unit'
:
'bytes'
},
'unit'
:
'bytes'
,
'min_symbol'
:
'K'
},
'free'
:
{
'description'
:
'Free swap memory.'
,
'unit'
:
'bytes'
},
'unit'
:
'bytes'
,
'min_symbol'
:
'K'
},
'percent'
:
{
'description'
:
'Used swap memory in percentage.'
,
'unit'
:
'percent'
},
'sin'
:
{
'description'
:
'The number of bytes the system has swapped in from disk (cumulative).'
,
'unit'
:
'bytes'
},
'unit'
:
'bytes'
,
'min_symbol'
:
'K'
},
'sout'
:
{
'description'
:
'The number of bytes the system has swapped out from disk (cumulative).'
,
'unit'
:
'bytes'
},
'unit'
:
'bytes'
,
'min_symbol'
:
'K'
},
'time_since_update'
:
{
'description'
:
'Number of seconds since last update.'
,
'unit'
:
'seconds'
},
}
...
...
@@ -175,8 +180,8 @@ class Plugin(GlancesPlugin):
if
not
self
.
stats
or
self
.
is_disable
():
return
ret
#
Build the string messag
e
#
Header
#
First lin
e
#
total%
msg
=
'{}'
.
format
(
'SWAP'
)
ret
.
append
(
self
.
curse_add_line
(
msg
,
"TITLE"
))
msg
=
' {:3}'
.
format
(
self
.
trend_msg
(
self
.
get_trend
(
'percent'
)))
...
...
@@ -185,27 +190,23 @@ class Plugin(GlancesPlugin):
msg
=
'{:>6.1%}'
.
format
(
self
.
stats
[
'percent'
]
/
100
)
ret
.
append
(
self
.
curse_add_line
(
msg
,
self
.
get_views
(
key
=
'percent'
,
option
=
'decoration'
)))
# New line
# Second line
# total
ret
.
append
(
self
.
curse_new_line
())
# Total memory usage
msg
=
'{:8}'
.
format
(
'total:'
)
ret
.
append
(
self
.
curse_add_line
(
msg
))
msg
=
'{:>6}'
.
format
(
self
.
auto_unit
(
self
.
stats
[
'total'
]))
ret
.
append
(
self
.
curse_add_line
(
msg
))
# New line
ret
.
extend
(
self
.
curse_add_stat
(
'total'
,
width
=
16
))
# Third line
# used
ret
.
append
(
self
.
curse_new_line
())
# Used memory usage
msg
=
'{:8}'
.
format
(
'used:'
)
ret
.
append
(
self
.
curse_add_line
(
msg
))
msg
=
'{:>6}'
.
format
(
self
.
auto_unit
(
self
.
stats
[
'used'
]))
ret
.
append
(
self
.
curse_add_line
(
msg
,
self
.
get_views
(
key
=
'used'
,
option
=
'decoration'
)))
# New line
ret
.
extend
(
self
.
curse_add_stat
(
'used'
,
width
=
16
))
# Fourth line
# free
ret
.
append
(
self
.
curse_new_line
())
# Free memory usage
msg
=
'{:8}'
.
format
(
'free:'
)
ret
.
append
(
self
.
curse_add_line
(
msg
))
msg
=
'{:>6}'
.
format
(
self
.
auto_unit
(
self
.
stats
[
'free'
]))
ret
.
append
(
self
.
curse_add_line
(
msg
))
ret
.
extend
(
self
.
curse_add_stat
(
'free'
,
width
=
16
))
return
ret
glances/plugins/glances_plugin.py
浏览文件 @
c2da541c
...
...
@@ -43,8 +43,17 @@ fields_unit_short = {
fields_unit_type
=
{
'percent'
:
'float'
,
'percents'
:
'float'
,
'number'
:
'int'
,
'seconds'
:
'int'
'numbers'
:
'int'
,
'int'
:
'int'
,
'ints'
:
'int'
,
'float'
:
'float'
,
'floats'
:
'float'
,
'second'
:
'int'
,
'seconds'
:
'int'
,
'byte'
:
'int'
,
'bytes'
:
'int'
}
...
...
@@ -992,6 +1001,9 @@ class GlancesPlugin(object):
ret.extend(self.curse_add_stat('idle', width=15, header=' '))
"""
if
key
not
in
self
.
stats
:
return
[]
# Check if a shortname is defined
if
'short_name'
in
self
.
fields_description
[
key
]:
key_name
=
self
.
fields_description
[
key
][
'short_name'
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录