samba.chart.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. # -*- coding: utf-8 -*-
  2. # Description: samba netdata python.d module
  3. # Author: Christopher Cox <chris_cox@endlessnow.com>
  4. # SPDX-License-Identifier: GPL-3.0-or-later
  5. #
  6. # The netdata user needs to be able to be able to sudo the smbstatus program
  7. # without password:
  8. # netdata ALL=(ALL) NOPASSWD: /usr/bin/smbstatus -P
  9. #
  10. # This makes calls to smbstatus -P
  11. #
  12. # This just looks at a couple of values out of syscall, and some from smb2.
  13. #
  14. # The Lesser Ops chart is merely a display of current counter values. They
  15. # didn't seem to change much to me. However, if you notice something changing
  16. # a lot there, bring one or more out into its own chart and make it incremental
  17. # (like find and notify... good examples).
  18. import re
  19. from bases.collection import find_binary
  20. from bases.FrameworkServices.ExecutableService import ExecutableService
  21. disabled_by_default = True
  22. update_every = 5
  23. ORDER = [
  24. 'syscall_rw',
  25. 'smb2_rw',
  26. 'smb2_create_close',
  27. 'smb2_info',
  28. 'smb2_find',
  29. 'smb2_notify',
  30. 'smb2_sm_count'
  31. ]
  32. CHARTS = {
  33. 'syscall_rw': {
  34. 'options': [None, 'R/Ws', 'KiB/s', 'syscall', 'syscall.rw', 'area'],
  35. 'lines': [
  36. ['syscall_sendfile_bytes', 'sendfile', 'incremental', 1, 1024],
  37. ['syscall_recvfile_bytes', 'recvfile', 'incremental', -1, 1024]
  38. ]
  39. },
  40. 'smb2_rw': {
  41. 'options': [None, 'R/Ws', 'KiB/s', 'smb2', 'smb2.rw', 'area'],
  42. 'lines': [
  43. ['smb2_read_outbytes', 'readout', 'incremental', 1, 1024],
  44. ['smb2_write_inbytes', 'writein', 'incremental', -1, 1024],
  45. ['smb2_read_inbytes', 'readin', 'incremental', 1, 1024],
  46. ['smb2_write_outbytes', 'writeout', 'incremental', -1, 1024]
  47. ]
  48. },
  49. 'smb2_create_close': {
  50. 'options': [None, 'Create/Close', 'operations/s', 'smb2', 'smb2.create_close', 'line'],
  51. 'lines': [
  52. ['smb2_create_count', 'create', 'incremental', 1, 1],
  53. ['smb2_close_count', 'close', 'incremental', -1, 1]
  54. ]
  55. },
  56. 'smb2_info': {
  57. 'options': [None, 'Info', 'operations/s', 'smb2', 'smb2.get_set_info', 'line'],
  58. 'lines': [
  59. ['smb2_getinfo_count', 'getinfo', 'incremental', 1, 1],
  60. ['smb2_setinfo_count', 'setinfo', 'incremental', -1, 1]
  61. ]
  62. },
  63. 'smb2_find': {
  64. 'options': [None, 'Find', 'operations/s', 'smb2', 'smb2.find', 'line'],
  65. 'lines': [
  66. ['smb2_find_count', 'find', 'incremental', 1, 1]
  67. ]
  68. },
  69. 'smb2_notify': {
  70. 'options': [None, 'Notify', 'operations/s', 'smb2', 'smb2.notify', 'line'],
  71. 'lines': [
  72. ['smb2_notify_count', 'notify', 'incremental', 1, 1]
  73. ]
  74. },
  75. 'smb2_sm_count': {
  76. 'options': [None, 'Lesser Ops', 'count', 'smb2', 'smb2.sm_counters', 'stacked'],
  77. 'lines': [
  78. ['smb2_tcon_count', 'tcon', 'absolute', 1, 1],
  79. ['smb2_negprot_count', 'negprot', 'absolute', 1, 1],
  80. ['smb2_tdis_count', 'tdis', 'absolute', 1, 1],
  81. ['smb2_cancel_count', 'cancel', 'absolute', 1, 1],
  82. ['smb2_logoff_count', 'logoff', 'absolute', 1, 1],
  83. ['smb2_flush_count', 'flush', 'absolute', 1, 1],
  84. ['smb2_lock_count', 'lock', 'absolute', 1, 1],
  85. ['smb2_keepalive_count', 'keepalive', 'absolute', 1, 1],
  86. ['smb2_break_count', 'break', 'absolute', 1, 1],
  87. ['smb2_sessetup_count', 'sessetup', 'absolute', 1, 1]
  88. ]
  89. }
  90. }
  91. class Service(ExecutableService):
  92. def __init__(self, configuration=None, name=None):
  93. ExecutableService.__init__(self, configuration=configuration, name=name)
  94. self.order = ORDER
  95. self.definitions = CHARTS
  96. self.rgx_smb2 = re.compile(r'(smb2_[^:]+|syscall_.*file_bytes):\s+(\d+)')
  97. def check(self):
  98. sudo_binary, smbstatus_binary = find_binary('sudo'), find_binary('smbstatus')
  99. if not (sudo_binary and smbstatus_binary):
  100. self.error("Can\'t locate 'sudo' or 'smbstatus' binary")
  101. return False
  102. self.command = [sudo_binary, '-v']
  103. err = self._get_raw_data(stderr=True)
  104. if err:
  105. self.error(''.join(err))
  106. return False
  107. self.command = ' '.join([sudo_binary, '-n', smbstatus_binary, '-P'])
  108. return ExecutableService.check(self)
  109. def _get_data(self):
  110. """
  111. Format data received from shell command
  112. :return: dict
  113. """
  114. raw_data = self._get_raw_data()
  115. if not raw_data:
  116. return None
  117. parsed = self.rgx_smb2.findall(' '.join(raw_data))
  118. return dict(parsed) or None