mod.config = {None: {}}
for var in BASE_CONFIG:
try:
- mod.config[None][var] = getattr(var, mod)
- except Exception:
+ mod.config[None][var] = getattr(mod, var)
+ except AttributeError:
mod.config[None][var] = BASE_CONFIG[var]
return modules
if config_dir[-1] != '/':
config_dir += '/'
configfile = config_dir + "python.d.conf"
- print(config_dir)
try:
conf = read_config(configfile)
if v is False:
disabled.append(k)
except FileNotFoundError:
- modules_conf = config_dir
+ modules_conf = config_dir + "python.d/"
modules_dir = main_dir.replace("plugins.d", "python.d")
# directories should end with '/'
# Description: example netdata python.d plugin
# Author: Pawel Krupa (paulfantom)
-NAME = "example.chart.py"
-import sys
import random
from base import BaseService
+NAME = "example.chart.py"
# default module values
update_every = 3
priority = 90000
class Service(BaseService):
- def __init__(self,configuration=None,name=None):
+ def __init__(self, configuration=None, name=None):
super().__init__(configuration=configuration)
def check(self):
print("DIMENSION random1 '' absolute 1 1")
return True
- def update(self,interval):
+ def update(self, interval):
print("BEGIN example.python_random "+str(interval))
print("SET random1 = "+str(random.randint(0,100)))
print("END")
# Description: MySQL netdata python.d plugin
# Author: Pawel Krupa (paulfantom)
-NAME = "mysql.chart.py"
import sys
+NAME = "mysql.chart.py"
# import 3rd party library to handle MySQL communication
try:
from base import BaseService
-# default configuration (overriden by python.d.plugin)
+# default configuration (overridden by python.d.plugin)
# FIXME change password
config = {
'local': {
# query executed on MySQL server
QUERY = "SHOW GLOBAL STATUS"
-# charts order (can be overriden if you want less charts, or different order)
-ORDER = ['net',
- 'queries',
- 'handlers',
- 'table_locks',
- 'join_issues',
- 'sort_issues',
- 'tmp',
- 'connections',
- 'binlog_cache',
- 'threads',
- 'thread_cache_misses',
- 'innodb_io',
+# charts order (can be overridden if you want less charts, or different order)
+ORDER = ['net',
+ 'queries',
+ 'handlers',
+ 'table_locks',
+ 'join_issues',
+ 'sort_issues',
+ 'tmp',
+ 'connections',
+ 'binlog_cache',
+ 'threads',
+ 'thread_cache_misses',
+ 'innodb_io',
'innodb_io_ops',
'innodb_io_pending_ops',
'innodb_log',
# 'chart_name_in_netdata': (
# "parameters defining chart (passed to CHART statement)",
# [ # dimensions (lines) definitions
-# ("dimension_name", "dimension parameters (passed to DIMENSION statement)", "additional parameter (optional)")
+# ("dimension_name", "dimension parameters (passed to DIMENSION statement)")
# ])
# }
connect_timeout=self.configuration['update_every'])
except Exception as e:
self.error(NAME + " has problem connecting to server:", e)
- raise RuntimeError #stop creating module, need to catch it in supervisor
-
+ raise RuntimeError # stop creating module, need to catch it in supervisor
+
def _get_data(self):
if self.connection is None:
self._connect()
self.connection.close()
self.connection = None
return None
-
+
return dict(raw_data)
def check(self):
self.defs[name] = []
for line in CHARTS[name][1]:
self.defs[name].append(line[0])
-
+
idx = 0
data = self._get_data()
for name in ORDER:
str(self.priority + idx) + " " + \
str(self.update_every)
content = ""
- # check if server has this datapoint
+ # check if server has this data point
for line in CHARTS[name][1]:
if line[0] in data:
content += "DIMENSION " + line[0] + " " + line[1] + "\n"
print(header)
print(content)
idx += 1
-
+
if idx == 0:
return False
return True
- def update(self,interval):
+ def update(self, interval):
data = self._get_data()
if data is None:
return False
try:
- data['Thread cache misses'] = int( int(data['Threads_created']) * 10000 / int(data['Connections']))
+ data['Thread cache misses'] = int(int(data['Threads_created']) * 10000 / int(data['Connections']))
except Exception:
pass
for chart, dimensions in self.defs.items():
pass
if len(lines) > 0:
print(header + lines + "END")
-
+
return True
sys.stderr.flush()
def check(self):
- # TODO notify about not overridden function
- self.error("Where is your check()?")
+ self.error("Service " + str(self.__name__) + "doesn't implement check() function")
return False
def create(self):
- # TODO notify about not overridden function
- self.error("Where is your create()?")
+ self.error("Service " + str(self.__name__) + "doesn't implement create() function?")
return False
def update(self):
- # TODO notify about not overridden function
- self.error("Where is your update()?")
+ self.error("Service " + str(self.__name__) + "doesn't implement update() function")
return False