@cryptotaxi247 / netdata-1 / commits / 6b92e9fac

basic checks in wrappers + store names of dimensions and charts in job object

paulfantom committed Jun 23, 2016 at 15:10 UTC 6b92e9facf567296fb6b273ccecb02d1c0cba4bf
1 file changed +44 -10
python.d/python_modules/base.py
+44 -10
@@ -18,8 +18,6 @@ class BaseService(threading.Thread):
18 Prototype of Service class.
19 Implemented basic functionality to run jobs by `python.d.plugin`
20 """
21 - debugging = False
22 -
21 def __init__(self, configuration=None, name=None):
22 """
23 This needs to be initialized in child classes
@@ -36,6 +34,8 @@ class BaseService(threading.Thread):
34 self.name = name
35 self.override_name = None
36 self.chart_name = ""
37 + self.dimensions = []
38 + self.charts = []
39 if configuration is None:
40 self.error("BaseService: no configuration parameters supplied. Cannot create Service.")
41 raise RuntimeError
@@ -145,20 +145,54 @@ class BaseService(threading.Thread):
145 self.data_stream += " "
146 self.data_stream += "\n"
147
148 - def chart(self, *params):
149 - self._line("CHART", *params)
148 + def chart(self, type_id, name="''", title="''", units="''", family="''",
149 + category="''", charttype="''", priority="''", update_every="''"):
150 + self.charts.append(type_id)
151 +
152 + self._line("CHART", type_id, name, title, units, family, category, charttype, priority, update_every)
153 pass
154
152 - def dimension(self, *params):
153 - self._line("DIMENSION", *params)
155 + def dimension(self, id, name="''", algorithm="''", multiplier=1, divisor=1, hidden=False):
156 + try:
157 + int(multiplier)
158 + except TypeError:
159 + self.error("malformed dimension: multiplier is not a number")
160 + multiplier = 1
161 + try:
162 + int(divisor)
163 + except TypeError:
164 + self.error("malformed dimension: divisor is not a number")
165 + divisor = 1
166 +
167 + self.dimensions.append(id)
168 + if hidden:
169 + self._line("DIMENSION", id, name, algorithm, multiplier, divisor, "hidden")
170 + else:
171 + self._line("DIMENSION", id, name, algorithm, multiplier, divisor)
172 pass
173
156 - def begin(self, *params):
157 - self._line("BEGIN", *params)
174 + def begin(self, type_id, microseconds="''"):
175 + if type_id not in self.charts:
176 + self.error("wrong chart type_id")
177 + try:
178 + int(microseconds)
179 + except TypeError:
180 + self.error("malformed begin statement: microseconds are not a number")
181 + microseconds = "''"
182 +
183 + self._line("BEGIN", type_id, microseconds)
184 pass
185
160 - def set(self, name, value):
161 - self._line("SET", name, "=", value)
186 + def set(self, id, value):
187 + if id not in self.dimensions:
188 + self.error("wrong dimension id")
189 + return
190 + try:
191 + value = str(int(value))
192 + except TypeError:
193 + self.error("cannot set non-numeric value")
194 + return
195 + self._line("SET", id, "=", value)
196 pass
197
198 def end(self):