Skip to content

Commit

Permalink
Added enable events statements consumers for aws/rds (#373)
Browse files Browse the repository at this point in the history
  • Loading branch information
kochetovd authored Nov 8, 2024
1 parent 2b0cfab commit 9612fc7
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 6 deletions.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

const (
ReleemAgentVersion = "1.19.5"
ReleemAgentVersion = "1.19.6"
)

type Config struct {
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.5
1.19.6
6 changes: 4 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.5
# install.sh - Version 1.19.6
# (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.5
install_script_version=1.19.6
logfile="/var/log/releem-install.log"

WORKDIR="/opt/releem"
Expand Down Expand Up @@ -54,9 +54,11 @@ function releem_update() {
$sudo_cmd curl -w "%{http_code}" -L -o $WORKDIR/releem-agent.new https://releem.s3.amazonaws.com/v2/releem-agent-$(arch)
$sudo_cmd curl -w "%{http_code}" -L -o $WORKDIR/mysqlconfigurer.sh.new https://releem.s3.amazonaws.com/v2/mysqlconfigurer.sh
$sudo_cmd $WORKDIR/releem-agent stop || true
#$sudo_cmd $WORKDIR/releem-agent remove || true
$sudo_cmd mv $WORKDIR/releem-agent.new $WORKDIR/releem-agent
$sudo_cmd mv $WORKDIR/mysqlconfigurer.sh.new $WORKDIR/mysqlconfigurer.sh
$sudo_cmd chmod 755 $WORKDIR/mysqlconfigurer.sh $WORKDIR/releem-agent
#$sudo_cmd $WORKDIR/releem-agent install || true
$sudo_cmd $WORKDIR/releem-agent start || true
$sudo_cmd $WORKDIR/releem-agent -f

Expand Down
6 changes: 6 additions & 0 deletions metrics/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ func RunWorker(gatherers []models.MetricsGatherer, gatherers_configuration []mod
f := tasks.ProcessTaskFunc(metrics, repeaters, gatherers, logger, configuration)
time.AfterFunc(5*time.Second, f)
}
if configuration.QueryOptimization && configuration.InstanceType == "aws/rds" {
utils.EnableEventsStatementsConsumers(configuration, logger, metrics.DB.Metrics.Status["Uptime"].(string))
}
}
logger.Println("Saved a metrics...")
}()
Expand All @@ -94,6 +97,9 @@ func RunWorker(gatherers []models.MetricsGatherer, gatherers_configuration []mod
if Mode.Name == "Configurations" {
logger.Println("Recommended MySQL configuration downloaded to ", configuration.GetReleemConfDir())
}
if configuration.QueryOptimization && configuration.InstanceType == "aws/rds" {
utils.EnableEventsStatementsConsumers(configuration, logger, "0")
}
}
if (Mode.Name == "Configurations" && Mode.Type != "default") || Mode.Name == "Event" || Mode.Name == "TaskSet" {
logger.Info("Exiting")
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.5
# mysqlconfigurer.sh - Version 1.19.6
# (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.5"
VERSION="1.19.6"
RELEEM_INSTALL_PATH=$MYSQLCONFIGURER_PATH"install.sh"
logfile="/var/log/releem-mysqlconfigurer.log"

Expand Down
24 changes: 24 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package utils
import (
"database/sql"
"fmt"
"strconv"
"strings"

"github.com/Releem/mysqlconfigurer/config"
Expand Down Expand Up @@ -97,3 +98,26 @@ func ConnectionDatabase(configuration *config.Config, logger logging.Logger, DBn
}
return db
}

func EnableEventsStatementsConsumers(configuration *config.Config, logger logging.Logger, uptime_str string) {
uptime, err := strconv.Atoi(uptime_str)
if err != nil {
logger.Error(err)
}
if uptime < 120 {
var count_setup_consumers int
err := models.DB.QueryRow("SELECT count(name) FROM performance_schema.setup_consumers WHERE enabled = 'YES' AND name LIKE 'events_statements_%' AND name != 'events_statements_cpu'").Scan(&count_setup_consumers)
if err != nil {
logger.Error(err)
}
logger.Println("Found enabled performance_schema statements consumers: ", count_setup_consumers)
if count_setup_consumers < 3 {
_, err := models.DB.Query("CALL releem.enable_events_statements_consumers()")
if err != nil {
logger.Error("Failed to enable events_statements consumers", err)
} else {
logger.Println("Enable events_statements_consumers")
}
}
}
}

0 comments on commit 9612fc7

Please sign in to comment.