Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
caeb0719
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 搜索 >>
提交
caeb0719
编写于
8月 01, 2017
作者:
N
Nicolas Hennion
提交者:
GitHub
8月 01, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1130 from dsouzajude/export-json
Export json
上级
38d66874
12ae6708
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
84 addition
and
0 deletion
+84
-0
NEWS
NEWS
+1
-0
docs/gw/index.rst
docs/gw/index.rst
+1
-0
docs/gw/json.rst
docs/gw/json.rst
+16
-0
glances/exports/glances_json.py
glances/exports/glances_json.py
+64
-0
glances/main.py
glances/main.py
+2
-0
未找到文件。
NEWS
浏览文件 @
caeb0719
...
...
@@ -9,6 +9,7 @@ Enhancements and new features:
* [WIP] Refactoring of the WebUI
* New export plugin: standard and configurable Restfull exporter (issue #1129)
* Add a JSON export module
Bugs corrected:
...
...
docs/gw/index.rst
浏览文件 @
caeb0719
...
...
@@ -10,6 +10,7 @@ to providing stats to multiple services (see list below).
:maxdepth: 2
csv
json
cassandra
couchdb
elastic
...
...
docs/gw/json.rst
0 → 100644
浏览文件 @
caeb0719
.. _json:
JSON
====
It's possible to export stats to a JSON file to be processed later by an
external system.
.. code-block:: console
$ glances --export-json /tmp/glances.json
JSON file description:
Each line would contain a JSON glance of the system. If this file needs to be
processed it should be processed in a line by line basis.
glances/exports/glances_json.py
0 → 100644
浏览文件 @
caeb0719
"""JSON interface class."""
import
sys
import
json
from
glances.compat
import
PY3
,
listkeys
from
glances.logger
import
logger
from
glances.exports.glances_export
import
GlancesExport
class
Export
(
GlancesExport
):
"""This class manages the JSON export module."""
def
__init__
(
self
,
config
=
None
,
args
=
None
):
"""Init the JSON export IF."""
super
(
Export
,
self
).
__init__
(
config
=
config
,
args
=
args
)
# JSON file name
self
.
json_filename
=
args
.
export_json
# Set the JSON output file
try
:
if
PY3
:
self
.
json_file
=
open
(
self
.
json_filename
,
'w'
)
else
:
self
.
json_file
=
open
(
self
.
json_filename
,
'wb'
)
except
IOError
as
e
:
logger
.
critical
(
"Cannot create the JSON file: {}"
.
format
(
e
))
sys
.
exit
(
2
)
logger
.
info
(
"Exporting stats to file: {}"
.
format
(
self
.
json_filename
))
self
.
export_enable
=
True
# Buffer for dict of stats
self
.
buffer
=
{}
def
exit
(
self
):
"""Close the JSON file."""
logger
.
debug
(
"Finalise export interface %s"
%
self
.
export_name
)
self
.
json_file
.
close
()
def
export
(
self
,
name
,
columns
,
points
):
"""Export the stats to the JSON file."""
# Check for completion of loop for all exports
if
name
==
self
.
plugins_to_export
()[
0
]
and
self
.
buffer
!=
{}:
# One whole loop has been completed
# Flush stats to file
logger
.
debug
(
"Exporting stats ({}) to JSON file ({})"
.
format
(
listkeys
(
self
.
buffer
),
self
.
json_filename
)
)
# Export stats to JSON file
data_json
=
json
.
dumps
(
self
.
buffer
)
self
.
json_file
.
write
(
"{}
\n
"
.
format
(
data_json
))
# Reset buffer
self
.
buffer
=
{}
# Add current stat to the buffer
self
.
buffer
[
name
]
=
dict
(
zip
(
columns
,
points
))
glances/main.py
浏览文件 @
caeb0719
...
...
@@ -173,6 +173,8 @@ Examples of use:
dest
=
'path_graph'
,
help
=
'set the export path for graphs (default is {})'
.
format
(
tempfile
.
gettempdir
()))
parser
.
add_argument
(
'--export-csv'
,
default
=
None
,
dest
=
'export_csv'
,
help
=
'export stats to a CSV file'
)
parser
.
add_argument
(
'--export-json'
,
default
=
None
,
dest
=
'export_json'
,
help
=
'export stats to a JSON file'
)
parser
.
add_argument
(
'--export-cassandra'
,
action
=
'store_true'
,
default
=
False
,
dest
=
'export_cassandra'
,
help
=
'export stats to a Cassandra or Scylla server (cassandra lib needed)'
)
parser
.
add_argument
(
'--export-couchdb'
,
action
=
'store_true'
,
default
=
False
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录