Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 26 additions & 10 deletions collector/info_schema_processlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ var (
processesByUserDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, informationSchema, "processes_by_user"),
"The number of processes by user.",
[]string{"mysql_user"}, nil)
[]string{"mysql_user", "command"}, nil)
processesByHostDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, informationSchema, "processes_by_host"),
"The number of processes by host.",
[]string{"client_host"}, nil)
[]string{"client_host", "command"}, nil)
)

// whitelist for connection/process states in SHOW PROCESSLIST
Expand Down Expand Up @@ -198,8 +198,8 @@ func (ScrapeProcesslist) Scrape(ctx context.Context, db *sql.DB, ch chan<- prome
)
stateCounts := make(map[string]uint32, len(threadStateCounterMap))
stateTime := make(map[string]uint32, len(threadStateCounterMap))
hostCount := make(map[string]uint32)
userCount := make(map[string]uint32)
hostCount := make(map[string]map[string]uint32)
userCount := make(map[string]map[string]uint32)
for k, v := range threadStateCounterMap {
stateCounts[k] = v
stateTime[k] = v
Expand All @@ -213,19 +213,35 @@ func (ScrapeProcesslist) Scrape(ctx context.Context, db *sql.DB, ch chan<- prome
realState := deriveThreadState(command, state)
stateCounts[realState] += processes
stateTime[realState] += time
hostCount[host] = hostCount[host] + processes
userCount[user] = userCount[user] + processes
if _, exits := userCount[user]; exits {
userCount[user][command] = userCount[user][command] + processes
} else {
userCommandCount := make(map[string]uint32)
userCommandCount[command] = processes
userCount[user] = userCommandCount
}
if _, exits := hostCount[host]; exits {
hostCount[host][command] = hostCount[host][command] + processes
} else {
hostCommandCount := make(map[string]uint32)
hostCommandCount[command] = processes
hostCount[host] = hostCommandCount
}
}

if *processesByHostFlag {
for host, processes := range hostCount {
ch <- prometheus.MustNewConstMetric(processesByHostDesc, prometheus.GaugeValue, float64(processes), host)
for host, _ := range hostCount {
for command, processes := range hostCount[host] {
ch <- prometheus.MustNewConstMetric(processesByHostDesc, prometheus.GaugeValue, float64(processes), host, command)
}
}
}

if *processesByUserFlag {
for user, processes := range userCount {
ch <- prometheus.MustNewConstMetric(processesByUserDesc, prometheus.GaugeValue, float64(processes), user)
for user, _ := range userCount {
for command, processes := range userCount[user] {
ch <- prometheus.MustNewConstMetric(processesByUserDesc, prometheus.GaugeValue, float64(processes), user, command)
}
}
}

Expand Down