code refactor

This commit is contained in:
Ulric Qin 2022-04-19 19:05:16 +08:00
parent 26d4bf1195
commit 1305b80f72
5 changed files with 20 additions and 13 deletions

View File

@ -1,11 +1,11 @@
# # collect interval # # collect interval
# interval = 15 # interval = 15
[[instances]] # [[instances]]
# commands, support glob # # commands, support glob
commands = [ # commands = [
"/opt/categraf/scripts/*.sh" # "/opt/categraf/scripts/*.sh"
] # ]
# # timeout for each command to complete # # timeout for each command to complete
# timeout = 5 # timeout = 5

View File

@ -1,14 +1,14 @@
# # collect interval # # collect interval
# interval = 15 # interval = 15
[[instances]] # [[instances]]
address = "10.1.2.3:1521/orcl" # address = "10.1.2.3:1521/orcl"
username = "monitor" # username = "monitor"
password = "123456" # password = "123456"
is_sys_dba = false # is_sys_dba = false
is_sys_oper = false # is_sys_oper = false
disable_connection_pool = false # disable_connection_pool = false
max_open_connections = 5 # max_open_connections = 5
# # interval = global.interval * interval_times # # interval = global.interval * interval_times
# interval_times = 1 # interval_times = 1
# labels = { region="cloud" } # labels = { region="cloud" }

View File

@ -58,6 +58,10 @@ func (e *Exec) GetInterval() config.Duration {
} }
func (e *Exec) Init() error { func (e *Exec) Init() error {
if len(e.Instances) == 0 {
return fmt.Errorf("exec instances empty")
}
for i := 0; i < len(e.Instances); i++ { for i := 0; i < len(e.Instances); i++ {
if e.Instances[i].DataFormat == "" || e.Instances[i].DataFormat == "influx" { if e.Instances[i].DataFormat == "" || e.Instances[i].DataFormat == "influx" {
e.Instances[i].parser = influx.NewSeriesParser() e.Instances[i].parser = influx.NewSeriesParser()

View File

@ -76,6 +76,9 @@ func (o *Oracle) Init() error {
o.dbconnpool = make(map[string]*sqlx.DB) o.dbconnpool = make(map[string]*sqlx.DB)
for i := 0; i < len(o.Instances); i++ { for i := 0; i < len(o.Instances); i++ {
dbConf := o.Instances[i] dbConf := o.Instances[i]
if dbConf.Address == "" {
return fmt.Errorf("some oracle address is blank")
}
connString := getConnectionString(dbConf) connString := getConnectionString(dbConf)
db, err := sqlx.Open("godror", connString) db, err := sqlx.Open("godror", connString)
if err != nil { if err != nil {