Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
bad96d34
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 搜索 >>
提交
bad96d34
编写于
4月 25, 2016
作者:
N
Nicolargo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add Systemd AMP
上级
84a40237
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
122 addition
and
18 deletion
+122
-18
conf/glances.conf
conf/glances.conf
+9
-1
glances/amps/glances_amp.py
glances/amps/glances_amp.py
+13
-7
glances/amps/glances_nginx.py
glances/amps/glances_nginx.py
+6
-9
glances/amps/glances_systemd.py
glances/amps/glances_systemd.py
+92
-0
glances/plugins/glances_amps.py
glances/plugins/glances_amps.py
+2
-1
未找到文件。
conf/glances.conf
浏览文件 @
bad96d34
...
...
@@ -254,10 +254,18 @@ queue=glances_queue
# AMPS
######
[
nginx
]
[
amp_
nginx
]
# Nginx status page should be enable (https://easyengine.io/tutorials/nginx/status-page/)
enable
=
true
regex
=\/
usr
\/
sbin
\/
nginx
refresh
=
60
one_line
=
false
status_url
=
http
://
localhost
/
nginx_status
[
amp_systemd
]
# Systemd
enable
=
true
regex
=\/
usr
\/
lib
\/
systemd
\/
systemd
refresh
=
30
one_line
=
true
systemctl_path
=/
usr
/
bin
/
systemctl
--
plain
glances/amps/glances_amp.py
浏览文件 @
bad96d34
...
...
@@ -80,14 +80,15 @@ class GlancesAmp(object):
# option1=opt1
# ...
#
amp_section
=
'amp_'
+
self
.
amp_name
if
(
hasattr
(
config
,
'has_section'
)
and
config
.
has_section
(
self
.
amp_name
)):
config
.
has_section
(
amp_section
)):
logger
.
debug
(
"{0}: Load configuration"
.
format
(
self
.
NAME
))
for
param
,
_
in
config
.
items
(
self
.
amp_name
):
for
param
,
_
in
config
.
items
(
amp_section
):
try
:
self
.
configs
[
param
]
=
config
.
get_float_value
(
self
.
amp_name
,
param
)
self
.
configs
[
param
]
=
config
.
get_float_value
(
amp_section
,
param
)
except
ValueError
:
self
.
configs
[
param
]
=
config
.
get_value
(
self
.
amp_name
,
param
).
split
(
','
)
self
.
configs
[
param
]
=
config
.
get_value
(
amp_section
,
param
).
split
(
','
)
if
len
(
self
.
configs
[
param
])
==
1
:
self
.
configs
[
param
]
=
self
.
configs
[
param
][
0
]
logger
.
debug
(
"{0}: Load parameter: {1} = {2}"
.
format
(
self
.
NAME
,
param
,
self
.
configs
[
param
]))
...
...
@@ -153,9 +154,14 @@ class GlancesAmp(object):
return
self
.
enable
()
return
False
def
set_result
(
self
,
result
):
"""Store the result (string) into the result key of the AMP"""
self
.
configs
[
'result'
]
=
str
(
result
)
def
set_result
(
self
,
result
,
separator
=
''
):
"""Store the result (string) into the result key of the AMP
if one_line is true then replace
\n
by separator
"""
if
self
.
one_line
():
self
.
configs
[
'result'
]
=
str
(
result
).
replace
(
'
\n
'
,
separator
)
else
:
self
.
configs
[
'result'
]
=
str
(
result
)
def
result
(
self
):
""" Return the result of the AMP (as a string)"""
...
...
glances/amps/glances_nginx.py
浏览文件 @
bad96d34
...
...
@@ -44,7 +44,7 @@ Source (https://easyengine.io/tutorials/nginx/status-page/)
Configuration file example
--------------------------
[nginx]
[
amp_
nginx]
# Nginx status page should be enable (https://easyengine.io/tutorials/nginx/status-page/)
enable=true
regex=\/usr\/sbin\/nginx
...
...
@@ -62,7 +62,7 @@ from glances.amps.glances_amp import GlancesAmp
class
Amp
(
GlancesAmp
):
"""Glances' Nginx AMP."""
NAME
=
'Nginx
Glances AMP
'
NAME
=
'Nginx'
VERSION
=
'1.0'
DESCRIPTION
=
'Get Nginx stats from status-page'
AUTHOR
=
'Nicolargo'
...
...
@@ -78,14 +78,11 @@ class Amp(GlancesAmp):
if
self
.
should_update
():
# Get the Nginx status
logger
.
debug
(
'{0}: Update stats using status URL {1}'
.
format
(
self
.
NAME
,
self
.
get
(
'status_url'
)))
re
q
=
requests
.
get
(
self
.
get
(
'status_url'
))
if
re
q
.
ok
:
re
s
=
requests
.
get
(
self
.
get
(
'status_url'
))
if
re
s
.
ok
:
# u'Active connections: 1 \nserver accepts handled requests\n 1 1 1 \nReading: 0 Writing: 1 Waiting: 0 \n'
if
self
.
one_line
():
self
.
set_result
(
req
.
text
.
replace
(
'
\n
'
,
''
))
else
:
self
.
set_result
(
req
.
text
)
self
.
set_result
(
res
.
text
)
else
:
logger
.
debug
(
'{0}: Can not grab status URL {1} ({2})'
.
format
(
self
.
NAME
,
self
.
get
(
'status_url'
),
re
q
.
reason
))
logger
.
debug
(
'{0}: Can not grab status URL {1} ({2})'
.
format
(
self
.
NAME
,
self
.
get
(
'status_url'
),
re
s
.
reason
))
return
self
.
result
()
glances/amps/glances_systemd.py
0 → 100644
浏览文件 @
bad96d34
# -*- 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/>.
"""
Systemd AMP
===========
Monitor the Systemd.
How to read the stats
---------------------
...
Configuration file example
--------------------------
[amp_systemd]
# Systemd
enable=true
regex=\/usr\/lib\/systemd\/systemd
refresh=30
one_line=true
systemctl_path=/usr/bin/systemctl
"""
from
subprocess
import
check_output
from
glances.logger
import
logger
from
glances.compat
import
iteritems
from
glances.amps.glances_amp
import
GlancesAmp
class
Amp
(
GlancesAmp
):
"""Glances' Systemd AMP."""
NAME
=
'Systemd'
VERSION
=
'1.0'
DESCRIPTION
=
'Get daemon list from systemctl (systemd)'
AUTHOR
=
'Nicolargo'
EMAIL
=
'contact@nicolargo.com'
# def __init__(self, args=None):
# """Init the AMP."""
# super(Amp, self).__init__(args=args)
def
update
(
self
):
"""Update the AMP"""
if
self
.
should_update
():
# Get the systemctl status
logger
.
debug
(
'{0}: Update stats using systemctl {1}'
.
format
(
self
.
NAME
,
self
.
get
(
'systemctl_path'
)))
try
:
res
=
check_output
(
self
.
get
(
'systemctl_path'
).
split
())
except
OSError
as
e
:
logger
.
debug
(
'{0}: Error while executing systemctl ({1})'
.
format
(
self
.
NAME
,
e
))
else
:
status
=
{}
# For each line
for
r
in
res
.
split
(
'
\n
'
)[
1
:
-
8
]:
# Split per space .*
l
=
r
.
split
()
if
len
(
l
)
>
3
:
# load column
for
c
in
range
(
1
,
3
):
try
:
status
[
l
[
c
]]
+=
1
except
KeyError
:
status
[
l
[
c
]]
=
1
# Build the output (string) message
output
=
'Services
\n
'
for
k
,
v
in
iteritems
(
status
):
output
+=
'{0}: {1}
\n
'
.
format
(
k
,
v
)
self
.
set_result
(
output
,
separator
=
' '
)
return
self
.
result
()
glances/plugins/glances_amps.py
浏览文件 @
bad96d34
...
...
@@ -58,6 +58,7 @@ class Plugin(GlancesPlugin):
for
k
,
v
in
iteritems
(
self
.
glances_amps
.
update
()):
# self.stats.append({k: v.result()})
self
.
stats
.
append
({
'key'
:
k
,
'name'
:
v
.
NAME
,
'result'
:
v
.
result
(),
'refresh'
:
v
.
refresh
(),
'timer'
:
v
.
time_until_refresh
()})
...
...
@@ -82,7 +83,7 @@ class Plugin(GlancesPlugin):
if
m
[
'result'
]
is
None
:
continue
# Display AMP
first_column
=
'{0}'
.
format
(
m
[
'
key
'
])
first_column
=
'{0}'
.
format
(
m
[
'
name
'
])
# first_column = '{0} {1}/{2}'.format(m['key'], int(m['timer']), int(m['refresh']))
for
l
in
m
[
'result'
].
split
(
'
\n
'
):
# Display first column with the process name...
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录