firehol/netdata

View on GitHub
src/go/plugin/go.d/modules/postgres/collect_metrics.go

Summary

Maintainability
D
2 days
Test Coverage

Method Postgres.collectMetrics has 274 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (p *Postgres) collectMetrics(mx map[string]int64) {
    mx["server_connections_used"] = p.mx.connUsed
    if p.mx.maxConnections > 0 {
        mx["server_connections_available"] = p.mx.maxConnections - p.mx.connUsed
        mx["server_connections_utilization"] = calcPercentage(p.mx.connUsed, p.mx.maxConnections)
Severity: Major
Found in src/go/plugin/go.d/modules/postgres/collect_metrics.go - About 1 day to fix

    Method Postgres.collectMetrics has a Cognitive Complexity of 77 (exceeds 20 allowed). Consider refactoring.
    Open

    func (p *Postgres) collectMetrics(mx map[string]int64) {
        mx["server_connections_used"] = p.mx.connUsed
        if p.mx.maxConnections > 0 {
            mx["server_connections_available"] = p.mx.maxConnections - p.mx.connUsed
            mx["server_connections_utilization"] = calcPercentage(p.mx.connUsed, p.mx.maxConnections)
    Severity: Minor
    Found in src/go/plugin/go.d/modules/postgres/collect_metrics.go - About 1 day 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 Postgres.resetMetrics has 69 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (p *Postgres) resetMetrics() {
        p.mx.srvMetrics = srvMetrics{
            xactTimeHist:   p.mx.xactTimeHist,
            queryTimeHist:  p.mx.queryTimeHist,
            maxConnections: p.mx.maxConnections,
    Severity: Minor
    Found in src/go/plugin/go.d/modules/postgres/collect_metrics.go - About 1 hr to fix

      There are no issues that match your filters.

      Category
      Status