samba.chart.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. # default module values (can be overridden per job in `config`)
  23. update_every = 5
  24. priority = 60000
  25. retries = 60
  26. ORDER = [
  27. 'syscall_rw',
  28. 'smb2_rw',
  29. 'smb2_create_close',
  30. 'smb2_info',
  31. 'smb2_find',
  32. 'smb2_notify',
  33. 'smb2_sm_count'
  34. ]
  35. CHARTS = {
  36. 'syscall_rw': {
  37. 'options': [None, 'R/Ws', 'kilobytes/s', 'syscall', 'syscall.rw', 'area'],
  38. 'lines': [
  39. ['syscall_sendfile_bytes', 'sendfile', 'incremental', 1, 1024],
  40. ['syscall_recvfile_bytes', 'recvfile', 'incremental', -1, 1024]
  41. ]
  42. },
  43. 'smb2_rw': {
  44. 'options': [None, 'R/Ws', 'kilobytes/s', 'smb2', 'smb2.rw', 'area'],
  45. 'lines': [
  46. ['smb2_read_outbytes', 'readout', 'incremental', 1, 1024],
  47. ['smb2_write_inbytes', 'writein', 'incremental', -1, 1024],
  48. ['smb2_read_inbytes', 'readin', 'incremental', 1, 1024],
  49. ['smb2_write_outbytes', 'writeout', 'incremental', -1, 1024]
  50. ]
  51. },
  52. 'smb2_create_close': {
  53. 'options': [None, 'Create/Close', 'operations/s', 'smb2', 'smb2.create_close', 'line'],
  54. 'lines': [
  55. ['smb2_create_count', 'create', 'incremental', 1, 1],
  56. ['smb2_close_count', 'close', 'incremental', -1, 1]
  57. ]
  58. },
  59. 'smb2_info': {
  60. 'options': [None, 'Info', 'operations/s', 'smb2', 'smb2.get_set_info', 'line'],
  61. 'lines': [
  62. ['smb2_getinfo_count', 'getinfo', 'incremental', 1, 1],
  63. ['smb2_setinfo_count', 'setinfo', 'incremental', -1, 1]
  64. ]
  65. },
  66. 'smb2_find': {
  67. 'options': [None, 'Find', 'operations/s', 'smb2', 'smb2.find', 'line'],
  68. 'lines': [
  69. ['smb2_find_count', 'find', 'incremental', 1, 1]
  70. ]
  71. },
  72. 'smb2_notify': {
  73. 'options': [None, 'Notify', 'operations/s', 'smb2', 'smb2.notify', 'line'],
  74. 'lines': [
  75. ['smb2_notify_count', 'notify', 'incremental', 1, 1]
  76. ]
  77. },
  78. 'smb2_sm_count': {
  79. 'options': [None, 'Lesser Ops', 'count', 'smb2', 'smb2.sm_counters', 'stacked'],
  80. 'lines': [
  81. ['smb2_tcon_count', 'tcon', 'absolute', 1, 1],
  82. ['smb2_negprot_count', 'negprot', 'absolute', 1, 1],
  83. ['smb2_tdis_count', 'tdis', 'absolute', 1, 1],
  84. ['smb2_cancel_count', 'cancel', 'absolute', 1, 1],
  85. ['smb2_logoff_count', 'logoff', 'absolute', 1, 1],
  86. ['smb2_flush_count', 'flush', 'absolute', 1, 1],
  87. ['smb2_lock_count', 'lock', 'absolute', 1, 1],
  88. ['smb2_keepalive_count', 'keepalive', 'absolute', 1, 1],
  89. ['smb2_break_count', 'break', 'absolute', 1, 1],
  90. ['smb2_sessetup_count', 'sessetup', 'absolute', 1, 1]
  91. ]
  92. }
  93. }
  94. class Service(ExecutableService):
  95. def __init__(self, configuration=None, name=None):
  96. ExecutableService.__init__(self, configuration=configuration, name=name)
  97. self.order = ORDER
  98. self.definitions = CHARTS
  99. self.rgx_smb2 = re.compile(r'(smb2_[^:]+|syscall_.*file_bytes):\s+(\d+)')
  100. def check(self):
  101. sudo_binary, smbstatus_binary = find_binary('sudo'), find_binary('smbstatus')
  102. if not (sudo_binary and smbstatus_binary):
  103. self.error("Can\'t locate 'sudo' or 'smbstatus' binary")
  104. return False
  105. self.command = [sudo_binary, '-v']
  106. err = self._get_raw_data(stderr=True)
  107. if err:
  108. self.error(''.join(err))
  109. return False
  110. self.command = ' '.join([sudo_binary, '-n', smbstatus_binary, '-P'])
  111. return ExecutableService.check(self)
  112. def _get_data(self):
  113. """
  114. Format data received from shell command
  115. :return: dict
  116. """
  117. raw_data = self._get_raw_data()
  118. if not raw_data:
  119. return None
  120. parsed = self.rgx_smb2.findall(' '.join(raw_data))
  121. return dict(parsed) or None