Commit ab3b71a3 authored by Dmitry's avatar Dmitry

Merge branch 'dmius-afterrelease-fix' into 'master'

A008,F004,F005 conclusion messages fixed, F005 total tables size calculation fixed

See merge request !324
parents aab0b908 2ab4bd96
Pipeline #63982549 passed with stages
in 7 minutes and 39 seconds
......@@ -38,7 +38,7 @@ func checkFsItemUsage(host string, fsItemData FsItem,
percent, _ := strconv.Atoi(usePercent)
if percent >= USAGE_WARNING && percent < USAGE_CRITICAL {
result.AppendConclusion(MSG_USAGE_WARNING_CONCLUSION, fsItemData.MountPoint, host, fsItemData.Used)
result.AppendRecommendation(MSG_USAGE_WARNING_RECOMMENDATION, fsItemData.MountPoint, host, USAGE_WARNING)
result.AppendRecommendation(MSG_USAGE_WARNING_RECOMMENDATION, fsItemData.MountPoint, host, 100-USAGE_WARNING)
usageWarning = true
result.P2 = true
}
......
......@@ -2,7 +2,7 @@ package a008
const MSG_NO_USAGE_RISKS_CONCLUSION string = "No significant risks of out-of-disk-space problem have been detected."
const MSG_USAGE_WARNING_CONCLUSION string = "[P2] Disk `%s` on `%s` space usage is %s, it exceeds 70%%. There are some risks of out-of-disk-space problem."
const MSG_USAGE_WARNING_RECOMMENDATION string = "[P2] Add more disk space to `%s` on `%s`. It is recommended to keep free disk space less than %d%% " +
const MSG_USAGE_WARNING_RECOMMENDATION string = "[P2] Add more disk space to `%s` on `%s`. It is recommended to keep free disk space more than %d%% " +
"to reduce risks of out-of-disk-space problem."
const MSG_USAGE_CRITICAL_CONCLUSION string = "Disk `%s` on `%s` space usage is %s, it exceeds 90%%. There are significant risks of out-of-disk-space problem. " +
"In this case, PostgreSQL will stop working and manual fix will be required."
......
......@@ -28,23 +28,19 @@ func appendTable(list []string, tableBloatData F004HeapBloat) []string {
func F004Process(report F004Report) checkup.ReportOutcome {
var result checkup.ReportOutcome
// check total values
var top5tables []string
var criticalTables []string
var warningTables []string
totalBloatIsCritical := false
var totalData F004HeapBloatTotal
i := 0
var databaseSize int64
for _, hostData := range report.Results {
databaseSize = hostData.Data.DatabaseSizeBytes
totalData = hostData.Data.HeapBloatTotal
if hostData.Data.HeapBloatTotal.BloatRatioPercentAvg > CRITICAL_TOTAL_BLOAT_RATIO {
totalBloatIsCritical = true
result.P1 = true
}
for _, heapBloatData := range hostData.Data.HeapBloat {
if totalBloatIsCritical && heapBloatData.RealSizeBytes > MIN_INDEX_SIZE_TO_ANALYZE && i < 5 {
top5tables = appendTable(top5tables, heapBloatData)
i++
}
if (heapBloatData.RealSizeBytes > MIN_INDEX_SIZE_TO_ANALYZE) && (heapBloatData.BloatRatioPercent >= WARNING_BLOAT_RATIO) &&
(heapBloatData.BloatRatioPercent < CRITICAL_BLOAT_RATIO) {
warningTables = appendTable(warningTables, heapBloatData)
......@@ -58,10 +54,10 @@ func F004Process(report F004Report) checkup.ReportOutcome {
result.AppendConclusion(MSG_TOTAL_BLOAT_EXCESS_CONCLUSION,
fmtutils.ByteFormat(float64(totalData.BloatSizeBytesSum), 2),
totalData.BloatRatioPercentAvg,
float64(float64(totalData.BloatSizeBytesSum)/float64(databaseSize)*100),
fmtutils.ByteFormat(float64(databaseSize-totalData.BloatSizeBytesSum), 2),
fmtutils.ByteFormat(float64(totalData.BloatSizeBytesSum), 2),
fmtutils.ByteFormat(float64(totalData.BloatSizeBytesSum), 2),
totalData.BloatRatioAvg,
strings.Join(top5tables, ""))
totalData.BloatRatioAvg)
result.P1 = true
} else {
result.AppendConclusion(MSG_TOTAL_BLOAT_LOW_CONCLUSION, totalData.BloatRatioPercentAvg,
......
......@@ -20,7 +20,7 @@ func TestF004Success(t *testing.T) {
BloatRatioPercentAvg: 5.367978121989509,
BloatRatioAvg: 1.0389965180727816,
}
hostResult.Data.DatabaseSizeBytes = 25526329344 * 4
hostResult.Data.HeapBloat = map[string]F004HeapBloat{
"table_1": F004HeapBloat{
Num: 1,
......@@ -84,6 +84,7 @@ func TestF004TotalExcess(t *testing.T) {
BloatRatioPercentAvg: 25.367978121989509,
BloatRatioAvg: 1.0389965180727816,
}
hostResult.Data.DatabaseSizeBytes = 25526329344 * 4
hostResult.Data.HeapBloat = map[string]F004HeapBloat{}
report.Results = F004ReportHostsResults{"test-host": hostResult}
result := F004Process(report)
......@@ -224,7 +225,7 @@ func TestF004Warnig(t *testing.T) {
BloatRatio: 2.46177370030581,
},
}
hostResult.Data.DatabaseSizeBytes = 25526329344 * 4
report.Results = F004ReportHostsResults{"test-host": hostResult}
result := F004Process(report)
if !result.P2 {
......@@ -247,7 +248,7 @@ func TestF004Critical(t *testing.T) {
BloatRatioPercentAvg: 5.367978121989509,
BloatRatioAvg: 1.0389965180727816,
}
hostResult.Data.DatabaseSizeBytes = 25526329344 * 4
hostResult.Data.HeapBloat = map[string]F004HeapBloat{
"table_1": F004HeapBloat{
Num: 1,
......
package f004
const MSG_NO_RECOMMENDATIONS string = "All good, no recommendations here. \n"
const MSG_TOTAL_BLOAT_EXCESS_CONCLUSION string = "[P1] Total table (heap) bloat estimation is %s, it is %.2f%% of overall DB size. " +
const MSG_TOTAL_BLOAT_EXCESS_CONCLUSION string = "[P1] Total table (heap) bloat estimation is %s, it is %.2f%% of overall tables size and %.2f%% of the DB size. " +
"So removing the table bloat can help to reduce the total database size to ~%s and to increase the free disk space by %s. " +
"Notice that this is only an estimation, sometimes it may be significantly off. Total size of tables is %.2f times bigger than it could be. " +
"The most bloated tables are: \n %s \n"
"Notice that this is only an estimation, sometimes it may be significantly off. Total size of tables is %.2f times bigger than it could be. \n"
const MSG_TOTAL_BLOAT_LOW_CONCLUSION string = "The total table (heap) bloat estimate is quite low, just ~%.2f%% (~%s). Hooray! Keep watching it though. \n"
const MSG_BLOAT_CRITICAL_RECOMMENDATION string = "[P1] Reduce and prevent high level of table bloat: \n" +
" - tune autovacuum: consider more aggressive autovacuum settings (See F001) \n" +
......
......@@ -39,6 +39,7 @@ type F004ReportHostResultData struct {
HeapBloat map[string]F004HeapBloat `json:"heap_bloat"`
HeapBloatTotal F004HeapBloatTotal `json:"heap_bloat_total"`
OverridedSettingsCount int `json:"overrided_settings_count"`
DatabaseSizeBytes int64 `json:"database_size_bytes"`
}
type F004ReportHostResult struct {
......
......@@ -33,8 +33,10 @@ func F005Process(report F005Report) checkup.ReportOutcome {
var warningIndexes []string
totalBloatIsCritical := false
var totalData F005IndexBloatTotal
var databaseSize int64
i := 0
for _, hostData := range report.Results {
databaseSize = hostData.Data.DatabaseSizeBytes
totalData = hostData.Data.IndexBloatTotal
if hostData.Data.IndexBloatTotal.BloatRatioPercentAvg > CRITICAL_TOTAL_BLOAT_RATIO {
totalBloatIsCritical = true
......@@ -58,10 +60,10 @@ func F005Process(report F005Report) checkup.ReportOutcome {
result.AppendConclusion(MSG_TOTAL_BLOAT_EXCESS_CONCLUSION,
fmtutils.ByteFormat(float64(totalData.BloatSizeBytesSum), 2),
totalData.BloatRatioPercentAvg,
float64(float64(totalData.BloatSizeBytesSum)/float64(databaseSize)*100),
fmtutils.ByteFormat(float64(databaseSize-totalData.BloatSizeBytesSum), 2),
fmtutils.ByteFormat(float64(totalData.BloatSizeBytesSum), 2),
fmtutils.ByteFormat(float64(totalData.BloatSizeBytesSum), 2),
totalData.BloatRatioAvg,
strings.Join(top5Indexes, ""))
totalData.BloatRatioAvg)
result.P1 = true
} else {
result.AppendConclusion(MSG_TOTAL_BLOAT_LOW_CONCLUSION, totalData.BloatRatioPercentAvg,
......
......@@ -59,7 +59,7 @@ func TestF005Success(t *testing.T) {
BloatRatio: 1.0,
},
}
hostResult.Data.DatabaseSizeBytes = 9828637208
report.Results = F005ReportHostsResults{"test-host": hostResult}
result := F005Process(report)
if result.P1 || result.P2 || result.P3 {
......@@ -81,8 +81,10 @@ func TestF005TotalExcess(t *testing.T) {
LiveDataSizeBytesSum: 457681690624,
BloatRatioPercentAvg: 25.367978121989509,
BloatRatioAvg: 1.0389965180727816,
TableSizeBytesSum: 25526329344 * 5,
}
hostResult.Data.IndexBloat = map[string]F005IndexBloat{}
hostResult.Data.DatabaseSizeBytes = 25526329344 * 4
report.Results = F005ReportHostsResults{"test-host": hostResult}
result := F005Process(report)
if !result.P1 {
......@@ -105,7 +107,7 @@ func TestF005Warnig(t *testing.T) {
BloatRatioPercentAvg: 5.367978121989509,
BloatRatioAvg: 1.0389965180727816,
}
hostResult.Data.DatabaseSizeBytes = 25526329344 * 4
hostResult.Data.IndexBloat = map[string]F005IndexBloat{
"index_1": F005IndexBloat{
Num: 1,
......@@ -167,7 +169,7 @@ func TestF005Critical(t *testing.T) {
BloatRatioPercentAvg: 5.367978121989509,
BloatRatioAvg: 1.0389965180727816,
}
hostResult.Data.DatabaseSizeBytes = 25526329344 * 4
hostResult.Data.IndexBloat = map[string]F005IndexBloat{
"index_1": F005IndexBloat{
Num: 1,
......
package f005
const MSG_NO_RECOMMENDATIONS string = "All good, no recommendations here."
const MSG_TOTAL_BLOAT_EXCESS_CONCLUSION string = "[P1] Total index bloat estimation is %s, it is %.2f%% of overall DB size. " +
const MSG_TOTAL_BLOAT_EXCESS_CONCLUSION string = "[P1] Total index bloat estimation is %s, it is %.2f%% of overall indexes size and %.2f%% of the DB size. " +
"So removing the index bloat can help to reduce the total database size to ~%s and to increase the free disk space by %s. " +
"Notice that this is only an estimation, sometimes it may be significantly off. Total size of indexes is %.2f times bigger than it could be. " +
"The most bloated indexes are: \n %s \n"
"Notice that this is only an estimation, sometimes it may be significantly off. Total size of indexes is %.2f times bigger than it could be. \n"
const MSG_TOTAL_BLOAT_LOW_CONCLUSION string = "The total index bloat estimate is quite low, just ~%.2f%% (~%s). Hooray! Keep watching it though."
const MSG_BLOAT_CRITICAL_RECOMMENDATION string = "[P1] Reduce and prevent high level of index bloat: \n" +
" - tune autovacuum: consider more aggressive autovacuum settings (See F001) \n" +
......
......@@ -44,6 +44,7 @@ type F005ReportHostResultData struct {
IndexBloat map[string]F005IndexBloat `json:"Index_bloat"`
IndexBloatTotal F005IndexBloatTotal `json:"Index_bloat_total"`
OverridedSettingsCount int `json:"overrided_settings_count"`
DatabaseSizeBytes int64 `json:"database_size_bytes"`
}
type F005ReportHostResult struct {
......
......@@ -150,7 +150,9 @@ select
'heap_bloat_total',
(select row_to_json(total_data) from total_data),
'overrided_settings_count',
(select count(1) from limited_data where overrided_settings = true)
(select count(1) from limited_data where overrided_settings = true),
'database_size_bytes',
(select pg_database_size(current_database()))
)
SQL
......
......@@ -188,9 +188,8 @@ with data as (
(sum("real_size_bytes")::numeric/sum("live_data_size_bytes")::numeric) as "bloat_ratio_avg",
(sum("bloat_size_bytes")::numeric/sum("real_size_bytes")::numeric * 100) as "bloat_ratio_percent_avg",
sum("extra_size_bytes") as "extra_size_bytes_sum",
sum("table_size_bytes") as "table_size_bytes_sum",
(select sum(ts.table_size_bytes) from (select distinct(table_name), table_size_bytes from data) ts) as "table_size_bytes_sum",
sum("live_data_size_bytes") as "live_data_size_bytes_sum"
from data
)
select
......@@ -200,7 +199,9 @@ select
'index_bloat_total',
(select row_to_json(total_data) from total_data),
'overrided_settings_count',
(select count(1) from limited_data where overrided_settings = true)
(select count(1) from limited_data where overrided_settings = true),
'database_size_bytes',
(select pg_database_size(current_database()))
)
SQL
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment