samba.chart.py 4.8 KB

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