git://git.iain.cx/iain
/
pstop.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
c5eb0ee
)
sort of working but statment stuff needs checking
author
Simon J Mudd
<sjmudd@pobox.com>
Fri, 16 Jan 2015 18:42:45 +0000
(19:42 +0100)
committer
Simon J Mudd
<sjmudd@pobox.com>
Fri, 16 Jan 2015 18:42:45 +0000
(19:42 +0100)
p_s/setup_instruments/setup_instruments.go
patch
|
blob
|
history
diff --git
a/p_s/setup_instruments/setup_instruments.go
b/p_s/setup_instruments/setup_instruments.go
index
cf4e347
..
3b260aa
100644
(file)
--- a/
p_s/setup_instruments/setup_instruments.go
+++ b/
p_s/setup_instruments/setup_instruments.go
@@
-1,4
+1,4
@@
-// manage the configuration of
performance_schema.
setup_instruments
+// manage the configuration of setup_instruments
package setup_instruments
import (
package setup_instruments
import (
@@
-9,7
+9,7
@@
import (
)
// We only match on the error number
)
// We only match on the error number
-// Error 1142: UPDATE command denied to user
+// 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
var EXPECTED_UPDATE_ERRORS = []string{
"Error 1142",
// Error 1290: The MySQL server is running with the --read-only option so it cannot execute this statement
var EXPECTED_UPDATE_ERRORS = []string{
"Error 1142",
@@
-33,24
+33,26
@@
type SetupInstruments struct {
// Change settings to monitor stage/sql/%
func (si *SetupInstruments) EnableStageMonitoring(dbh *sql.DB) {
// Change settings to monitor stage/sql/%
func (si *SetupInstruments) EnableStageMonitoring(dbh *sql.DB) {
+ lib.Logger.Println("EnableStageMonitoring")
sql := "SELECT NAME, ENABLED, TIMED FROM setup_instruments WHERE NAME LIKE 'stage/sql/%' AND ( enabled <> 'YES' OR timed <> 'YES' )"
sql := "SELECT NAME, ENABLED, TIMED FROM setup_instruments WHERE NAME LIKE 'stage/sql/%' AND ( enabled <> 'YES' OR timed <> 'YES' )"
- collecting := "Collecting
p_s.
setup_instruments stage/sql configuration settings"
- updating := "Updating
p_s.setup_instruments to allow stage/sql configuration
"
+ collecting := "Collecting setup_instruments stage/sql configuration settings"
+ updating := "Updating
setup_instruments configuration for: stage/sql
"
si.ConfigureSetupInstruments(dbh, sql, collecting, updating)
}
// Change settings to monitor wait/synch/mutex/%
func (si *SetupInstruments) EnableMutexMonitoring(dbh *sql.DB) {
si.ConfigureSetupInstruments(dbh, sql, collecting, updating)
}
// Change settings to monitor wait/synch/mutex/%
func (si *SetupInstruments) EnableMutexMonitoring(dbh *sql.DB) {
+ 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 := "SELECT NAME, ENABLED, TIMED FROM setup_instruments WHERE NAME LIKE 'wait/synch/mutex/%' AND ( enabled <> 'YES' OR timed <> 'YES' )"
- collecting := "Collecting
p_s.
setup_instruments wait/synch/mutex configuration settings"
- updating := "Updating
p_s.setup_instruments to allow wait/synch/mutex configuration
"
+ collecting := "Collecting setup_instruments wait/synch/mutex configuration settings"
+ updating := "Updating
setup_instruments configuration for: wait/synch/mutex
"
si.ConfigureSetupInstruments(dbh, sql, collecting, updating)
}
// generic routine (now) to update some rows in setup instruments
si.ConfigureSetupInstruments(dbh, sql, collecting, updating)
}
// generic routine (now) to update some rows in setup instruments
-func (si *SetupInstruments) ConfigureSetupInstruments(dbh *sql.DB, sql string, collecting, updating string) {
+func (si *SetupInstruments) ConfigureSetupInstruments(dbh *sql.DB, s
elect_s
ql string, collecting, updating string) {
// setup the old values in case they're not set
if si.rows == nil {
si.rows = make([]table_row, 0, 500)
// setup the old values in case they're not set
if si.rows == nil {
si.rows = make([]table_row, 0, 500)
@@
-58,7
+60,7
@@
func (si *SetupInstruments) ConfigureSetupInstruments(dbh *sql.DB, sql string, c
lib.Logger.Println(collecting)
lib.Logger.Println(collecting)
- rows, err := dbh.Query(sql)
+ rows, err := dbh.Query(s
elect_s
ql)
if err != nil {
log.Fatal(err)
}
if err != nil {
log.Fatal(err)
}
@@
-85,15
+87,16
@@
func (si *SetupInstruments) ConfigureSetupInstruments(dbh *sql.DB, sql string, c
// update the rows which need to be set - do multiple updates but I don't care
lib.Logger.Println(updating)
// update the rows which need to be set - do multiple updates but I don't care
lib.Logger.Println(updating)
+ lib.Logger.Println("- about to try to update", len(si.rows), "row(s)" )
count = 0
count = 0
- update_sql := "UPDATE setup_instruments SET enabled = ?, TIMED = ? WHERE NAME = ?"
- stmt, err := dbh.Prepare( update_sql )
- if err != nil {
- log.Fatal(err)
- }
for i := range si.rows {
for i := range si.rows {
- if _, err := stmt.Exec(update_sql, "YES", "YES", si.rows[i].NAME); err == nil {
+ lib.Logger.Println("- changing row:", si.rows[i].NAME )
+ sql := "UPDATE setup_instruments SET enabled = 'YES', TIMED = 'YES' WHERE NAME = '" + si.rows[i].NAME + "'"
+ lib.Logger.Println("exec statement:", sql )
+ if res, err := dbh.Exec(sql); err == nil {
si.update_succeeded = true
si.update_succeeded = true
+ c, _ := res.RowsAffected()
+ count += int(c)
} else {
found_expected := false
for i := range EXPECTED_UPDATE_ERRORS {
} else {
found_expected := false
for i := range EXPECTED_UPDATE_ERRORS {
@@
-106,9
+109,9
@@
func (si *SetupInstruments) ConfigureSetupInstruments(dbh *sql.DB, sql string, c
log.Fatal(err)
}
lib.Logger.Println("Insufficient privileges to UPDATE setup_instruments: " + err.Error())
log.Fatal(err)
}
lib.Logger.Println("Insufficient privileges to UPDATE setup_instruments: " + err.Error())
+ lib.Logger.Println("Not attempting further updates")
break
}
break
}
- count++
}
if si.update_succeeded {
lib.Logger.Println(count, "rows changed in p_s.setup_instruments")
}
if si.update_succeeded {
lib.Logger.Println(count, "rows changed in p_s.setup_instruments")
@@
-126,17
+129,18
@@
func (si *SetupInstruments) RestoreConfiguration(dbh *sql.DB) {
}
// update the rows which need to be set - do multiple updates but I don't care
}
// update the rows which need to be set - do multiple updates but I don't care
- count := 0
update_sql := "UPDATE setup_instruments SET enabled = ?, TIMED = ? WHERE NAME = ?"
stmt, err := dbh.Prepare( update_sql )
if err != nil {
log.Fatal(err)
}
update_sql := "UPDATE setup_instruments SET enabled = ?, TIMED = ? WHERE NAME = ?"
stmt, err := dbh.Prepare( update_sql )
if err != nil {
log.Fatal(err)
}
+ count := 0
for i := range si.rows {
for i := range si.rows {
- if _, err := stmt.Exec(
update_sql,
si.rows[i].ENABLED, si.rows[i].TIMED, si.rows[i].NAME ); err != nil {
+ if _, err := stmt.Exec(si.rows[i].ENABLED, si.rows[i].TIMED, si.rows[i].NAME ); err != nil {
log.Fatal(err)
}
count++
}
log.Fatal(err)
}
count++
}
+ stmt.Close()
lib.Logger.Println(count, "rows changed in p_s.setup_instruments")
}
lib.Logger.Println(count, "rows changed in p_s.setup_instruments")
}