github.com/netdata/go.d.plugin@v0.58.1/modules/mysql/collect_process_list.go (about) 1 // SPDX-License-Identifier: GPL-3.0-or-later 2 3 package mysql 4 5 import ( 6 "github.com/blang/semver/v4" 7 ) 8 9 // Table Schema: 10 // (MariaDB) https://mariadb.com/kb/en/information-schema-processlist-table/ 11 // (MySql) https://dev.mysql.com/doc/refman/5.7/en/information-schema-processlist-table.html 12 const ( 13 queryShowProcessList = ` 14 SELECT 15 time, 16 user 17 FROM 18 information_schema.processlist 19 WHERE 20 info IS NOT NULL 21 AND info NOT LIKE '%PROCESSLIST%' 22 ORDER BY 23 time;` 24 ) 25 26 // Performance Schema 27 // (MySQL) https://dev.mysql.com/doc/refman/8.0/en/performance-schema-processlist-table.html 28 const ( 29 queryShowProcessListPS = ` 30 SELECT 31 time, 32 user 33 FROM 34 performance_schema.processlist 35 WHERE 36 info IS NOT NULL 37 AND info NOT LIKE '%PROCESSLIST%' 38 ORDER BY 39 time;` 40 ) 41 42 func (m *MySQL) collectProcessListStatistics(mx map[string]int64) error { 43 var q string 44 mysqlMinVer := semver.Version{Major: 8, Minor: 0, Patch: 22} 45 if !m.isMariaDB && m.version.GTE(mysqlMinVer) && m.varPerformanceSchema == "ON" { 46 q = queryShowProcessListPS 47 } else { 48 q = queryShowProcessList 49 } 50 m.Debugf("executing query: '%s'", q) 51 52 var maxTime int64 // slowest query milliseconds in process list 53 54 duration, err := m.collectQuery(q, func(column, value string, _ bool) { 55 switch column { 56 case "time": 57 maxTime = parseInt(value) 58 case "user": 59 // system user refers to non-client threads 60 // event_scheduler is the thread used to monitor scheduled events 61 // system user and event_scheduler threads are grouped as system/database threads 62 // authenticated and unauthenticated user are grouped as users 63 // please see USER section in 64 // https://dev.mysql.com/doc/refman/8.0/en/information-schema-processlist-table.html 65 switch value { 66 case "system user", "event_scheduler": 67 mx["process_list_queries_count_system"] += 1 68 default: 69 mx["process_list_queries_count_user"] += 1 70 } 71 } 72 }) 73 if err != nil { 74 return err 75 } 76 77 if _, ok := mx["process_list_queries_count_system"]; !ok { 78 mx["process_list_queries_count_system"] = 0 79 } 80 if _, ok := mx["process_list_queries_count_user"]; !ok { 81 mx["process_list_queries_count_user"] = 0 82 } 83 mx["process_list_fetch_query_duration"] = duration 84 mx["process_list_longest_query_duration"] = maxTime 85 86 return nil 87 }