Skip to content

Commit

Permalink
osHealth: reduce float depth on places that don't need it
Browse files Browse the repository at this point in the history
  • Loading branch information
kreatoo committed Aug 23, 2024
1 parent f36ccc7 commit b0235c0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
11 changes: 9 additions & 2 deletions common/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,21 @@ func LogError(err string) {
logrus.Error(err)
}

func PrettyPrint(name string, lessOrMore string, value float64, hasPercentage bool) {
func PrettyPrint(name string, lessOrMore string, value float64, hasPercentage bool, wantFloat bool) {
var par string
var floatDepth int

if hasPercentage {
par = "%)"
} else {
par = ")"
}

fmt.Println(Blue + name + Reset + " is " + lessOrMore + " (" + strconv.FormatFloat(value, 'f', 2, 64) + par + Reset)
if wantFloat {
floatDepth = 2
} else {
floatDepth = 0
}

fmt.Println(Blue + name + Reset + " is " + lessOrMore + " (" + strconv.FormatFloat(value, 'f', floatDepth, 64) + par + Reset)
}
14 changes: 7 additions & 7 deletions osHealth/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ func DiskUsage() {
usage, _ := disk.Usage(partition.Mountpoint)

if usage.UsedPercent > OsHealthConfig.Part_use_limit {
common.PrettyPrint("Disk usage at " + partition.Mountpoint, common.Fail + " more than " + strconv.FormatFloat(OsHealthConfig.Part_use_limit, 'f', -1, 64) + "%", usage.UsedPercent, true)
exceededParts = append(exceededParts, []string{strconv.FormatFloat(usage.UsedPercent, 'f', 2, 64), common.ConvertBytes(usage.Used), common.ConvertBytes(usage.Total), partition.Device, partition.Mountpoint})
common.PrettyPrint("Disk usage at " + partition.Mountpoint, common.Fail + " more than " + strconv.FormatFloat(OsHealthConfig.Part_use_limit, 'f', 0, 64) + "%", usage.UsedPercent, true, false)
exceededParts = append(exceededParts, []string{strconv.FormatFloat(usage.UsedPercent, 'f', 0, 64), common.ConvertBytes(usage.Used), common.ConvertBytes(usage.Total), partition.Device, partition.Mountpoint})
} else {
common.PrettyPrint("Disk usage at " + partition.Mountpoint, common.Green + " less than " + strconv.FormatFloat(OsHealthConfig.Part_use_limit, 'f', -1, 64) + "%", usage.UsedPercent, true)
common.PrettyPrint("Disk usage at " + partition.Mountpoint, common.Green + " less than " + strconv.FormatFloat(OsHealthConfig.Part_use_limit, 'f', 0, 64) + "%", usage.UsedPercent, true, false)
}
}

Expand All @@ -45,7 +45,7 @@ func DiskUsage() {
table.SetCenterSeparator("|")
table.AppendBulk(exceededParts)
table.Render()
msg := "Partition usage level has exceeded to " + strconv.FormatFloat(OsHealthConfig.Part_use_limit, 'f', 2, 64) + "% " + "for the following partitions;\n\n" + output.String()
msg := "Partition usage level has exceeded to " + strconv.FormatFloat(OsHealthConfig.Part_use_limit, 'f', 0, 64) + "% " + "for the following partitions;\n\n" + output.String()
msg = strings.Replace(msg, "\n", `\n`, -1)

// Check if file exists
Expand All @@ -66,10 +66,10 @@ func DiskUsage() {

common.AlarmCheckDown("disk", msg)

common.RedmineCreate("disk", common.Config.Identifier + " - Diskteki bir (ya da birden fazla) bölümün doluluk seviyesi %"+strconv.FormatFloat(OsHealthConfig.Part_use_limit, 'f', 2, 64)+" üstüne çıktı", output.String())
common.RedmineCreate("disk", common.Config.Identifier + " - Diskteki bir (ya da birden fazla) bölümün doluluk seviyesi %"+strconv.FormatFloat(OsHealthConfig.Part_use_limit, 'f', 0, 64)+" üstüne çıktı", output.String())
} else {
common.AlarmCheckUp("disk", "All partitions are now under the limit of " + strconv.FormatFloat(OsHealthConfig.Part_use_limit, 'f', 2, 64) + "%")
common.RedmineClose("disk", common.Config.Identifier + " - Bütün disk bölümleri "+strconv.FormatFloat(OsHealthConfig.Part_use_limit, 'f', 2, 64)+"% altına indi, kapatılıyor.")
common.AlarmCheckUp("disk", "All partitions are now under the limit of " + strconv.FormatFloat(OsHealthConfig.Part_use_limit, 'f', 0, 64) + "%")
common.RedmineClose("disk", common.Config.Identifier + " - Bütün disk bölümleri "+strconv.FormatFloat(OsHealthConfig.Part_use_limit, 'f', 0, 64)+"% altına indi, kapatılıyor.")
}
}

Expand Down
8 changes: 4 additions & 4 deletions osHealth/ram.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ func RamUsage() {
ramLimit := OsHealthConfig.Ram_Limit

if virtualMemory.UsedPercent > ramLimit {
common.PrettyPrint("RAM Usage", common.Fail + " more than " + strconv.FormatFloat(ramLimit, 'f', 2, 64) + "%", virtualMemory.UsedPercent, true)
common.AlarmCheckDown("ram", "RAM usage limit has exceeded " + strconv.FormatFloat(ramLimit, 'f', 2, 64) + "% (Current: " + strconv.FormatFloat(virtualMemory.UsedPercent, 'f', 2, 64) + "%)")
common.PrettyPrint("RAM Usage", common.Fail + " more than " + strconv.FormatFloat(ramLimit, 'f', 0, 64) + "%", virtualMemory.UsedPercent, true, false)
common.AlarmCheckDown("ram", "RAM usage limit has exceeded " + strconv.FormatFloat(ramLimit, 'f', 0, 64) + "% (Current: " + strconv.FormatFloat(virtualMemory.UsedPercent, 'f', 0, 64) + "%)")
} else {
common.PrettyPrint("RAM Usage", common.Green + " less than " + strconv.FormatFloat(ramLimit, 'f', 2, 64) + "%", virtualMemory.UsedPercent, true)
common.AlarmCheckUp("ram", "RAM usage went below " + strconv.FormatFloat(ramLimit, 'f', 2, 64) + "% (Current: " + strconv.FormatFloat(virtualMemory.UsedPercent, 'f', 2, 64) + "%)")
common.PrettyPrint("RAM Usage", common.Green + " less than " + strconv.FormatFloat(ramLimit, 'f', 0, 64) + "%", virtualMemory.UsedPercent, true, false)
common.AlarmCheckUp("ram", "RAM usage went below " + strconv.FormatFloat(ramLimit, 'f', 0, 64) + "% (Current: " + strconv.FormatFloat(virtualMemory.UsedPercent, 'f', 0, 64) + "%)")
}
}

4 changes: 2 additions & 2 deletions osHealth/sysload.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func SysLoad() {
}

if loadAvg.Load1 > loadLimit {
common.PrettyPrint("System Load", common.Fail + " more than " + strconv.FormatFloat(loadLimit, 'f', 2, 64) + "%", loadAvg.Load1, false)
common.PrettyPrint("System Load", common.Fail + " more than " + strconv.FormatFloat(loadLimit, 'f', 2, 64) + "%", loadAvg.Load1, false, true)
} else {
common.PrettyPrint("System Load", common.Green + " less than " + strconv.FormatFloat(loadLimit, 'f', 2, 64) + "%", loadAvg.Load1, false)
common.PrettyPrint("System Load", common.Green + " less than " + strconv.FormatFloat(loadLimit, 'f', 2, 64) + "%", loadAvg.Load1, false, true)
}
}

0 comments on commit b0235c0

Please sign in to comment.