Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
fede5024
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,发现更多精彩内容 >>
提交
fede5024
编写于
1月 20, 2019
作者:
N
nicolargo
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'develop' of
https://github.com/nicolargo/glances
into develop
上级
0a948d87
15fba1b8
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
78 addition
and
10 deletion
+78
-10
.gitignore
.gitignore
+2
-2
conf/glances.conf
conf/glances.conf
+3
-0
glances/exports/glances_cassandra.py
glances/exports/glances_cassandra.py
+13
-3
glances/outputs/glances_curses_browser.py
glances/outputs/glances_curses_browser.py
+60
-5
未找到文件。
.gitignore
浏览文件 @
fede5024
...
...
@@ -48,5 +48,5 @@ _build
node_modules/
bower_components/
# visual stdio code
.vscode/
\ No newline at end of file
# visual stdio code
.vscode/
conf/glances.conf
浏览文件 @
fede5024
...
...
@@ -365,6 +365,9 @@ keyspace=glances
replication_factor
=
2
# If not define, table name is set to host key
table
=
localhost
# If not define, username and password will not be used
#username=cassandra
#password=password
[
opentsdb
]
# Configuration for the --export opentsdb option
...
...
glances/exports/glances_cassandra.py
浏览文件 @
fede5024
...
...
@@ -27,6 +27,7 @@ from glances.logger import logger
from
glances.exports.glances_export
import
GlancesExport
from
glances.compat
import
iteritems
from
cassandra.auth
import
PlainTextAuthProvider
from
cassandra.cluster
import
Cluster
from
cassandra.util
import
uuid_from_time
from
cassandra
import
InvalidRequest
...
...
@@ -47,13 +48,17 @@ class Export(GlancesExport):
self
.
protocol_version
=
3
self
.
replication_factor
=
2
self
.
table
=
None
self
.
username
=
None
self
.
password
=
None
# Load the Cassandra configuration file section
self
.
export_enable
=
self
.
load_conf
(
'cassandra'
,
mandatories
=
[
'host'
,
'port'
,
'keyspace'
],
options
=
[
'protocol_version'
,
'replication_factor'
,
'table'
])
'table'
,
'username'
,
'password'
])
if
not
self
.
export_enable
:
sys
.
exit
(
2
)
...
...
@@ -61,15 +66,20 @@ class Export(GlancesExport):
self
.
cluster
,
self
.
session
=
self
.
init
()
def
init
(
self
):
"""Init the connection to the
InfluxDB
server."""
"""Init the connection to the
Cassandra
server."""
if
not
self
.
export_enable
:
return
None
# if username and/or password are not set the connection will try to connect with no auth
auth_provider
=
PlainTextAuthProvider
(
username
=
self
.
username
,
password
=
self
.
password
)
# Cluster
try
:
cluster
=
Cluster
([
self
.
host
],
port
=
int
(
self
.
port
),
protocol_version
=
int
(
self
.
protocol_version
))
protocol_version
=
int
(
self
.
protocol_version
),
auth_provider
=
auth_provider
)
session
=
cluster
.
connect
()
except
Exception
as
e
:
logger
.
critical
(
"Cannot connect to Cassandra cluster '%s:%s' (%s)"
%
(
self
.
host
,
self
.
port
,
e
))
...
...
glances/outputs/glances_curses_browser.py
浏览文件 @
fede5024
...
...
@@ -62,6 +62,8 @@ class GlancesCursesBrowser(_GlancesCurses):
self
.
_page_max_lines
=
0
self
.
is_end
=
False
self
.
_revesed_sorting
=
False
self
.
_stats_list
=
None
@
property
def
active_server
(
self
):
...
...
@@ -90,6 +92,33 @@ class GlancesCursesBrowser(_GlancesCurses):
page_lines
=
self
.
_page_max_lines
return
page_lines
def
_get_status_count
(
self
,
stats
):
counts
=
{}
for
item
in
stats
:
color
=
item
[
'status'
]
counts
[
color
]
=
counts
.
get
(
color
,
0
)
+
1
result
=
''
for
key
in
counts
.
keys
():
result
+=
key
+
': '
+
str
(
counts
[
key
])
+
' '
return
result
def
_get_stats
(
self
,
stats
):
stats_list
=
None
if
self
.
_stats_list
is
not
None
:
stats_list
=
self
.
_stats_list
stats_list
.
sort
(
reverse
=
self
.
_revesed_sorting
,
key
=
lambda
x
:
{
'UNKNOWN'
:
0
,
'OFFLINE'
:
1
,
'PROTECTED'
:
2
,
'SNMP'
:
3
,
'ONLINE'
:
4
}.
get
(
x
[
'status'
],
99
))
else
:
stats_list
=
stats
return
stats_list
def
cursor_up
(
self
,
stats
):
"""Set the cursor to position N-1 in the list."""
if
0
<=
self
.
cursor_position
-
1
:
...
...
@@ -133,7 +162,7 @@ class GlancesCursesBrowser(_GlancesCurses):
def
__catch_key
(
self
,
stats
):
# Catch the browser pressed key
self
.
pressedkey
=
self
.
get_key
(
self
.
term_window
)
refresh
=
False
if
self
.
pressedkey
!=
-
1
:
logger
.
debug
(
"Key pressed. Code=%s"
%
self
.
pressedkey
)
...
...
@@ -164,6 +193,22 @@ class GlancesCursesBrowser(_GlancesCurses):
# 'Page Down' > Next page in the server list
self
.
cursor_pagedown
(
stats
)
logger
.
debug
(
"PageDown: Server {}/{} pages"
.
format
(
self
.
_current_page
+
1
,
self
.
_page_max
))
elif
self
.
pressedkey
==
ord
(
'1'
):
self
.
_stats_list
=
None
refresh
=
True
elif
self
.
pressedkey
==
ord
(
'2'
):
self
.
_revesed_sorting
=
False
self
.
_stats_list
=
stats
.
copy
()
refresh
=
True
elif
self
.
pressedkey
==
ord
(
'3'
):
self
.
_revesed_sorting
=
True
self
.
_stats_list
=
stats
.
copy
()
refresh
=
True
if
refresh
:
self
.
_current_page
=
0
self
.
cursor_position
=
0
self
.
flush
(
stats
)
# Return the key code
return
self
.
pressedkey
...
...
@@ -248,12 +293,21 @@ class GlancesCursesBrowser(_GlancesCurses):
msg
,
screen_x
-
x
,
self
.
colors_list
[
'TITLE'
])
if
stats_len
>
stats_max
and
screen_y
>
2
:
msg
=
'{}
servers displayed.({}/{})'
.
format
(
self
.
get_pagelines
(
stats
),
self
.
_current_page
+
1
,
self
.
_page_max
)
msg
=
'{}
'
.
format
(
self
.
_get_status_count
(
stats
)
)
self
.
term_window
.
addnstr
(
y
+
1
,
x
,
msg
,
screen_x
-
x
)
if
stats_len
>
stats_max
and
screen_y
>
2
:
msg
=
'{} servers displayed.({}/{}) {}'
.
format
(
self
.
get_pagelines
(
stats
),
self
.
_current_page
+
1
,
self
.
_page_max
,
self
.
_get_status_count
(
stats
))
self
.
term_window
.
addnstr
(
y
+
1
,
x
,
msg
,
screen_x
-
x
)
if
stats_len
==
0
:
return
False
...
...
@@ -292,9 +346,10 @@ class GlancesCursesBrowser(_GlancesCurses):
# Set the cursor position to the latest item
self
.
cursor
=
len
(
stats
)
-
1
stats_list
=
self
.
_get_stats
(
stats
)
start_line
=
self
.
_page_max_lines
*
self
.
_current_page
end_line
=
start_line
+
self
.
get_pagelines
(
stats
)
current_page
=
stats
[
start_line
:
end_line
]
end_line
=
start_line
+
self
.
get_pagelines
(
stats
_list
)
current_page
=
stats
_list
[
start_line
:
end_line
]
# Display table
line
=
0
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录