Skip to content

Commit

Permalink
fix(): MSSQL database metric set
Browse files Browse the repository at this point in the history
  • Loading branch information
wilhuang committed Dec 18, 2024
1 parent 6cdf979 commit 5d5c14d
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions x-pack/metricbeat/module/mssql/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,18 +612,18 @@ GROUP BY
mapStr := m.fetchRowsWithRowCounter(query, reporter, counter)

result := make([]mapstr.M, 0)
var (
dbTotalSpace int64
dbUsedSpace int64
dbUnusedSpace int64
dbSpaceUsedPct float64 = 0.00

Check failure on line 619 in x-pack/metricbeat/module/mssql/database/database.go

View workflow job for this annotation

GitHub Actions / lint (windows)

ineffectual assignment to dbSpaceUsedPct (ineffassign)

Check failure on line 619 in x-pack/metricbeat/module/mssql/database/database.go

View workflow job for this annotation

GitHub Actions / lint (linux)

ineffectual assignment to dbSpaceUsedPct (ineffassign)

Check failure on line 619 in x-pack/metricbeat/module/mssql/database/database.go

View workflow job for this annotation

GitHub Actions / lint (darwin)

ineffectual assignment to dbSpaceUsedPct (ineffassign)
)
for key, item := range mapStr {
keys := strings.SplitN(key, "-", 2)
if len(keys) != 2 {
continue
}
dbName, tblName := keys[0], keys[1]
var (
dbTotalSpace int64
dbUsedSpace int64
dbUnusedSpace int64
dbSpaceUsedPct float64 = 0.00
)
for metricName, val := range item.(mapstr.M) {
result = append(result, mapstr.M{
metricName: val,
Expand All @@ -650,26 +650,26 @@ GROUP BY
}
}
}
}

result = append(result, mapstr.M{
"used_space": fmt.Sprintf("%v", dbUsedSpace),
"db_name": dbName,
})
result = append(result, mapstr.M{
"unused_space": fmt.Sprintf("%v", dbUnusedSpace),
"db_name": dbName,
})
result = append(result, mapstr.M{
"total_space": fmt.Sprintf("%v", dbTotalSpace),
"db_name": dbName,
})
if dbTotalSpace != 0 {
dbSpaceUsedPct = float64(dbUsedSpace) / float64(dbTotalSpace)
result = append(result, mapstr.M{
"used_space": fmt.Sprintf("%v", dbUsedSpace),
"db_name": dbName,
})
result = append(result, mapstr.M{
"unused_space": fmt.Sprintf("%v", dbUnusedSpace),
"db_name": dbName,
"space_used_pct": fmt.Sprintf("%v", dbSpaceUsedPct),
"db_name": dbName,
})
result = append(result, mapstr.M{
"total_space": fmt.Sprintf("%v", dbTotalSpace),
"db_name": dbName,
})
if dbTotalSpace != 0 {
dbSpaceUsedPct = float64(dbUsedSpace) / float64(dbTotalSpace)
result = append(result, mapstr.M{
"space_used_pct": fmt.Sprintf("%v", dbSpaceUsedPct),
"db_name": dbName,
})
}
}

return result
Expand Down

0 comments on commit 5d5c14d

Please sign in to comment.