*/
func (r *pl_by_user_row) headings() string {
- return fmt.Sprintf("%-14s|%10s %6s|%5s %4s|%4s %3s|%6s %6s %6s %6s %6s|",
+ return fmt.Sprintf("%-14s|%10s %6s|%4s %4s|%5s %3s|%6s %6s %6s %6s %6s|",
"username", "Run Time", "%", "Conn", "Actv", "Hosts", "DBs", "Select", "Insert", "Update", "Delete", "Other")
}
} else {
u = r.username
}
- return fmt.Sprintf("%-14s|%10s %6s|%5s %4s|%4s %3s|%6s %6s %6s %6s %6s|",
+ return fmt.Sprintf("%-14s|%10s %6s|%4s %4s|%5s %3s|%6s %6s %6s %6s %6s|",
u,
lib.FormatTime(r.runtime),
lib.FormatPct(lib.MyDivide(r.runtime, totals.runtime)),
totals.runtime += t[i].runtime
totals.connections += t[i].connections
totals.active += t[i].active
- // totals.hosts += t[i].hosts This needs to be done differently to get the total number of distinct hosts
- // totals.dbs += t[i].dbs This needs to be done differently to get the total number of distinct dbs
+ // totals.hosts += t[i].hosts This needs to be done differently to get the total number of distinct hosts
+ // totals.dbs += t[i].dbs This needs to be done differently to get the total number of distinct dbs
totals.selects += t[i].selects
totals.inserts += t[i].inserts
totals.updates += t[i].updates
"time"
)
-type map_string_string map[string]string
+type map_string_int map[string]int
// a table of rows
type Processlist struct {
lib.Logger.Println("Processlist.processlist2by_user() START")
var re_active_repl_master_thread *regexp.Regexp = regexp.MustCompile("Sending binlog event to slave")
- var re_select *regexp.Regexp = regexp.MustCompile(`SELECT(?i)`) // make case insensitive
- var re_insert *regexp.Regexp = regexp.MustCompile(`INSERT(?i)`) // make case insensitive
- var re_update *regexp.Regexp = regexp.MustCompile(`UPDATE(?i)`) // make case insensitive
- var re_delete *regexp.Regexp = regexp.MustCompile(`DELETE(?i)`) // make case insensitive
+ var re_select *regexp.Regexp = regexp.MustCompile(`(?i)SELECT`) // make case insensitive
+ var re_insert *regexp.Regexp = regexp.MustCompile(`(?i)INSERT`) // make case insensitive
+ var re_update *regexp.Regexp = regexp.MustCompile(`(?i)UPDATE`) // make case insensitive
+ var re_delete *regexp.Regexp = regexp.MustCompile(`(?i)DELETE`) // make case insensitive
var row pl_by_user_row
var results pl_by_user_rows
- var my_hosts map_string_string
- var my_db map_string_string
+ var my_hosts map_string_int
+ var my_db map_string_int
var ok bool
- // map username to row details
- users := make(map[string]pl_by_user_row)
- hosts_by_user := make(map[string]map_string_string)
- dbs_by_user := make(map[string]map_string_string)
- // var dbs map[string]map_string_string
- // Command state
- // | 3859522915 | m1m1repl | bc210bprdb-01.lhr4.prod.booking.com:58703 | NULL | Binlog Dump | 4165475 | Master has sent all binlog to slave; waiting for binlog to be updated | NULL |
- // | 4179949288 | m1m1repl | xc238bprdb-01.lhr4.prod.booking.com:34391 | NULL | Binlog Dump | 3053011 | Master has sent all binlog to slave; waiting for binlog to be updated | NULL |
- // | 4336765784 | m1m1repl | bc279bprdb-01.lhr4.prod.booking.com:50991 | NULL | Binlog Dump | 2523403 | Sending binlog event to slave | NULL |
+
+ row_by_user := make(map[string]pl_by_user_row)
+ hosts_by_user := make(map[string]map_string_int)
+ dbs_by_user := make(map[string]map_string_int)
for i := range t.current {
// munge the username for special purposes (event scheduler, replication threads etc)
lib.Logger.Println("- id/user/host:", id, username, host)
- if old_row, ok := users[username]; ok {
- lib.Logger.Println("- found old row in users")
+ if old_row, ok := row_by_user[username]; ok {
+ lib.Logger.Println("- found old row in row_by_user")
row = old_row // get old row
} else {
- lib.Logger.Println("- NOT found old row in users")
+ lib.Logger.Println("- NOT found old row in row_by_user")
// create new row - RESET THE VALUES !!!!
rowp := new(pl_by_user_row)
row = *rowp
row.username = t.current[i].USER
- users[username] = row
+ row_by_user[username] = row
}
row.connections++
// ignore system SQL threads (may be more to filter out)
// add the host if not known already
if host != "" {
if my_hosts, ok = hosts_by_user[username]; !ok {
- my_hosts = make(map_string_string)
+ my_hosts = make(map_string_int)
}
- my_hosts[host] = host // whatever - value doesn't matter
+ my_hosts[host] = 1 // whatever - value doesn't matter
hosts_by_user[username] = my_hosts
}
row.hosts = uint64(len(hosts_by_user[username]))
// add the db count if not known already
if db != "" {
if my_db, ok = dbs_by_user[username]; !ok {
- my_db = make(map_string_string)
+ my_db = make(map_string_int)
}
- my_db[db] = db // whatever - value doesn't matter
+ my_db[db] = 1 // whatever - value doesn't matter
dbs_by_user[username] = my_db
}
row.dbs = uint64(len(dbs_by_user[username]))
- // selects
if re_select.MatchString(info) == true {
row.selects++
}
row.deletes++
}
- users[username] = row
+ row_by_user[username] = row
}
- results = make(pl_by_user_rows, 0, len(users))
- for _, v := range users {
+ results = make(pl_by_user_rows, 0, len(row_by_user))
+ for _, v := range row_by_user {
results = append(results, v)
}
t.results = results