sensu-plugins/sensu-plugins-process-checks

View on GitHub

Showing 23 of 23 total issues

Method run has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring.
Open

  def run
    procs = acquire_procs

    if config[:file_pid] && (file_pid = read_pid(config[:file_pid]))
      procs.select! { |p| p[:pid].to_i == file_pid }
Severity: Minor
Found in bin/check-process.rb - About 5 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function connection_stats has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
Open

def connection_stats(process_handler, metrics_regexp):
  tcp_stats = ['total'] + [s.lower() for s in TCP_CONN_STATUSES]
  tcp_conns = None
  tcp_conns_count = {}
  for stat in tcp_stats:
Severity: Minor
Found in bin/metrics-per-process.py - About 3 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method run has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

  def run
    if checkrestart?
      checkrestart_out = run_checkrestart

      if /^Failed/ =~ checkrestart_out[:found]
Severity: Minor
Found in bin/check-process-restart.rb - About 2 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method run has 48 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def run
    procs = acquire_procs

    if config[:file_pid] && (file_pid = read_pid(config[:file_pid]))
      procs.select! { |p| p[:pid].to_i == file_pid }
Severity: Minor
Found in bin/check-process.rb - About 1 hr to fix

    Method run has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

      def run
        ipcs_status = run_ipcs
    
        found = false
        index = -1
    Severity: Minor
    Found in bin/metrics-ipcs.rb - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function additional_stats has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    def additional_stats(process_handler, metrics_regexp):
      stats = {}
    
      if metrics_regexp.match('cpu.user'): 
        stats['cpu.user'] = process_handler.cpu_times().user
    Severity: Minor
    Found in bin/metrics-per-process.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

      if metrics_regexp.match('conns.unix_sockets.total'):
        unix_conns = process_handler.connections(kind='unix')
        if unix_conns:
          stats['conns.unix_sockets.total'] = len(unix_conns)
    Severity: Major
    Found in bin/metrics-per-process.py and 1 other location - About 1 hr to fix
    bin/metrics-per-process.py on lines 213..216

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 42.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

      if metrics_regexp.match('conns.udp.total'):
        udp_conns = process_handler.connections(kind='udp')
        if udp_conns:
          stats['conns.udp.total'] = len(udp_conns)
    Severity: Major
    Found in bin/metrics-per-process.py and 1 other location - About 1 hr to fix
    bin/metrics-per-process.py on lines 218..221

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 42.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Method run has 31 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def run
        ps_table = Sys::ProcTable.ps
        processes = ps_table.length
        threads = count_threads(ps_table) if config[:threads]
    
    
    Severity: Minor
    Found in bin/metrics-processes-threads-count.rb - About 1 hr to fix

      Method count_processes_by_status has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

        def count_processes_by_status(ps_table)
          list_proc = {}
          %w[S R D T t X Z].each do |v|
            list_proc[v] = 0
          end
      Severity: Minor
      Found in bin/metrics-processes-threads-count.rb - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

            needs_restarting_out = run_needs_restarting
      
            if /^Failed/ =~ needs_restarting_out[:found]
              unknown needs_restarting_out[:found]
            end
      Severity: Minor
      Found in bin/check-process-restart.rb and 1 other location - About 55 mins to fix
      bin/check-process-restart.rb on lines 136..147

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 46.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

            checkrestart_out = run_checkrestart
      
            if /^Failed/ =~ checkrestart_out[:found]
              unknown checkrestart_out[:found]
            end
      Severity: Minor
      Found in bin/check-process-restart.rb and 1 other location - About 55 mins to fix
      bin/check-process-restart.rb on lines 149..160

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 46.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Method acquire_cmd_status has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

        def acquire_cmd_status
          stdout = `#{config[:command]}`
          # #YELLOW
          unless $CHILD_STATUS.exitstatus.to_s == config[:status] # rubocop:disable UnlessElse
            critical "#{config[:command]} exited with #{$CHILD_STATUS.exitstatus}"
      Severity: Minor
      Found in bin/check-cmd.rb - About 55 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Avoid deeply nested control flow statements.
      Open

                if conn.status == tcp_status:
                  tcp_conns_count[stat] = tcp_conns_count[stat] + 1
          stats.update(tcp_conns_count)
      Severity: Major
      Found in bin/metrics-per-process.py - About 45 mins to fix

        Method run_checkrestart has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

          def run_checkrestart
            checkrestart_hash = { found: '', pids: [] }
        
            out = `sudo #{CHECK_RESTART} #{config[:args]} 2>&1`
            if $CHILD_STATUS.to_i.nonzero?
        Severity: Minor
        Found in bin/check-process-restart.rb - About 45 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function find_pids has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

        def find_pids(matcher):
          '''Find process PID using /proc/<pids> with given matcher'''
        
          pids_in_proc = [ pid for pid in os.listdir(PROC_ROOT_DIR) if pid.isdigit() ]
          pids = []
        Severity: Minor
        Found in bin/metrics-per-process.py - About 45 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

          def cputime_to_csec(time)
            m = /(\d+-)?(\d\d:)?(\d\d):(\d\d)/.match(time)
            (m[1] || 0).to_i * 86_400 + (m[2] || 0).to_i * 3600 + (m[3] || 0).to_i * 60 + (m[4] || 0).to_i
        Severity: Minor
        Found in bin/check-process.rb and 1 other location - About 45 mins to fix
        bin/check-process.rb on lines 237..239

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 39.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

          def etime_to_esec(etime)
            m = /(\d+-)?(\d\d:)?(\d\d):(\d\d)/.match(etime)
            (m[1] || 0).to_i * 86_400 + (m[2] || 0).to_i * 3600 + (m[3] || 0).to_i * 60 + (m[4] || 0).to_i
        Severity: Minor
        Found in bin/check-process.rb and 1 other location - About 45 mins to fix
        bin/check-process.rb on lines 244..246

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 39.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 3 locations. Consider refactoring.
        Open

          if options.username:
            pids = find_pids_from_user(options.username)
            graphite_printer(multi_pid_process_stats(pids, options.metrics_regexes), options.graphite_scheme)
        Severity: Major
        Found in bin/metrics-per-process.py and 2 other locations - About 40 mins to fix
        bin/metrics-per-process.py on lines 317..319
        bin/metrics-per-process.py on lines 325..327

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 34.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 3 locations. Consider refactoring.
        Open

          if options.process_pid_file:
            pid = get_pid_from_pid_file(options.process_pid_file)
            graphite_printer(stats_per_pid(pid, options.metrics_regexes), options.graphite_scheme)
        Severity: Major
        Found in bin/metrics-per-process.py and 2 other locations - About 40 mins to fix
        bin/metrics-per-process.py on lines 317..319
        bin/metrics-per-process.py on lines 321..323

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 34.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Severity
        Category
        Status
        Source
        Language