Skip to content

Commit

Permalink
Added a command to get the current configuration (#261)
Browse files Browse the repository at this point in the history
The dev2 environment has been added
  • Loading branch information
kochetovd authored Jan 30, 2024
1 parent f3fad3e commit 65a46ae
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 27 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.11.0.1.1"
ReleemAgentVersion = "1.12.0"
)

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.11.0.1.1
1.12.0
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.11.0.1.1
# install.sh - Version 1.12.0
# (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.11.0.1.1
install_script_version=1.12.0
logfile="releem-install.log"

WORKDIR="/opt/releem"
Expand Down
24 changes: 16 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func IsPath(path string, logger logging.Logger) bool {
}

// Manage by daemon commands or run the daemon
func (service *Service) Manage(logger logging.Logger, configFile string, command []string, FirstRun bool, AgentEvents string, AgentTask string) (string, error) {
func (service *Service) Manage(logger logging.Logger, configFile string, command []string, TypeConfiguration string, AgentEvents string, AgentTask string) (string, error) {
var gatherers, gatherers_configuration []m.MetricsGatherer
var Mode metrics.Mode
usage := "Usage: myservice install | remove | start | stop | status"
Expand Down Expand Up @@ -94,9 +94,7 @@ func (service *Service) Manage(logger logging.Logger, configFile string, command
Mode.ModeType = AgentTask
} else {
Mode.Name = "Configurations"
if FirstRun {
Mode.ModeType = "FirstRun"
}
Mode.ModeType = TypeConfiguration
}
// if Mode.Name != "Events" {
// Select how we collect instance metrics depending on InstanceType
Expand Down Expand Up @@ -188,14 +186,14 @@ func (service *Service) Manage(logger logging.Logger, configFile string, command
//Init repeaters
repeaters := make(map[string]m.MetricsRepeater)
repeaters["Metrics"] = m.MetricsRepeater(r.NewReleemMetricsRepeater(configuration))
repeaters["Configurations"] = m.MetricsRepeater(r.NewReleemConfigurationsRepeater(configuration))
repeaters["Configurations"] = m.MetricsRepeater(r.NewReleemConfigurationsRepeater(configuration, Mode))
repeaters["Events"] = m.MetricsRepeater(r.NewReleemEventsRepeater(configuration, Mode))
repeaters["Tasks"] = m.MetricsRepeater(t.NewReleemTasksRepeater(configuration))
repeaters["TaskStatus"] = m.MetricsRepeater(t.NewReleemTaskStatusRepeater(configuration))
repeaters["Task"] = m.MetricsRepeater(t.NewReleemTaskSetRepeater(configuration, Mode))

//Init gatherers
if Mode.Name == "Events" || Mode.Name == "Task" {
if (Mode.Name == "Configurations" && Mode.ModeType == "get") || Mode.Name == "Events" || Mode.Name == "Task" {
gatherers = append(gatherers,
m.NewDbConfGatherer(nil, db, configuration),
m.NewAgentMetricsGatherer(nil, configuration))
Expand All @@ -215,23 +213,33 @@ func (service *Service) Manage(logger logging.Logger, configFile string, command
}

func main() {
var TypeConfiguration string
logger = logging.NewSimpleLogger("Main")

configFile := flag.String("config", "/opt/releem/releem.conf", "Releem agent config")
FirstRun := flag.Bool("f", false, "Releem agent generate config")
SetConfigRun := flag.Bool("f", false, "Releem agent generate config")
GetConfigRun := flag.Bool("c", false, "Releem agent generate config")

AgentEvents := flag.String("event", "", "Releem agent type event")
AgentTask := flag.String("task", "", "Releem agent task name")

flag.Parse()
command := flag.Args()
if *SetConfigRun {
TypeConfiguration = "set"
} else if *GetConfigRun {
TypeConfiguration = "get"
} else {
TypeConfiguration = "default"
}

srv, err := daemon.New(name, description, daemon.SystemDaemon, dependencies...)
if err != nil {
logger.PrintError("Error: ", err)
os.Exit(1)
}
service := &Service{srv}
status, err := service.Manage(logger, *configFile, command, *FirstRun, *AgentEvents, *AgentTask)
status, err := service.Manage(logger, *configFile, command, TypeConfiguration, *AgentEvents, *AgentTask)

if err != nil {
logger.Println(status, "\nError: ", err)
Expand Down
4 changes: 2 additions & 2 deletions metrics/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func RunWorker(gatherers []MetricsGatherer, gatherers_configuration []MetricsGat
logger.Debug(configuration)
timer := time.NewTimer(1 * time.Second)
configTimer := time.NewTimer(configuration.ReadConfigSeconds * time.Second)
if Mode.ModeType == "FirstRun" || Mode.Name == "Events" || Mode.Name == "Task" {
if (Mode.Name == "Configurations" && Mode.ModeType != "default") || Mode.Name == "Events" || Mode.Name == "Task" {
GenerateTimer = time.NewTimer(0 * time.Second)

} else {
Expand Down Expand Up @@ -82,7 +82,7 @@ func RunWorker(gatherers []MetricsGatherer, gatherers_configuration []MetricsGat
if Ready {
processRepeaters(metrics, repeaters[Mode.Name], configuration, logger)
}
if Mode.ModeType == "FirstRun" || Mode.Name == "Events" || Mode.Name == "Task" {
if (Mode.Name == "Configurations" && Mode.ModeType != "default") || Mode.Name == "Events" || Mode.Name == "Task" {
os.Exit(0)
}
}()
Expand Down
7 changes: 5 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.11.0.1.1
# mysqlconfigurer.sh - Version 1.12.0
# (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.11.0.1.1"
VERSION="1.12.0"
RELEEM_INSTALL_PATH=$MYSQLCONFIGURER_PATH"install.sh"
logfile="releem-mysqlconfigurer.log"

Expand Down Expand Up @@ -263,6 +263,9 @@ function releem_apply_auto() {

function releem_apply_manual() {
printf "\n`date +%Y%m%d-%H:%M:%S`\033[37m Applying the recommended MySQL configuration...\033[0m\n"
printf "\n`date +%Y%m%d-%H:%M:%S`\033[37m Getting the latest up-to-date configuration...\033[0m\n"
/opt/releem/releem-agent -c >/dev/null 2>&1 || true

if [ ! -f $MYSQLCONFIGURER_CONFIGFILE ]; then
printf "\033[37m\n * Recommended MySQL configuration is not found.\033[0m"
printf "\033[37m\n * Please apply recommended configuration later or run Releem Agent manually:\033[0m"
Expand Down
22 changes: 16 additions & 6 deletions repeater/releemConfiguration.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
type ReleemConfigurationsRepeater struct {
logger logging.Logger
configuration *config.Config
Mode m.Mode
}

func (repeater ReleemConfigurationsRepeater) ProcessMetrics(context m.MetricContext, metrics m.Metrics) (interface{}, error) {
Expand All @@ -27,12 +28,21 @@ func (repeater ReleemConfigurationsRepeater) ProcessMetrics(context m.MetricCont
repeater.logger.Debug("Result Send data: ", string(e))
var api_domain string
env := context.GetEnv()
if env == "dev" {
api_domain = "https://api.dev.releem.com/v2/mysql"
if env == "dev2" {
api_domain = "https://api.dev2.releem.com/v2/"
} else if env == "dev" {
api_domain = "https://api.dev.releem.com/v2/"
} else if env == "stage" {
api_domain = "https://api.stage.releem.com/v2/mysql"
api_domain = "https://api.stage.releem.com/v2/"
} else {
api_domain = "https://api.releem.com/v2/mysql"
api_domain = "https://api.releem.com/v2/"
}
if repeater.Mode.ModeType == "set" {
api_domain = api_domain + "mysql"
} else if repeater.Mode.ModeType == "get" {
api_domain = api_domain + "config"
} else {
api_domain = api_domain + "mysql"
}
req, err := http.NewRequest(http.MethodPost, api_domain, bodyReader)
if err != nil {
Expand Down Expand Up @@ -74,12 +84,12 @@ func (repeater ReleemConfigurationsRepeater) ProcessMetrics(context m.MetricCont
return nil, err
}

func NewReleemConfigurationsRepeater(configuration *config.Config) ReleemConfigurationsRepeater {
func NewReleemConfigurationsRepeater(configuration *config.Config, Mode m.Mode) ReleemConfigurationsRepeater {
var logger logging.Logger
if configuration.Debug {
logger = logging.NewSimpleDebugLogger("ReleemRepeaterConfigurations")
} else {
logger = logging.NewSimpleLogger("ReleemRepeaterConfigurations")
}
return ReleemConfigurationsRepeater{logger, configuration}
return ReleemConfigurationsRepeater{logger, configuration, Mode}
}
4 changes: 3 additions & 1 deletion repeater/releemEvents.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ func (repeater ReleemEventsRepeater) ProcessMetrics(context m.MetricContext, met
repeater.logger.Debug("Result Send data: ", string(e))
var api_domain string
env := context.GetEnv()
if env == "dev" {
if env == "dev2" {
api_domain = "https://api.dev2.releem.com/v1/events/"
} else if env == "dev" {
api_domain = "https://api.dev.releem.com/v1/events/"
} else if env == "stage" {
api_domain = "https://api.stage.releem.com/v1/events/"
Expand Down
4 changes: 3 additions & 1 deletion repeater/releemMetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ func (repeater ReleemMetricsRepeater) ProcessMetrics(context m.MetricContext, me
repeater.logger.Debug("Result Send data: ", string(e))
var api_domain string
env := context.GetEnv()
if env == "dev" {
if env == "dev2" {
api_domain = "https://api.dev2.releem.com/v2/metrics"
} else if env == "dev" {
api_domain = "https://api.dev.releem.com/v2/metrics"
} else if env == "stage" {
api_domain = "https://api.stage.releem.com/v2/metrics"
Expand Down
4 changes: 3 additions & 1 deletion tasks/taskGet.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ func (repeater ReleemTasksRepeater) ProcessMetrics(context m.MetricContext, metr
repeater.logger.Debug("Result Send data: ", string(e))
var api_domain string
env := context.GetEnv()
if env == "dev" {
if env == "dev2" {
api_domain = "https://api.dev2.releem.com/v1/tasks/task_get"
} else if env == "dev" {
api_domain = "https://api.dev.releem.com/v1/tasks/task_get"
} else if env == "stage" {
api_domain = "https://api.stage.releem.com/v1/tasks/task_get"
Expand Down
4 changes: 3 additions & 1 deletion tasks/taskSet.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ func (repeater ReleemTaskSetRepeater) ProcessMetrics(context m.MetricContext, me
repeater.logger.Debug("Result Send data: ", string(e))
var api_domain string
env := context.GetEnv()
if env == "dev" {
if env == "dev2" {
api_domain = "https://api.dev2.releem.com/v1/tasks/"
} else if env == "dev" {
api_domain = "https://api.dev.releem.com/v1/tasks/"
} else if env == "stage" {
api_domain = "https://api.stage.releem.com/v1/tasks/"
Expand Down
4 changes: 3 additions & 1 deletion tasks/taskStatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ func (repeater ReleemTaskStatusRepeater) ProcessMetrics(context m.MetricContext,
repeater.logger.Debug("Result Send data: ", string(e))
var api_domain string
env := context.GetEnv()
if env == "dev" {
if env == "dev2" {
api_domain = "https://api.dev2.releem.com/v1/tasks/task_status"
} else if env == "dev" {
api_domain = "https://api.dev.releem.com/v1/tasks/task_status"
} else if env == "stage" {
api_domain = "https://api.stage.releem.com/v1/tasks/task_status"
Expand Down

0 comments on commit 65a46ae

Please sign in to comment.