sensu-plugins/sensu-plugins-process-checks

View on GitHub
bin/metrics-per-process.py

Summary

Maintainability
C
1 day
Test Coverage

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

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

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

    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

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

      if options.process_name:
        pids = find_pids_from_name(options.process_name)
        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 321..323
    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

    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

    There are no issues that match your filters.

    Category
    Status