Skip to content

Commit

Permalink
Merge pull request #56 from NETWAYS/refactor-strings
Browse files Browse the repository at this point in the history
Refactor to use strings.Builder
  • Loading branch information
martialblog authored Feb 3, 2023
2 parents 25e5d49 + c51ecc3 commit 08984d0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
3 changes: 1 addition & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ linters:
- funlen
- dogsled
- dupl
# - lll
- whitespace
- wsl
- exportloopref
Expand All @@ -25,8 +24,8 @@ linters:
- sqlclosecheck
- structcheck
- unparam
- musttag
presets:
- bugs
- unused
# - style
fast: false
11 changes: 6 additions & 5 deletions cmd/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/spf13/cobra"
"net/http"
"net/url"
"strings"
)

// To store the CLI parameters
Expand Down Expand Up @@ -142,7 +143,6 @@ var healthCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
var (
output string
summary string
rc int
stat logstash.Stat
thresholds HealthThreshold
Expand Down Expand Up @@ -247,11 +247,12 @@ var healthCmd = &cobra.Command{
}

// Generate summary for subchecks
summary += fmt.Sprintf("\n \\_[%s] Heap usage at %.2f%%", heapstatus, stat.Jvm.Mem.HeapUsedPercent)
summary += fmt.Sprintf("\n \\_[%s] Open file descriptors at %.2f%%", fdstatus, fileDescriptorsPercent)
summary += fmt.Sprintf("\n \\_[%s] CPU usage at %.2f%%", cpustatus, stat.Process.CPU.Percent)
var summary strings.Builder
summary.WriteString(fmt.Sprintf("\n \\_[%s] Heap usage at %.2f%%", heapstatus, stat.Jvm.Mem.HeapUsedPercent))
summary.WriteString(fmt.Sprintf("\n \\_[%s] Open file descriptors at %.2f%%", fdstatus, fileDescriptorsPercent))
summary.WriteString(fmt.Sprintf("\n \\_[%s] CPU usage at %.2f%%", cpustatus, stat.Process.CPU.Percent))

check.ExitRaw(rc, output, summary, "|", perfList.String())
check.ExitRaw(rc, output, summary.String(), "|", perfList.String())
},
}

Expand Down
14 changes: 8 additions & 6 deletions cmd/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/spf13/cobra"
"net/http"
"net/url"
"strings"
)

// To store the CLI parameters
Expand Down Expand Up @@ -64,7 +65,6 @@ var pipelineCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
var (
output string
summary string
rc int
pp logstash.Pipeline
thresholds PipelineThreshold
Expand Down Expand Up @@ -102,19 +102,21 @@ var pipelineCmd = &cobra.Command{
states := make([]int, 0, len(pp.Pipelines))

// Check status for each pipeline
var summary strings.Builder

for name, pipe := range pp.Pipelines {
inflightEvents := pipe.Events.In - pipe.Events.Out

summary += "\n \\_"
summary.WriteString("\n \\_")
if thresholds.inflightEventsCrit.DoesViolate(float64(inflightEvents)) {
states = append(states, check.Critical)
summary += fmt.Sprintf("[CRITICAL] inflight_events_%s:%d;", name, inflightEvents)
summary.WriteString(fmt.Sprintf("[CRITICAL] inflight_events_%s:%d;", name, inflightEvents))
} else if thresholds.inflightEventsWarn.DoesViolate(float64(inflightEvents)) {
states = append(states, check.Warning)
summary += fmt.Sprintf("[WARNING] inflight_events_%s:%d;", name, inflightEvents)
summary.WriteString(fmt.Sprintf("[WARNING] inflight_events_%s:%d;", name, inflightEvents))
} else {
states = append(states, check.OK)
summary += fmt.Sprintf("[OK] inflight_events_%s:%d;", name, inflightEvents)
summary.WriteString(fmt.Sprintf("[OK] inflight_events_%s:%d;", name, inflightEvents))
}

// Generate perfdata for each event
Expand Down Expand Up @@ -155,7 +157,7 @@ var pipelineCmd = &cobra.Command{
output = "Inflight events status unknown"
}

check.ExitRaw(rc, output, summary, "|", perfList.String())
check.ExitRaw(rc, output, summary.String(), "|", perfList.String())
},
}

Expand Down

0 comments on commit 08984d0

Please sign in to comment.