Use state_change for measuring elapsed time
This commit is contained in:
parent
bb7ddf2bc5
commit
3a89201a94
3 changed files with 35 additions and 40 deletions
|
|
@ -7,29 +7,25 @@ import (
|
|||
|
||||
// Session represents a PostgreSQL backend
|
||||
type Session struct {
|
||||
Pid int64
|
||||
User string
|
||||
Db string
|
||||
Client string
|
||||
State string
|
||||
Query string
|
||||
BackendDuration float64
|
||||
XactDuration float64
|
||||
QueryDuration float64
|
||||
Pid int64
|
||||
User string
|
||||
Db string
|
||||
Client string
|
||||
State string
|
||||
Query string
|
||||
StateDuration float64
|
||||
}
|
||||
|
||||
// NewSession instanciates a Session
|
||||
func NewSession(pid int64, user string, db string, client string, state string, query string, backendDuration float64, xactDuration float64, queryDuration float64) Session {
|
||||
func NewSession(pid int64, user string, db string, client string, state string, query string, stateDuration float64) Session {
|
||||
return Session{
|
||||
Pid: pid,
|
||||
User: user,
|
||||
Db: db,
|
||||
Client: client,
|
||||
State: state,
|
||||
Query: query,
|
||||
BackendDuration: backendDuration,
|
||||
XactDuration: xactDuration,
|
||||
QueryDuration: queryDuration,
|
||||
Pid: pid,
|
||||
User: user,
|
||||
Db: db,
|
||||
Client: client,
|
||||
State: state,
|
||||
Query: query,
|
||||
StateDuration: stateDuration,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -51,17 +47,19 @@ func (s Session) String() string {
|
|||
if s.State != "" {
|
||||
output = append(output, fmt.Sprintf("state=%s", s.State))
|
||||
}
|
||||
if s.BackendDuration != 0 {
|
||||
output = append(output, fmt.Sprintf("backend_duration=%f", s.BackendDuration))
|
||||
if s.StateDuration != 0 {
|
||||
output = append(output, fmt.Sprintf("state_duration=%f", s.StateDuration))
|
||||
}
|
||||
if s.XactDuration != 0 {
|
||||
output = append(output, fmt.Sprintf("xact_duration=%f", s.XactDuration))
|
||||
}
|
||||
if s.QueryDuration != 0 {
|
||||
output = append(output, fmt.Sprintf("query_duration=%f", s.QueryDuration))
|
||||
}
|
||||
if s.Query != "" {
|
||||
if s.Query != "" && !s.IsIdle() {
|
||||
output = append(output, fmt.Sprintf("query=%s", s.Query))
|
||||
}
|
||||
return strings.Join(output, " ")
|
||||
}
|
||||
|
||||
// IsIdle returns true when a session is doing nothing
|
||||
func (s Session) IsIdle() bool {
|
||||
if s.State == "idle" || s.State == "idle in transaction" || s.State == "idle in transaction (aborted)" {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue