Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
dcd28b77
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,发现更多精彩内容 >>
提交
dcd28b77
编写于
9月 28, 2019
作者:
N
nicolargo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add a new TCP connections status plugin #1526 RC1
上级
66c9fff7
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
188 addition
and
2 deletion
+188
-2
conf/glances.conf
conf/glances.conf
+6
-1
docs/_static/connections.png
docs/_static/connections.png
+0
-0
docs/aoa/connections.rst
docs/aoa/connections.rst
+25
-0
glances/outputs/glances_curses.py
glances/outputs/glances_curses.py
+1
-1
glances/plugins/glances_connections.py
glances/plugins/glances_connections.py
+156
-0
未找到文件。
conf/glances.conf
浏览文件 @
dcd28b77
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
# Does Glances should check if a newer version is available on PyPI ?
# Does Glances should check if a newer version is available on PyPI ?
check_update
=
true
check_update
=
true
# History size (maximum number of values)
# History size (maximum number of values)
# Default is 28800: 1 day with 1 point every 3 seconds
(default refresh time)
# Default is 28800: 1 day with 1 point every 3 seconds
history_size
=
28800
history_size
=
28800
##############################################################################
##############################################################################
...
@@ -139,6 +139,11 @@ tx_critical=90
...
@@ -139,6 +139,11 @@ tx_critical=90
#wlan0_tx_critical=1000000
#wlan0_tx_critical=1000000
#wlan0_tx_log=True
#wlan0_tx_log=True
[
connections
]
# Display additional information about TCP connections
# This plugin will be disable by default
disable
=
True
[
wifi
]
[
wifi
]
# Define the list of hidden wireless network interfaces (comma-separated regexp)
# Define the list of hidden wireless network interfaces (comma-separated regexp)
hide
=
lo
,
docker
.*
hide
=
lo
,
docker
.*
...
...
docs/_static/connections.png
0 → 100644
浏览文件 @
dcd28b77
7.3 KB
docs/aoa/connections.rst
0 → 100644
浏览文件 @
dcd28b77
.. _connections:
Connections
===========
.. image:: ../_static/connections.png
This plugin display extended information about network connections.
The states are the following:
- Listen: all ports created by server and waiting for a client to connect
- Initialized: All states when a connection is initialized (sum of SYN_SENT and SYN_RECEIVED)
- Established: All established connections between a client and a server
- Terminated: All states when a connection is terminated (FIN_WAIT1, CLOSE_WAIT, LAST_ACK, FIN_WAIT2, TIME_WAIT and CLOSE)
The configuration should be done in the ``[connections]`` section of the
Glances configuration file.
By default the plugin is disabled.
.. code-block:: ini
[connections]
disable=False
glances/outputs/glances_curses.py
浏览文件 @
dcd28b77
...
@@ -96,7 +96,7 @@ class _GlancesCurses(object):
...
@@ -96,7 +96,7 @@ class _GlancesCurses(object):
_quicklook_max_width
=
68
_quicklook_max_width
=
68
# Define left sidebar
# Define left sidebar
_left_sidebar
=
[
'network'
,
'wifi'
,
'ports'
,
'diskio'
,
'fs'
,
_left_sidebar
=
[
'network'
,
'
connections'
,
'
wifi'
,
'ports'
,
'diskio'
,
'fs'
,
'irq'
,
'folders'
,
'raid'
,
'sensors'
,
'now'
]
'irq'
,
'folders'
,
'raid'
,
'sensors'
,
'now'
]
_left_sidebar_min_width
=
23
_left_sidebar_min_width
=
23
_left_sidebar_max_width
=
34
_left_sidebar_max_width
=
34
...
...
glances/plugins/glances_connections.py
0 → 100644
浏览文件 @
dcd28b77
# -*- coding: utf-8 -*-
#
# This file is part of Glances.
#
# Copyright (C) 2019 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/>.
"""Connections plugin."""
from
__future__
import
unicode_literals
from
glances.timer
import
getTimeSinceLastUpdate
from
glances.plugins.glances_plugin
import
GlancesPlugin
from
glances.compat
import
n
,
u
,
b
,
nativestr
import
psutil
# Define the history items list
# items_history_list = [{'name': 'rx',
# 'description': 'Download rate per second',
# 'y_unit': 'bit/s'},
# {'name': 'tx',
# 'description': 'Upload rate per second',
# 'y_unit': 'bit/s'}]
class
Plugin
(
GlancesPlugin
):
"""Glances connections plugin.
stats is a dict
"""
status_list
=
[
psutil
.
CONN_LISTEN
,
psutil
.
CONN_ESTABLISHED
]
initiated_states
=
[
psutil
.
CONN_SYN_SENT
,
psutil
.
CONN_SYN_RECV
]
terminated_states
=
[
psutil
.
CONN_FIN_WAIT1
,
psutil
.
CONN_FIN_WAIT2
,
psutil
.
CONN_TIME_WAIT
,
psutil
.
CONN_CLOSE
,
psutil
.
CONN_CLOSE_WAIT
,
psutil
.
CONN_LAST_ACK
]
def
__init__
(
self
,
args
=
None
,
config
=
None
):
"""Init the plugin."""
super
(
Plugin
,
self
).
__init__
(
args
=
args
,
config
=
config
,
# items_history_list=items_history_list,
stats_init_value
=
{})
# We want to display the stat in the curse interface
self
.
display_curse
=
True
@
GlancesPlugin
.
_check_decorator
@
GlancesPlugin
.
_log_result_decorator
def
update
(
self
):
"""Update connections stats using the input method.
Stats is a dict
"""
# Init new stats
stats
=
self
.
get_init_value
()
if
self
.
input_method
==
'local'
:
# Update stats using the PSUtils lib
# Grab network interface stat using the psutil net_connections method
try
:
net_connections
=
psutil
.
net_connections
(
kind
=
"tcp"
)
except
Exception
as
e
:
logger
.
debug
(
'Can not get network connections stats ({})'
.
format
(
e
))
return
self
.
stats
for
s
in
self
.
status_list
:
stats
[
s
]
=
len
([
c
for
c
in
net_connections
if
c
.
status
==
s
])
initiated
=
0
for
s
in
self
.
initiated_states
:
stats
[
s
]
=
len
([
c
for
c
in
net_connections
if
c
.
status
==
s
])
initiated
+=
stats
[
s
]
stats
[
'initiated'
]
=
initiated
terminated
=
0
for
s
in
self
.
initiated_states
:
stats
[
s
]
=
len
([
c
for
c
in
net_connections
if
c
.
status
==
s
])
terminated
+=
stats
[
s
]
stats
[
'terminated'
]
=
terminated
elif
self
.
input_method
==
'snmp'
:
# Update stats using SNMP
pass
# Update the stats
self
.
stats
=
stats
return
self
.
stats
def
update_views
(
self
):
"""Update stats views."""
# Call the father's method
super
(
Plugin
,
self
).
update_views
()
# Add specifics informations
# Alert
# for i in self.stats:
# ifrealname = i['interface_name'].split(':')[0]
# # Convert rate in bps ( to be able to compare to interface speed)
# bps_rx = int(i['rx'] // i['time_since_update'] * 8)
# bps_tx = int(i['tx'] // i['time_since_update'] * 8)
# # Decorate the bitrate with the configuration file thresolds
# alert_rx = self.get_alert(bps_rx, header=ifrealname + '_rx')
# alert_tx = self.get_alert(bps_tx, header=ifrealname + '_tx')
# # If nothing is define in the configuration file...
# # ... then use the interface speed (not available on all systems)
# if alert_rx == 'DEFAULT' and 'speed' in i and i['speed'] != 0:
# alert_rx = self.get_alert(current=bps_rx,
# maximum=i['speed'],
# header='rx')
# if alert_tx == 'DEFAULT' and 'speed' in i and i['speed'] != 0:
# alert_tx = self.get_alert(current=bps_tx,
# maximum=i['speed'],
# header='tx')
# # then decorates
# self.views[i[self.get_key()]]['rx']['decoration'] = alert_rx
# self.views[i[self.get_key()]]['tx']['decoration'] = alert_tx
def
msg_curse
(
self
,
args
=
None
,
max_width
=
None
):
"""Return the dict to display in the curse interface."""
# Init the return message
ret
=
[]
# Only process if stats exist and display plugin enable...
if
not
self
.
stats
or
self
.
is_disable
():
return
ret
# Header
msg
=
'{}'
.
format
(
'TCP CONNECTIONS'
)
ret
.
append
(
self
.
curse_add_line
(
msg
,
"TITLE"
))
# Connections status
for
s
in
[
psutil
.
CONN_LISTEN
,
'initiated'
,
psutil
.
CONN_ESTABLISHED
,
'terminated'
]:
ret
.
append
(
self
.
curse_new_line
())
msg
=
'{:{width}}'
.
format
(
nativestr
(
s
).
capitalize
(),
width
=
len
(
s
))
ret
.
append
(
self
.
curse_add_line
(
msg
))
msg
=
'{:>{width}}'
.
format
(
self
.
stats
[
s
],
width
=
max_width
-
len
(
s
)
+
2
)
ret
.
append
(
self
.
curse_add_line
(
msg
))
return
ret
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录