Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
a38b6b48
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 搜索 >>
提交
a38b6b48
编写于
6月 13, 2016
作者:
N
nicolargo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
First release for the TCP ports scanner plugin. TODO: test and doc
上级
18100648
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
147 addition
and
7 deletion
+147
-7
conf/glances.conf
conf/glances.conf
+22
-1
glances/main.py
glances/main.py
+2
-0
glances/outputs/glances_curses.py
glances/outputs/glances_curses.py
+9
-1
glances/ports_list.py
glances/ports_list.py
+92
-0
glances/static_list.py
glances/static_list.py
+4
-4
glances/stats.py
glances/stats.py
+1
-1
glances/timer.py
glances/timer.py
+17
-0
未找到文件。
conf/glances.conf
浏览文件 @
a38b6b48
...
...
@@ -179,6 +179,27 @@ mem_careful=50
mem_warning
=
70
mem_critical
=
90
[
ports
]
# TCP Ports scanner plugin configuration
# Interval in second between scan
refresh
=
30
# Set the timeout for a scan
timeout
=
3
# Define the scan list
# host (name or IP) and port (TCP) are mandatory
# description is optinal (set to host:port)
port_1_host
=
www
.
google
.
com
port_1_port
=
443
port_1_description
=
Internet
port_2_host
=
www
.
free
.
fr
port_2_port
=
80
port_2_description
=
ISP
port_3_host
=
192
.
168
.
0
.
1
port_3_port
=
80
port_3_description
=
Home
Box
port_4_host
=
192
.
168
.
5
.
1
port_4_port
=
80
##############################################################################
# Client/server
##############################################################################
...
...
@@ -202,7 +223,7 @@ mem_critical=90
# Where: host is the hostname
# password is the clear password
# Additionally (and optionally) a default password could be defined
#
xps
=abc
#
localhost
=abc
#default=defaultpassword
##############################################################################
...
...
glances/main.py
浏览文件 @
a38b6b48
...
...
@@ -114,6 +114,8 @@ Start the client browser (browser mode):\n\
dest
=
'disable_load'
,
help
=
'disable load module'
)
parser
.
add_argument
(
'--disable-network'
,
action
=
'store_true'
,
default
=
False
,
dest
=
'disable_network'
,
help
=
'disable network module'
)
parser
.
add_argument
(
'--disable-ports'
,
action
=
'store_true'
,
default
=
False
,
dest
=
'disable_ports'
,
help
=
'disable ports scanner module'
)
parser
.
add_argument
(
'--disable-ip'
,
action
=
'store_true'
,
default
=
False
,
dest
=
'disable_ip'
,
help
=
'disable IP module'
)
parser
.
add_argument
(
'--disable-diskio'
,
action
=
'store_true'
,
default
=
False
,
...
...
glances/outputs/glances_curses.py
浏览文件 @
a38b6b48
...
...
@@ -412,6 +412,9 @@ class _GlancesCurses(object):
# 'p' > Sort processes by name
glances_processes
.
auto_sort
=
False
glances_processes
.
sort_key
=
'name'
elif
self
.
pressedkey
==
ord
(
'P'
):
# 'P' > Disable ports scan plugins
self
.
args
.
disable_ports
=
not
self
.
args
.
disable_ports
elif
self
.
pressedkey
==
ord
(
'r'
):
# 'r' > Reset history
self
.
reset_history_tag
=
not
self
.
reset_history_tag
...
...
@@ -548,6 +551,8 @@ class _GlancesCurses(object):
args
=
self
.
args
)
stats_sensors
=
stats
.
get_plugin
(
'sensors'
).
get_stats_display
(
args
=
self
.
args
)
stats_ports
=
stats
.
get_plugin
(
'ports'
).
get_stats_display
(
args
=
self
.
args
)
stats_now
=
stats
.
get_plugin
(
'now'
).
get_stats_display
()
stats_docker
=
stats
.
get_plugin
(
'docker'
).
get_stats_display
(
args
=
self
.
args
)
...
...
@@ -704,10 +709,11 @@ class _GlancesCurses(object):
self
.
saved_line
=
self
.
next_line
# ==================================================================
# Display left sidebar (NETWORK+DISKIO+FS+SENSORS+Current time)
# Display left sidebar (NETWORK+
PORTS+
DISKIO+FS+SENSORS+Current time)
# ==================================================================
self
.
init_column
()
if
not
(
self
.
args
.
disable_network
and
self
.
args
.
disable_ports
and
self
.
args
.
disable_diskio
and
self
.
args
.
disable_fs
and
self
.
args
.
disable_folder
and
...
...
@@ -716,6 +722,8 @@ class _GlancesCurses(object):
self
.
new_line
()
self
.
display_plugin
(
stats_network
)
self
.
new_line
()
self
.
display_plugin
(
stats_ports
)
self
.
new_line
()
self
.
display_plugin
(
stats_diskio
)
self
.
new_line
()
self
.
display_plugin
(
stats_fs
)
...
...
glances/ports_list.py
0 → 100644
浏览文件 @
a38b6b48
# -*- coding: utf-8 -*-
#
# This file is part of Glances.
#
# Copyright (C) 2016 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/>.
"""Manage the Glances ports list (Ports plugin)."""
from
glances.compat
import
range
from
glances.logger
import
logger
class
GlancesPortsList
(
object
):
"""Manage the ports list for the ports plugin."""
_section
=
"ports"
_default_refresh
=
60
_default_timeout
=
3
def
__init__
(
self
,
config
=
None
,
args
=
None
):
# ports_list is a list of dict (JSON compliant)
# [ {'host': 'www.google.fr', 'port': 443, 'refresh': 30, 'description': Internet, 'status': True} ... ]
# Load the configuration file
self
.
_ports_list
=
self
.
load
(
config
)
def
load
(
self
,
config
):
"""Load the ports list from the configuration file."""
ports_list
=
[]
if
config
is
None
:
logger
.
debug
(
"No configuration file available. Cannot load ports list."
)
elif
not
config
.
has_section
(
self
.
_section
):
logger
.
warning
(
"No [%s] section in the configuration file. Cannot load ports list."
%
self
.
_section
)
else
:
logger
.
debug
(
"Start reading the [%s] section in the configuration file"
%
self
.
_section
)
refresh
=
config
.
get_value
(
self
.
_section
,
'refresh'
,
default
=
self
.
_default_refresh
)
timeout
=
config
.
get_value
(
self
.
_section
,
'timeout'
,
default
=
self
.
_default_timeout
)
for
i
in
range
(
1
,
256
):
new_port
=
{}
postfix
=
'port_%s_'
%
str
(
i
)
# Read mandatories configuration keys: host and port
for
s
in
[
'host'
,
'port'
]:
new_port
[
s
]
=
config
.
get_value
(
self
.
_section
,
'%s%s'
%
(
postfix
,
s
))
if
new_port
[
'host'
]
is
None
or
new_port
[
'port'
]
is
None
:
continue
# Read optionals configuration keys
new_port
[
'description'
]
=
config
.
get_value
(
self
.
_section
,
'%sdescription'
%
postfix
,
default
=
"%s:%s"
%
(
new_port
[
'host'
],
new_port
[
'port'
]))
# Default status
new_port
[
'status'
]
=
None
# Refresh rate in second
new_port
[
'refresh'
]
=
refresh
# Timeout in second
new_port
[
'timeout'
]
=
timeout
# Add the server to the list
logger
.
debug
(
"Add port %s:%s to the static list"
%
(
new_port
[
'host'
],
new_port
[
'port'
]))
ports_list
.
append
(
new_port
)
# Ports list loaded
logger
.
debug
(
"Ports list loaded: %s"
%
ports_list
)
return
ports_list
def
get_ports_list
(
self
):
"""Return the current server list (dict of dict)."""
return
self
.
_ports_list
def
set_server
(
self
,
pos
,
key
,
value
):
"""Set the key to the value for the pos (position in the list)."""
self
.
_ports_list
[
pos
][
key
]
=
value
glances/static_list.py
浏览文件 @
a38b6b48
...
...
@@ -2,7 +2,7 @@
#
# This file is part of Glances.
#
# Copyright (C) 201
5
Nicolargo <nicolas@nicolargo.com>
# Copyright (C) 201
6
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
...
...
@@ -32,7 +32,7 @@ class GlancesStaticServer(object):
_section
=
"serverlist"
def
__init__
(
self
,
config
=
None
,
args
=
None
):
# server_
dic
t is a list of dict (JSON compliant)
# server_
lis
t is a list of dict (JSON compliant)
# [ {'key': 'zeroconf name', ip': '172.1.2.3', 'port': 61209, 'cpu': 3, 'mem': 34 ...} ... ]
# Load the configuration file
self
.
_server_list
=
self
.
load
(
config
)
...
...
@@ -42,7 +42,7 @@ class GlancesStaticServer(object):
server_list
=
[]
if
config
is
None
:
logger
.
warnin
g
(
"No configuration file available. Cannot load server list."
)
logger
.
debu
g
(
"No configuration file available. Cannot load server list."
)
elif
not
config
.
has_section
(
self
.
_section
):
logger
.
warning
(
"No [%s] section in the configuration file. Cannot load server list."
%
self
.
_section
)
else
:
...
...
@@ -84,7 +84,7 @@ class GlancesStaticServer(object):
return
server_list
def
get_servers_list
(
self
):
"""Return the current server list (
dic
t of dict)."""
"""Return the current server list (
lis
t of dict)."""
return
self
.
_server_list
def
set_server
(
self
,
server_pos
,
key
,
value
):
...
...
glances/stats.py
浏览文件 @
a38b6b48
...
...
@@ -97,7 +97,7 @@ class GlancesStats(object):
# for example, the file glances_xxx.py
# generate self._plugins_list["xxx"] = ...
plugin_name
=
os
.
path
.
basename
(
item
)[
len
(
header
):
-
3
].
lower
()
if
plugin_name
in
(
'help'
,
'amps'
):
if
plugin_name
in
(
'help'
,
'amps'
,
'ports'
):
self
.
_plugins
[
plugin_name
]
=
plugin
.
Plugin
(
args
=
args
,
config
=
self
.
config
)
else
:
self
.
_plugins
[
plugin_name
]
=
plugin
.
Plugin
(
args
=
args
)
...
...
glances/timer.py
浏览文件 @
a38b6b48
...
...
@@ -61,3 +61,20 @@ class Timer(object):
def
finished
(
self
):
return
time
()
>
self
.
target
class
Counter
(
object
):
"""The counter class."""
def
__init__
(
self
):
self
.
start
()
def
start
(
self
):
self
.
target
=
time
()
def
reset
(
self
):
self
.
start
()
def
get
(
self
):
return
time
()
-
self
.
target
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录