@cryptotaxi247 / netdata-1 / commits / 5475421a9

Added new chart for syscall_send/recvfile_bytes. Switched to ExecutableService. Got rid of any attempt to color the charts, just because I could never seem to make it work.

Added new chart for syscall_send/recvfile_bytes. Switched to ExecutableService. Got rid of any attempt to color the charts, just because I could never seem to make it work.

Christopher Cox committed Apr 23, 2017 at 19:44 UTC 5475421a9c60860d9ec2b22fc34417f2e68e70fa
2 files changed +28 -93
python.d/samba.chart.py
+28 -70
@@ -22,7 +22,7 @@
22 # chart and make it incremental (like find and notify... good examples).
23
24
25 -from base import SimpleService
25 +from base import ExecutableService
26 from re import compile
27 from subprocess import Popen, PIPE
28
@@ -31,9 +31,16 @@ from subprocess import Popen, PIPE
31 priority = 60000
32 retries = 60
33
34 -ORDER = ['smb2_rw','smb2_create_close','smb2_info','smb2_find','smb2_notify','smb2_sm_count']
34 +ORDER = ['syscall_rw','smb2_rw','smb2_create_close','smb2_info','smb2_find','smb2_notify','smb2_sm_count']
35
36 CHARTS = {
37 + 'syscall_rw': {
38 + 'lines': [
39 + ['syscall_sendfile_bytes', 'sendfile', 'incremental', 1, 1024],
40 + ['syscall_recvfile_bytes', 'recvfile', 'incremental', -1, 1024]
41 + ],
42 + 'options': [None, 'R/Ws', 'kilobytes/s', 'Smb2', 'smb2.readwrite', 'area']
43 + },
44 'smb2_rw': {
45 'lines': [
46 ['smb2_read_outbytes', 'readout', 'incremental', 1, 1024],
@@ -48,26 +55,26 @@ CHARTS = {
55 ['smb2_create_count', 'create', 'incremental', 1, 1],
56 ['smb2_close_count', 'close', 'incremental', -1, 1]
57 ],
51 - 'options': [None, 'Create/Close', 'operations/s', 'Smb2', 'smb2.create_close', 'area']
58 + 'options': [None, 'Create/Close', 'operations/s', 'Smb2', 'smb2.create_close', 'line']
59 },
60 'smb2_info': {
61 'lines': [
62 ['smb2_getinfo_count', 'getinfo', 'incremental', 1, 1],
63 ['smb2_setinfo_count', 'setinfo', 'incremental', -1, 1]
64 ],
58 - 'options': [None, 'Info', 'operations/s', 'Smb2', 'smb2.get_set_info', 'area']
65 + 'options': [None, 'Info', 'operations/s', 'Smb2', 'smb2.get_set_info', 'line']
66 },
67 'smb2_find': {
68 'lines': [
69 ['smb2_find_count', 'find', 'incremental', 1, 1]
70 ],
64 - 'options': [None, 'Find', 'operations/s', 'Smb2', 'smb2.find', 'area']
71 + 'options': [None, 'Find', 'operations/s', 'Smb2', 'smb2.find', 'line']
72 },
73 'smb2_notify': {
74 'lines': [
75 ['smb2_notify_count', 'notify', 'incremental', 1, 1]
76 ],
70 - 'options': [None, 'Notify', 'operations/s', 'Smb2', 'smb2.notify', 'area']
77 + 'options': [None, 'Notify', 'operations/s', 'Smb2', 'smb2.notify', 'line']
78 },
79 'smb2_sm_count': {
80 'lines': [
@@ -87,84 +94,35 @@ CHARTS = {
94 }
95
96
90 -class Service(SimpleService):
97 +class Service(ExecutableService):
98 def __init__(self, configuration=None, name=None):
92 - SimpleService.__init__(self, configuration=configuration, name=name)
93 - self.smbstatus = self.find_binary('smbstatus')
94 - self.rgx_smb2 = compile(r'(smb2_[^:]+):\s+(\d+)')
95 - self.cache_prev = list()
99 + ExecutableService.__init__(self, configuration=configuration, name=name)
100 + self.order = ORDER
101 + self.definitions = CHARTS
102 + self.rgx_smb2 = compile(r'(smb2_[^:]+|syscall_.*file_bytes):\s+(\d+)')
103
104 def check(self):
98 - # Cant start without 'smbstatus' command
99 - if not self.smbstatus:
100 - self.error('Can\'t locate \'smbstatus\' binary or binary is not executable by netdata')
101 - return False
105 + sudo_binary, smbstatus_binary = self.find_binary('sudo'), self.find_binary('smbstatus')
106
103 - # If command is present and we can execute it we need to make sure..
104 - # 1. STDOUT is not empty
105 - reply = self._get_raw_data()
106 - if not reply:
107 - self.error('No output from \'smbstatus\' (not enough privileges?)')
107 + if not (sudo_binary and smbstatus_binary):
108 + self.error('Can\'t locate \'sudo\' or \'smbstatus\' binary')
109 return False
109 - self.error(reply)
110 -
111 - # 2. Output is parsable (list is not empty after regex findall)
112 - is_parsable = self.rgx_smb2.findall(reply)
113 - if not is_parsable:
114 - self.error('Cant parse output...')
115 - return False
116 -
117 - # We are about to start!
118 - self.create_charts()
119 -
120 - self.info('Plugin was started successfully')
121 - return True
122 -
123 - def _get_raw_data(self):
124 - try:
125 - reply = Popen(['/usr/bin/sudo', '-n', self.smbstatus, '-P'], stdout=PIPE, stderr=PIPE, shell=False)
126 - except OSError:
127 - return None
128 -
129 - raw_data = reply.communicate()[0]
130 -
131 - if not raw_data:
132 - return None
133 -
134 - return raw_data.decode()
110 +
111 + self.command = ' '.join([sudo_binary, '-n', smbstatus_binary, '-P'])
112
113 + return ExecutableService.check(self)
114 +
115 def _get_data(self):
116 """
117 Format data received from shell command
118 :return: dict
119 """
120 raw_data = self._get_raw_data()
142 - data_all = self.rgx_smb2.findall(raw_data)
143 -
144 - if not data_all:
121 + if not raw_data:
122 return None
123
147 - # 1. ALL data from 'smbstatus -P'.
148 - to_netdata = dict([(k, int(v)) for k, v in data_all])
149 -
150 - # Ready steady go!
151 - return to_netdata
124 + parsed = self.rgx_smb2.findall(' '.join(raw_data))
125
153 - def create_charts(self):
154 - # If 'all_charts' is true...ALL charts are displayed. If no only default + 'extra_charts'
155 - #if self.configuration.get('all_charts'):
156 - # self.order = EXTRA_ORDER
157 - #else:
158 - # try:
159 - # extra_charts = list(filter(lambda chart: chart in EXTRA_ORDER, self.extra_charts.split()))
160 - # except (AttributeError, NameError, ValueError):
161 - # self.error('Extra charts disabled.')
162 - # extra_charts = []
163 -
164 - self.order = ORDER[:]
165 - #self.order.extend(extra_charts)
126 + return dict(parsed) or None
127
167 - # Create static charts
168 - #self.definitions = {chart: values for chart, values in CHARTS.items() if chart in self.order}
169 - self.definitions = CHARTS
128
web/dashboard_info.js
-23
@@ -853,29 +853,6 @@ netdataDashboard.context = {
853 info: 'Statistics about RetroShare\'s DHT. These values are estimated!'
854 },
855
856 - // ------------------------------------------------------------------------
857 - // SAMBA
858 -
859 - 'samba.smb2_create_close': {
860 - colors: NETDATA.colors[2] + ' ' + NETDATA.colors[3],
861 - height: 0.5
862 - },
863 -
864 - 'samba.smb2_info': {
865 - colors: NETDATA.colors[4] + ' ' + NETDATA.colors[5],
866 - height: 0.5
867 - },
868 -
869 - 'samba.smb2_find': {
870 - colors: NETDATA.colors[6],
871 - height: 0.5
872 - },
873 -
874 - 'samba.smb2_notify': {
875 - colors: NETDATA.colors[7],
876 - height: 0.5
877 - },
878 -
856 // ------------------------------------------------------------------------
857 // fping
858