Skip to content

Commit

Permalink
#347: Optimized algorithm for collecting the data of tables for query…
Browse files Browse the repository at this point in the history
… optimization (#359)
  • Loading branch information
kochetovd authored Oct 8, 2024
1 parent a481930 commit 1c69c33
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 39 deletions.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

const (
ReleemAgentVersion = "1.19.4.1"
ReleemAgentVersion = "1.19.4.2"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion current_version_agent
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.19.4.1
1.19.4.2
4 changes: 2 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# install.sh - Version 1.19.4.1
# install.sh - Version 1.19.4.2
# (C) Releem, Inc 2022
# All rights reserved

Expand All @@ -9,7 +9,7 @@ export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/
# using the package manager.

set -e -E
install_script_version=1.19.4.1
install_script_version=1.19.4.2
logfile="/var/log/releem-install.log"

WORKDIR="/opt/releem"
Expand Down
32 changes: 20 additions & 12 deletions metrics/dbCollectQueries.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"database/sql"
"sort"
"strings"
"time"

u "github.com/Releem/mysqlconfigurer/utils"

Expand Down Expand Up @@ -118,19 +119,26 @@ func (DbCollectQueriesOptimization *DbCollectQueriesOptimization) GetMetrics(met
TABLE_COLLATION string
}
var information_schema_table information_schema_table_type

rows, err := config.DB.Query("SELECT IFNULL(TABLE_SCHEMA, 'NULL') as TABLE_SCHEMA, IFNULL(TABLE_NAME, 'NULL') as TABLE_NAME, IFNULL(TABLE_TYPE, 'NULL') as TABLE_TYPE, IFNULL(ENGINE, 'NULL') as ENGINE, IFNULL(ROW_FORMAT, 'NULL') as ROW_FORMAT, IFNULL(TABLE_ROWS, 'NULL') as TABLE_ROWS, IFNULL(AVG_ROW_LENGTH, 'NULL') as AVG_ROW_LENGTH, IFNULL(MAX_DATA_LENGTH, 'NULL') as MAX_DATA_LENGTH,IFNULL(DATA_LENGTH, 'NULL') as DATA_LENGTH, IFNULL(INDEX_LENGTH, 'NULL') as INDEX_LENGTH, IFNULL(TABLE_COLLATION, 'NULL') as TABLE_COLLATION FROM information_schema.tables")
if err != nil {
DbCollectQueriesOptimization.logger.Error(err)
} else {
for rows.Next() {
err := rows.Scan(&information_schema_table.TABLE_SCHEMA, &information_schema_table.TABLE_NAME, &information_schema_table.TABLE_TYPE, &information_schema_table.ENGINE, &information_schema_table.ROW_FORMAT, &information_schema_table.TABLE_ROWS, &information_schema_table.AVG_ROW_LENGTH, &information_schema_table.MAX_DATA_LENGTH, &information_schema_table.DATA_LENGTH, &information_schema_table.INDEX_LENGTH, &information_schema_table.TABLE_COLLATION)
if err != nil {
DbCollectQueriesOptimization.logger.Error(err)
return err
i := 0
for _, database := range metrics.DB.Metrics.Databases {
rows, err := config.DB.Query(`SELECT IFNULL(TABLE_SCHEMA, 'NULL') as TABLE_SCHEMA, IFNULL(TABLE_NAME, 'NULL') as TABLE_NAME, IFNULL(TABLE_TYPE, 'NULL') as TABLE_TYPE, IFNULL(ENGINE, 'NULL') as ENGINE, IFNULL(ROW_FORMAT, 'NULL') as ROW_FORMAT, IFNULL(TABLE_ROWS, 'NULL') as TABLE_ROWS, IFNULL(AVG_ROW_LENGTH, 'NULL') as AVG_ROW_LENGTH, IFNULL(MAX_DATA_LENGTH, 'NULL') as MAX_DATA_LENGTH,IFNULL(DATA_LENGTH, 'NULL') as DATA_LENGTH, IFNULL(INDEX_LENGTH, 'NULL') as INDEX_LENGTH, IFNULL(TABLE_COLLATION, 'NULL') as TABLE_COLLATION FROM information_schema.tables WHERE TABLE_SCHEMA = ? `, database)
if err != nil {
DbCollectQueriesOptimization.logger.Error(err)
} else {
for rows.Next() {
err := rows.Scan(&information_schema_table.TABLE_SCHEMA, &information_schema_table.TABLE_NAME, &information_schema_table.TABLE_TYPE, &information_schema_table.ENGINE, &information_schema_table.ROW_FORMAT, &information_schema_table.TABLE_ROWS, &information_schema_table.AVG_ROW_LENGTH, &information_schema_table.MAX_DATA_LENGTH, &information_schema_table.DATA_LENGTH, &information_schema_table.INDEX_LENGTH, &information_schema_table.TABLE_COLLATION)
if err != nil {
DbCollectQueriesOptimization.logger.Error(err)
return err
}
table := MetricGroupValue{"TABLE_SCHEMA": information_schema_table.TABLE_SCHEMA, "TABLE_NAME": information_schema_table.TABLE_NAME, "TABLE_TYPE": information_schema_table.TABLE_TYPE, "ENGINE": information_schema_table.ENGINE, "ROW_FORMAT": information_schema_table.ROW_FORMAT, "TABLE_ROWS": information_schema_table.TABLE_ROWS, "AVG_ROW_LENGTH": information_schema_table.AVG_ROW_LENGTH, "MAX_DATA_LENGTH": information_schema_table.MAX_DATA_LENGTH, "DATA_LENGTH": information_schema_table.DATA_LENGTH, "INDEX_LENGTH": information_schema_table.INDEX_LENGTH, "TABLE_COLLATION": information_schema_table.TABLE_COLLATION}
output = append(output, table)
}
table := MetricGroupValue{"TABLE_SCHEMA": information_schema_table.TABLE_SCHEMA, "TABLE_NAME": information_schema_table.TABLE_NAME, "TABLE_TYPE": information_schema_table.TABLE_TYPE, "ENGINE": information_schema_table.ENGINE, "ROW_FORMAT": information_schema_table.ROW_FORMAT, "TABLE_ROWS": information_schema_table.TABLE_ROWS, "AVG_ROW_LENGTH": information_schema_table.AVG_ROW_LENGTH, "MAX_DATA_LENGTH": information_schema_table.MAX_DATA_LENGTH, "DATA_LENGTH": information_schema_table.DATA_LENGTH, "INDEX_LENGTH": information_schema_table.INDEX_LENGTH, "TABLE_COLLATION": information_schema_table.TABLE_COLLATION}
output = append(output, table)
}
rows.Close()
i += 1
if i%25 == 0 {
time.Sleep(3 * time.Second)
}
}
QueriesOptimization["information_schema_tables"] = output
Expand Down
20 changes: 0 additions & 20 deletions metrics/dbMetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,6 @@ func (DbMetrics *DbMetricsGatherer) GetMetrics(metrics *Metrics) error {
}
metrics.DB.Metrics.TotalTables = row
}
//list of databases
{
var database string
var output []string
rows, err := config.DB.Query("SELECT table_schema FROM INFORMATION_SCHEMA.tables group BY table_schema")
if err != nil {
DbMetrics.logger.Error(err)
return err
}
for rows.Next() {
err := rows.Scan(&database)
if err != nil {
DbMetrics.logger.Error(err)
return err
}
output = append(output, database)
}
rows.Close()
metrics.DB.Metrics.Databases = output
}
//Stat mysql Engine
{
var engine_db, engineenabled string
Expand Down
21 changes: 20 additions & 1 deletion metrics/dbMetricsBase.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,28 @@ func (DbMetricsBase *DbMetricsBaseGatherer) GetMetrics(metrics *Metrics) error {
metrics.DB.Metrics.InnoDBEngineStatus = status
}
}
//list of databases
{
var database string
var output []string
rows, err := config.DB.Query("SELECT table_schema FROM INFORMATION_SCHEMA.tables group BY table_schema")
if err != nil {
DbMetricsBase.logger.Error(err)
return err
}
for rows.Next() {
err := rows.Scan(&database)
if err != nil {
DbMetricsBase.logger.Error(err)
return err
}
output = append(output, database)
}
rows.Close()
metrics.DB.Metrics.Databases = output
}
DbMetricsBase.logger.Debug("collectMetrics ", metrics.DB.Metrics)
return nil

}

func contains(arr []int, num int) bool {
Expand Down
4 changes: 2 additions & 2 deletions mysqlconfigurer.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# mysqlconfigurer.sh - Version 1.19.4.1
# mysqlconfigurer.sh - Version 1.19.4.2
# (C) Releem, Inc 2022
# All rights reserved

Expand All @@ -15,7 +15,7 @@ MYSQLTUNER_REPORT=$MYSQLCONFIGURER_PATH"mysqltunerreport.json"
RELEEM_MYSQL_VERSION=$MYSQLCONFIGURER_PATH"mysql_version"
MYSQLCONFIGURER_CONFIGFILE="${MYSQLCONFIGURER_PATH}${MYSQLCONFIGURER_FILE_NAME}"
MYSQL_MEMORY_LIMIT=0
VERSION="1.19.4.1"
VERSION="1.19.4.2"
RELEEM_INSTALL_PATH=$MYSQLCONFIGURER_PATH"install.sh"
logfile="/var/log/releem-mysqlconfigurer.log"

Expand Down

0 comments on commit 1c69c33

Please sign in to comment.