Skip to content

Commit

Permalink
Added debug messages and error handler
Browse files Browse the repository at this point in the history
  • Loading branch information
kochetovd committed Jul 5, 2024
1 parent b60465c commit 6c9dd30
Show file tree
Hide file tree
Showing 16 changed files with 55 additions and 35 deletions.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

const (
ReleemAgentVersion = "1.17.2"
ReleemAgentVersion = "1.17.3"
)

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.17.2
1.17.3
4 changes: 2 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/bin/bash
# install.sh - Version 1.17.2
# install.sh - Version 1.17.3
# (C) Releem, Inc 2022
# All rights reserved

# Releem installation script: install and set up the Releem Agent on supported Linux distributions
# using the package manager.

set -e
install_script_version=1.17.2
install_script_version=1.17.3
logfile="releem-install.log"

WORKDIR="/opt/releem"
Expand Down
1 change: 1 addition & 0 deletions metrics/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func NewAgentMetricsGatherer(logger logging.Logger, configuration *config.Config
}

func (Agent *AgentMetricsGatherer) GetMetrics(metrics *Metrics) error {
defer HandlePanic(Agent.configuration, Agent.logger)

output := make(map[string]interface{})
output["Version"] = config.ReleemAgentVersion
Expand Down
1 change: 1 addition & 0 deletions metrics/awsrdsdiscovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func NewAWSRDSInstanceGatherer(logger logging.Logger, rdsclient *rds.Client, ec2
}

func (awsrdsinstance *AWSRDSInstanceGatherer) GetMetrics(metrics *Metrics) error {
defer HandlePanic(awsrdsinstance.configuration, awsrdsinstance.logger)

//output := make(MetricGroupValue)
info := make(MetricGroupValue)
Expand Down
1 change: 1 addition & 0 deletions metrics/awsrdsenhancedmetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ func NewAWSRDSEnhancedMetricsGatherer(logger logging.Logger, dbinstance types.DB
}

func (awsrdsenhancedmetrics *AWSRDSEnhancedMetricsGatherer) GetMetrics(metrics *Metrics) error {
defer HandlePanic(awsrdsenhancedmetrics.configuration, awsrdsenhancedmetrics.logger)

info := make(MetricGroupValue)
metricsMap := make(MetricGroupValue)
Expand Down
1 change: 1 addition & 0 deletions metrics/awsrdsmetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func NewAWSRDSMetricsGatherer(logger logging.Logger, cwclient *cloudwatch.Client
}

func (awsrdsmetrics *AWSRDSMetricsGatherer) GetMetrics(metrics *Metrics) error {
defer HandlePanic(awsrdsmetrics.configuration, awsrdsmetrics.logger)

MetricDataQueries := []types.MetricDataQuery{}
output := make(MetricGroupValue)
Expand Down
13 changes: 7 additions & 6 deletions metrics/dbCollectQueries.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
)

type DbCollectQueries struct {
logger logging.Logger
debug bool
db *sql.DB
logger logging.Logger
configuration *config.Config
db *sql.DB
}

func NewDbCollectQueries(logger logging.Logger, db *sql.DB, configuration *config.Config) *DbCollectQueries {
Expand All @@ -24,13 +24,14 @@ func NewDbCollectQueries(logger logging.Logger, db *sql.DB, configuration *confi
}

return &DbCollectQueries{
logger: logger,
debug: configuration.Debug,
db: db,
logger: logger,
configuration: configuration,
db: db,
}
}

func (DbCollectQueries *DbCollectQueries) GetMetrics(metrics *Metrics) error {
defer HandlePanic(DbCollectQueries.configuration, DbCollectQueries.logger)

{
var output []MetricGroupValue
Expand Down
13 changes: 7 additions & 6 deletions metrics/dbConf.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
)

type DbConfGatherer struct {
logger logging.Logger
debug bool
db *sql.DB
logger logging.Logger
configuration *config.Config
db *sql.DB
}

func NewDbConfGatherer(logger logging.Logger, db *sql.DB, configuration *config.Config) *DbConfGatherer {
Expand All @@ -24,13 +24,14 @@ func NewDbConfGatherer(logger logging.Logger, db *sql.DB, configuration *config.
}

return &DbConfGatherer{
logger: logger,
debug: configuration.Debug,
db: db,
logger: logger,
configuration: configuration,
db: db,
}
}

func (DbConf *DbConfGatherer) GetMetrics(metrics *Metrics) error {
defer HandlePanic(DbConf.configuration, DbConf.logger)

output := make(MetricGroupValue)

Expand Down
1 change: 1 addition & 0 deletions metrics/dbInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func NewDbInfoGatherer(logger logging.Logger, db *sql.DB, configuration *config.
}

func (DbInfo *DbInfoGatherer) GetMetrics(metrics *Metrics) error {
defer HandlePanic(DbInfo.configuration, DbInfo.logger)

var row MetricValue
var mysql_version string
Expand Down
13 changes: 7 additions & 6 deletions metrics/dbMetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
)

type DbMetricsGatherer struct {
logger logging.Logger
debug bool
db *sql.DB
logger logging.Logger
configuration *config.Config
db *sql.DB
}

func NewDbMetricsGatherer(logger logging.Logger, db *sql.DB, configuration *config.Config) *DbMetricsGatherer {
Expand All @@ -24,13 +24,14 @@ func NewDbMetricsGatherer(logger logging.Logger, db *sql.DB, configuration *conf
}

return &DbMetricsGatherer{
logger: logger,
debug: configuration.Debug,
db: db,
logger: logger,
configuration: configuration,
db: db,
}
}

func (DbMetrics *DbMetricsGatherer) GetMetrics(metrics *Metrics) error {
defer HandlePanic(DbMetrics.configuration, DbMetrics.logger)
//Total table
{
var row MetricValue
Expand Down
13 changes: 7 additions & 6 deletions metrics/dbMetricsBase.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
)

type DbMetricsBaseGatherer struct {
logger logging.Logger
debug bool
db *sql.DB
logger logging.Logger
configuration *config.Config
db *sql.DB
}

func NewDbMetricsBaseGatherer(logger logging.Logger, db *sql.DB, configuration *config.Config) *DbMetricsBaseGatherer {
Expand All @@ -26,13 +26,14 @@ func NewDbMetricsBaseGatherer(logger logging.Logger, db *sql.DB, configuration *
}

return &DbMetricsBaseGatherer{
logger: logger,
debug: configuration.Debug,
db: db,
logger: logger,
configuration: configuration,
db: db,
}
}

func (DbMetricsBase *DbMetricsBaseGatherer) GetMetrics(metrics *Metrics) error {
defer HandlePanic(DbMetricsBase.configuration, DbMetricsBase.logger)
// Mysql Status
output := make(MetricGroupValue)
{
Expand Down
1 change: 1 addition & 0 deletions metrics/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func StructToMap(valueStruct string) MetricGroupValue {
return value_map
}
func (OS *OSMetricsGatherer) GetMetrics(metrics *Metrics) error {
defer HandlePanic(OS.configuration, OS.logger)

info := make(MetricGroupValue)
metricsMap := make(MetricGroupValue)
Expand Down
19 changes: 14 additions & 5 deletions metrics/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ func RunWorker(gatherers []MetricsGatherer, gatherers_configuration []MetricsGat
logger.Info("Exiting")
os.Exit(0)
case <-timer.C:
logger.Println("Starting collection of data for saving a metrics...", timer)
timer.Reset(configuration.TimePeriodSeconds * time.Second)
go func() {
defer HandlePanic(configuration, logger)
Ready = false
metrics := collectMetrics(gatherers, logger)
metrics := collectMetrics(gatherers, logger, configuration)
if Ready {
task := processRepeaters(metrics, repeaters["Metrics"], configuration, logger)
if task == "Task" {
Expand All @@ -66,14 +67,17 @@ func RunWorker(gatherers []MetricsGatherer, gatherers_configuration []MetricsGat
time.AfterFunc(5*time.Second, f)
}
}
logger.Println("Saved a metrics...")
}()
logger.Println("End collection of metrics for saving a metrics...", timer)
case <-GenerateTimer.C:
logger.Println("Starting collection of data for generating a config...", GenerateTimer)
GenerateTimer.Reset(configuration.GenerateConfigSeconds * time.Second)
go func() {
logger.Println(" * Collecting metrics to recommend a config...")
defer HandlePanic(configuration, logger)
Ready = false
logger.Println(" * Collecting metrics to recommend a config...")
metrics := collectMetrics(append(gatherers, gatherers_configuration...), logger)
metrics := collectMetrics(append(gatherers, gatherers_configuration...), logger, configuration)
if Ready {
logger.Println(" * Sending metrics to Releem Cloud Platform...")
processRepeaters(metrics, repeaters[Mode.Name], configuration, logger)
Expand All @@ -84,10 +88,14 @@ func RunWorker(gatherers []MetricsGatherer, gatherers_configuration []MetricsGat
}
}
if (Mode.Name == "Configurations" && Mode.ModeType != "default") || Mode.Name == "Event" || Mode.Name == "TaskSet" {
logger.Info("Exiting")
os.Exit(0)
}
logger.Println("Saved a config...")
}()
logger.Println("End collection of metrics for saving a metrics...", GenerateTimer)
}
logger.Info("LOOP")
}
}

Expand Down Expand Up @@ -226,7 +234,7 @@ func processTask(metrics Metrics, repeaters map[string]MetricsRepeater, gatherer
output["task_exit_code"] = 10
}
}
metrics = collectMetrics(gatherers, logger)
metrics = collectMetrics(gatherers, logger, configuration)
}
} else if TaskTypeID == 5 {
output["task_exit_code"], output["task_status"], task_output = execCmd(configuration.ReleemDir+"/mysqlconfigurer.sh -s automatic", []string{"RELEEM_RESTART_SERVICE=1"}, logger)
Expand Down Expand Up @@ -299,7 +307,8 @@ func processRepeaters(metrics Metrics, repeaters MetricsRepeater,
return result
}

func collectMetrics(gatherers []MetricsGatherer, logger logging.Logger) Metrics {
func collectMetrics(gatherers []MetricsGatherer, logger logging.Logger, configuration *config.Config) Metrics {
defer HandlePanic(configuration, logger)
var metrics Metrics
for _, g := range gatherers {
err := g.GetMetrics(&metrics)
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.17.2
# mysqlconfigurer.sh - Version 1.17.3
# (C) Releem, Inc 2022
# All rights reserved

Expand All @@ -12,7 +12,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.17.2"
VERSION="1.17.3"
RELEEM_INSTALL_PATH=$MYSQLCONFIGURER_PATH"install.sh"
logfile="releem-mysqlconfigurer.log"

Expand Down
1 change: 1 addition & 0 deletions repeater/releemConfiguration.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type ReleemConfigurationsRepeater struct {
}

func (repeater ReleemConfigurationsRepeater) ProcessMetrics(context m.MetricContext, metrics m.Metrics) (interface{}, error) {
defer m.HandlePanic(repeater.configuration, repeater.logger)
repeater.logger.Debug(repeater.Mode.Name, repeater.Mode.ModeType)
e, _ := json.Marshal(metrics)
bodyReader := strings.NewReader(string(e))
Expand Down

0 comments on commit 6c9dd30

Please sign in to comment.