-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswisnap-collector-plugin-lib-example.py
127 lines (113 loc) · 4.24 KB
/
swisnap-collector-plugin-lib-example.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import time
from swisnap_plugin_lib_py import BaseCollector, start_collector, LOGLEVEL_INFO
from swisnap_plugin_lib_py.exceptions import PluginLibException
class ExampleCollectorPlugin(BaseCollector):
def define_plugin(self, ctx):
example_config = {"ip": "127.0.0.1", "port": 5434}
ctx.define_example_config(str(example_config))
ctx.define_tasks_per_instance_limit(4)
ctx.define_instances_limit(3)
ctx.define_group("dyn", "Dynamic element from python")
ctx.define_metric("/python/group1/metric1", "C", True, "1st metric")
ctx.define_metric("/python/group1/metric2", "C", True, "2nd metric")
ctx.define_metric("/python/group1/metric3", "C", False, "3rd metric")
ctx.define_metric(
"/python/group2/[dyn]/metric4", "C", False, "1st dynamic metric"
)
ctx.define_metric(
"/python/group2/[dyn]/metric5", "C", False, "2nd dynamic metric"
)
def collect(self, ctx):
ctx.log(LOGLEVEL_INFO, "Collect requested", {"name": self._name})
print("Requested metrics: ", ctx.requested_metrics())
mts = (
(
"/python/group1/metric1",
10,
{"bastide": "80", "succubine": "31"},
"knifesmith threadmaker",
"Albanian cheirosophy",
),
(
"/python/group1/metric2",
"string 34",
{"untransferred": "27", "cupolaman": "7"},
"Chastacosta Entoprocta",
"octocotyloid lexicon",
),
(
"/python/group1/metric3",
40,
{"gymnotid": "59", "ineffable": "76"},
"reliantly relick",
"Cerastium chilenite",
),
(
"/python/group2/dyn1/metric4",
40,
{"heelstrap": "48", "corbiculate": "84"},
"bastide koechlinite",
"counteravouch euphon",
),
(
"/python/group2/dyn15/metric4",
11,
{"newelty": "64", "lungmotor": "36"},
"rootlessness unwise",
"prepartake Tabebuia",
),
(
"/python/group2/dyn55/metric4",
5.34,
{"wresting": "71", "semidiaphaneity": "3"},
"overinsolent desilicify",
"unindulgently planipetalous",
),
(
"/python/group2/dyn56/metric4",
-21,
{"replenishingly": "83", "exululate": "50"},
"ostraite proliferant",
"nonhomogenous unreeling",
),
(
"/python/group2/dyn57/metric4",
9223372036854775999,
{"masu": "84", "dallier": "55"},
"unrelevant corncake",
"proconquest predeterministic",
),
(
"/python/group2/dyn58/metric4",
True,
{"postcordial": "52", "cupping": "68"},
"liturgize buhr",
"presentiveness sulfopurpurate",
),
(
"/python/group2/dyn3/metric5",
10,
{"foyaite": "64", "osoberry": "38"},
"jowler serape",
"overknee pinnaclet",
),
)
for (mt, val, tags, desc, unit) in mts:
ctx.add_metric(mt, val, tags=tags, description=desc, unit=unit)
try:
ctx.add_metric("/^$^%", 20)
except PluginLibException as e:
print("Exception: ", e)
def load(self, ctx):
ctx.log(LOGLEVEL_INFO, "Plugin is being loaded", {"name": self._name})
print("Config keys:", ctx.config_keys())
print("Config: ", ctx.raw_config())
try:
print("Config a", ctx.config_value("a"))
except PluginLibException as e:
print("Exception: ", e)
def unload(self, ctx):
ctx.log(LOGLEVEL_INFO, "Plugin is being unloaded", {"name": self._name})
if __name__ == "__main__":
collector = ExampleCollectorPlugin("collector-example", "0.0.1")
start_collector(collector)