sensu-plugins/sensu-plugins-process-checks

View on GitHub

Showing 14 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

    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

      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

      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

      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

        Method run has a Cognitive Complexity of 6 (exceeds 5 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 25 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

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

          def run
            raise 'You must supply -u USER or -p PROCESSNAME' unless config[:user] || config[:processname]
            metrics = {}
            pgrep_output = `#{pgrep_command}`
            pids = acquire_valid_pids(pgrep_output)
        Severity: Minor
        Found in bin/metrics-process-status.rb - About 25 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

        Severity
        Category
        Status
        Source
        Language