X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=p_s%2Fsetup_instruments%2Fsetup_instruments.go;h=476b77be2de9a20c21346c747ba4bd7491b53976;hb=1b47199c6dbcda482dda1c5ea11c3899f724d563;hp=8a93493e6c8dc06d1b830b058a1653077dc17a92;hpb=a2fbfd747e5479aea9be0e22b1dff42ca1d7de52;p=pstop.git diff --git a/p_s/setup_instruments/setup_instruments.go b/p_s/setup_instruments/setup_instruments.go index 8a93493..476b77b 100644 --- a/p_s/setup_instruments/setup_instruments.go +++ b/p_s/setup_instruments/setup_instruments.go @@ -9,6 +9,9 @@ import ( "github.com/sjmudd/pstop/lib" ) +// constants +const sql_select = "SELECT NAME, ENABLED, TIMED FROM setup_instruments WHERE NAME LIKE ? AND 'YES NOT IN (enabled,timed)" + // We only match on the error number // Error 1142: UPDATE command denied to user 'cacti'@'10.164.132.182' for table 'setup_instruments' // Error 1290: The MySQL server is running with the --read-only option so it cannot execute this statement @@ -37,7 +40,7 @@ type SetupInstruments struct { // Return a newly initialised SetupInstruments structure with a handle to the database. // Better to return a pointer ? func NewSetupInstruments(dbh *sql.DB) SetupInstruments { - return SetupInstruments{ dbh: dbh } + return SetupInstruments{dbh: dbh} } // enable mutex and stage monitoring @@ -49,22 +52,22 @@ func (si *SetupInstruments) EnableMonitoring() { // Change settings to monitor stage/sql/% func (si *SetupInstruments) EnableStageMonitoring() { lib.Logger.Println("EnableStageMonitoring") - sql := "SELECT NAME, ENABLED, TIMED FROM setup_instruments WHERE NAME LIKE 'stage/sql/%' AND ( enabled <> 'YES' OR timed <> 'YES' )" + sql_match := "stage/sql/%" collecting := "Collecting setup_instruments stage/sql configuration settings" updating := "Updating setup_instruments configuration for: stage/sql" - si.Configure(sql, collecting, updating) + si.Configure(sql_match, collecting, updating) lib.Logger.Println("EnableStageMonitoring finishes") } // Change settings to monitor wait/synch/mutex/% func (si *SetupInstruments) EnableMutexMonitoring() { lib.Logger.Println("EnableMutexMonitoring") - sql := "SELECT NAME, ENABLED, TIMED FROM setup_instruments WHERE NAME LIKE 'wait/synch/mutex/%' AND ( enabled <> 'YES' OR timed <> 'YES' )" + sql_match := "wait/synch/mutex/%" collecting := "Collecting setup_instruments wait/synch/mutex configuration settings" updating := "Updating setup_instruments configuration for: wait/synch/mutex" - si.Configure(sql, collecting, updating) + si.Configure(sql_match, collecting, updating) lib.Logger.Println("EnableMutexMonitoring finishes") } @@ -85,8 +88,8 @@ func error_in_expected_list(actual_error string, expected_errors []string) bool } // generic routine (now) to update some rows in setup instruments -func (si *SetupInstruments) Configure(select_sql string, collecting, updating string) { - lib.Logger.Println(fmt.Sprintf("Configure(%q,%q,%q)", select_sql, collecting, updating)) +func (si *SetupInstruments) Configure(sql_match string, collecting, updating string) { + lib.Logger.Println(fmt.Sprintf("Configure(%q,%q,%q)", sql_match, collecting, updating)) // skip if we've tried and failed if si.update_tried && !si.update_succeeded { lib.Logger.Println("Configure() - Skipping further configuration") @@ -100,8 +103,8 @@ func (si *SetupInstruments) Configure(select_sql string, collecting, updating st lib.Logger.Println(collecting) - lib.Logger.Println("dbh.query", select_sql) - rows, err := si.dbh.Query(select_sql) + lib.Logger.Println("dbh.query", sql_select, sql_match) + rows, err := si.dbh.Query(sql_select, sql_match) if err != nil { log.Fatal(err) } @@ -144,7 +147,7 @@ func (si *SetupInstruments) Configure(select_sql string, collecting, updating st count = 0 for i := range si.rows { lib.Logger.Println("- changing row:", si.rows[i].NAME) - lib.Logger.Println("stmt.Exec", "YES", "YES", si.rows[i].NAME ) + lib.Logger.Println("stmt.Exec", "YES", "YES", si.rows[i].NAME) if res, err := stmt.Exec("YES", "YES", si.rows[i].NAME); err == nil { lib.Logger.Println("update succeeded") si.update_succeeded = true @@ -166,10 +169,10 @@ func (si *SetupInstruments) Configure(select_sql string, collecting, updating st } stmt.Close() } - lib.Logger.Println( "Configure() returns update_tried", si.update_tried, ", update_succeeded", si.update_succeeded) + lib.Logger.Println("Configure() returns update_tried", si.update_tried, ", update_succeeded", si.update_succeeded) } -// restore setup_instruments rows to their previous settings +// Restore setup_instruments rows to their previous settings (if changed previously). func (si *SetupInstruments) RestoreConfiguration() { lib.Logger.Println("RestoreConfiguration()") // If the previous update didn't work then don't try to restore @@ -182,14 +185,14 @@ func (si *SetupInstruments) RestoreConfiguration() { // update the rows which need to be set - do multiple updates but I don't care update_sql := "UPDATE setup_instruments SET enabled = ?, TIMED = ? WHERE NAME = ?" - lib.Logger.Println("dbh.Prepare(",update_sql,")") + lib.Logger.Println("dbh.Prepare(", update_sql, ")") stmt, err := si.dbh.Prepare(update_sql) if err != nil { log.Fatal(err) } count := 0 for i := range si.rows { - lib.Logger.Println("stmt.Exec(",si.rows[i].ENABLED, si.rows[i].TIMED, si.rows[i].NAME,")") + lib.Logger.Println("stmt.Exec(", si.rows[i].ENABLED, si.rows[i].TIMED, si.rows[i].NAME, ")") if _, err := stmt.Exec(si.rows[i].ENABLED, si.rows[i].TIMED, si.rows[i].NAME); err != nil { log.Fatal(err) }