sensu-plugins/sensu-plugins-memory-checks

View on GitHub

Showing 6 of 10 total issues

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

  def run
    begin
      require 'vmstat'
    rescue LoadError => e
      raise unless e.message =~ /vmstat/
Severity: Minor
Found in bin/check-ram.rb - 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 metrics_hash has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

  def metrics_hash
    mem = {}
    memp = {}

    meminfo_output.each_line do |line|
Severity: Minor
Found in bin/metrics-memory-percent.rb - 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 metrics_hash has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

  def metrics_hash
    mem = {}
    meminfo_output.each_line do |line|
      mem['total']     = line.split(/\s+/)[1].to_i * 1024 if line =~ /^MemTotal/
      mem['free']      = line.split(/\s+/)[1].to_i * 1024 if line =~ /^MemFree/
Severity: Minor
Found in bin/metrics-memory.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 47 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def run
    begin
      require 'vmstat'
    rescue LoadError => e
      raise unless e.message =~ /vmstat/
Severity: Minor
Found in bin/check-ram.rb - About 1 hr to fix

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

      def metrics_hash
        mem = {}
        memp = {}
    
        meminfo_output.each_line do |line|
    Severity: Minor
    Found in bin/metrics-memory-percent.rb - About 1 hr to fix

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

        def run
          # Get output from free command
          output_swap = `free -m | grep "Swap"`
      
          # Prepare total and used swap
      Severity: Minor
      Found in bin/check-swap-percent.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

      Severity
      Category
      Status
      Source
      Language