parse rds slowquery user
This commit is contained in:
parent
07828aef7b
commit
a66ded0e8f
2 changed files with 39 additions and 0 deletions
|
|
@ -107,6 +107,20 @@ func FieldsFromKayvee(line string) (map[string]interface{}, error) {
|
|||
return m, nil
|
||||
}
|
||||
|
||||
var userPattern = `#\sUser@Host:\s(?P<user>[a-zA-Z]+\[[a-zA-Z]+\])\s@\s[a-zA-Z]+.*Id:\s+(?P<id>[0-9]+)`
|
||||
var userPatternRegex = regexp.MustCompile(userPattern)
|
||||
|
||||
func FieldsFromRDSSlowquery(rawlog string) map[string]interface{} {
|
||||
out := map[string]interface{}{}
|
||||
|
||||
match := userPatternRegex.FindStringSubmatch(rawlog)
|
||||
if len(match) == 3 {
|
||||
out["user"] = match[1]
|
||||
out["user_id"] = match[2]
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// MetricsRoute represents a metrics kv log route
|
||||
type MetricsRoute struct {
|
||||
Series string
|
||||
|
|
@ -421,6 +435,14 @@ func ParseAndEnhance(line string, env string) (map[string]interface{}, error) {
|
|||
}
|
||||
}
|
||||
|
||||
// Try pulling RDS slowquery logs fields out of message
|
||||
if out["hostname"] == "aws-rds" {
|
||||
slowQueryFields := FieldsFromRDSSlowquery(rawlog)
|
||||
for k, v := range slowQueryFields {
|
||||
out[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
return out, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -344,6 +344,23 @@ func TestParseAndEnhance(t *testing.T) {
|
|||
"timestamp": logTime2,
|
||||
},
|
||||
},
|
||||
ParseAndEnhanceSpec{
|
||||
Title: "RDS Slowquery Log",
|
||||
Line: `2017-04-05T21:57:46+00:00 aws-rds production-aurora-test-db: Slow query: # Time: 190921 16:02:59
|
||||
# User@Host: rdsadmin[rdsadmin] @ localhost [] Id: 1
|
||||
# Query_time: 22.741550 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0SET timestamp=1569081779;call action start_seamless_scaling('AQEAAB1P/PAIqvTHEQFJAEkojZUoH176FGJttZ62JF5QmRehaf0S0VFTa+5MPJdYQ9k0/sekBlnMi8U=', 300000, 2);
|
||||
SET timestamp=1569862702;`,
|
||||
ExpectedOutput: map[string]interface{}{
|
||||
"env": "deploy-env",
|
||||
"hostname": "aws-rds",
|
||||
"programname": "production-aurora-test-db",
|
||||
"decoder_msg_type": "syslog",
|
||||
"rawlog": "Slow query: # Time: 190921 16:02:59\n# User@Host: rdsadmin[rdsadmin] @ localhost [] Id: 1\n# Query_time: 22.741550 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0SET timestamp=1569081779;call action start_seamless_scaling('AQEAAB1P/PAIqvTHEQFJAEkojZUoH176FGJttZ62JF5QmRehaf0S0VFTa+5MPJdYQ9k0/sekBlnMi8U=', 300000, 2);\nSET timestamp=1569862702;",
|
||||
"timestamp": logTime2,
|
||||
"user": "rdsadmin[rdsadmin]",
|
||||
"user_id": "1",
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, spec := range specs {
|
||||
t.Run(fmt.Sprintf(spec.Title), func(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue