-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmnt_instruction.py
76 lines (60 loc) · 2.34 KB
/
mnt_instruction.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# -*- coding: utf-8 -*-
import settings
from manipRRD import RRDManip
from instruction import figure_path
_rrds = {}
_graph_args = {}
def register_mnt_rrd(target, dsNames, dsType='GAUGE'):
"""Register a RRDManip.
:param target: 用于构造 rrd 文件名以及做为内部rrd对象缓存的 key
:param dsName: 用于指定 data source 的命名
:param dsType: 用于指定 data source 类型
"""
global _rrds
if (target not in _rrds) or (_rrds[target] is None):
filepath = figure_path(target)
roundRobinArchives = settings.PRECISE_MAX_RRA + \
settings.PRECISE_AVERAGE_RRA
dataSources = []
for dsname in dsNames:
datasource = settings.DataSource.copy()
datasource['dsName'] = dsname
datasource['dsType'] = dsType
dataSources.append(datasource)
_rrds[target] = RRDManip(filepath, settings.STEP,
dataSources, roundRobinArchives)
_rrds[target].ensure_rrd()
def get_mnt_rrd(target):
"""
获取 rrd 控制类,根据 target 缓存该对象。
"""
global _rrds
if target not in _rrds:
_rrds[target] = None
return _rrds[target]
def load_mnt_rrd(target):
"""
类似于 get_mnt_rrd,获取 rrd 控制对象,根据 target 缓存该对象。不同的是,
get_mnt_rrd 发现 target 不存在缓存中时,会直接返回 None,而 load_mnt_rrd
会创建 rrd 再返回控制对象。
:note: 使用 load_mnt_rrd 的默认前提是 target 对应的 rrd 控制对象是已经创建了。
"""
global _rrds
if target not in _rrds:
filepath = figure_path(target)
_rrds[target] = RRDManip(filepath, None, None, None)
_rrds[target].ensure_rrd()
return _rrds[target]
def register_graph_args(target, prep_args):
"""Register the RRDGraph preparing arguments.
:param target: 用于构造 rrd 文件名以及做为内部rrd对象缓存的 key
:param prep_args: 确定设置 RRDGraph 的所需参数,为 dict 类型
"""
global _graph_args
if (target not in _graph_args) or (_graph_args[target] is None):
_graph_args[target] = prep_args
def get_graph_args(target):
global _graph_args
if target not in _graph_args:
_graph_args[target] = None
return _graph_args[target]