Add exclude-listeners parameter
This commit is contained in:
parent
ebc48e3615
commit
c0382eaad9
10 changed files with 47 additions and 22 deletions
|
@ -38,6 +38,7 @@ type Config struct {
|
|||
ExcludeUsers StringFlags `yaml:"exclude-users"`
|
||||
ExcludeUsersRegex string `yaml:"exclude-users-regex"`
|
||||
ExcludeUsersRegexCompiled *regexp.Regexp
|
||||
ExcludeListeners bool `yaml:"exclude-listeners"`
|
||||
Cancel bool `yaml:"cancel"`
|
||||
}
|
||||
|
||||
|
|
|
@ -2,13 +2,13 @@ package base
|
|||
|
||||
// Context stores dynamic values like channels and exposes configuration
|
||||
type Context struct {
|
||||
Sessions chan Session
|
||||
Sessions chan *Session
|
||||
Done chan bool
|
||||
Config *Config
|
||||
}
|
||||
|
||||
// NewContext instanciates a Context
|
||||
func NewContext(config *Config, sessions chan Session, done chan bool) *Context {
|
||||
func NewContext(config *Config, sessions chan *Session, done chan bool) *Context {
|
||||
return &Context{
|
||||
Config: config,
|
||||
Sessions: sessions,
|
||||
|
|
|
@ -42,7 +42,7 @@ func (db *Db) Disconnect() {
|
|||
}
|
||||
|
||||
// Sessions connects to the database and returns current sessions
|
||||
func (db *Db) Sessions() (sessions []Session) {
|
||||
func (db *Db) Sessions() (sessions []*Session) {
|
||||
query := fmt.Sprintf(`select pid as pid,
|
||||
usename as user,
|
||||
datname as db,
|
||||
|
@ -72,7 +72,7 @@ func (db *Db) Sessions() (sessions []Session) {
|
|||
}
|
||||
|
||||
// TerminateSessions terminates a list of sessions
|
||||
func (db *Db) TerminateSessions(sessions []Session) {
|
||||
func (db *Db) TerminateSessions(sessions []*Session) {
|
||||
var pids []int64
|
||||
for _, session := range sessions {
|
||||
pids = append(pids, session.Pid)
|
||||
|
@ -86,7 +86,7 @@ func (db *Db) TerminateSessions(sessions []Session) {
|
|||
}
|
||||
|
||||
// CancelSessions terminates current query of a list of sessions
|
||||
func (db *Db) CancelSessions(sessions []Session) {
|
||||
func (db *Db) CancelSessions(sessions []*Session) {
|
||||
var pids []int64
|
||||
for _, session := range sessions {
|
||||
pids = append(pids, session.Pid)
|
||||
|
|
|
@ -17,8 +17,8 @@ type Session struct {
|
|||
}
|
||||
|
||||
// NewSession instanciates a Session
|
||||
func NewSession(pid int64, user string, db string, client string, state string, query string, stateDuration float64) Session {
|
||||
return 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,
|
||||
|
@ -30,7 +30,7 @@ func NewSession(pid int64, user string, db string, client string, state string,
|
|||
}
|
||||
|
||||
// String represents a Session as a string
|
||||
func (s Session) String() string {
|
||||
func (s *Session) String() string {
|
||||
var output []string
|
||||
if s.Pid != 0 {
|
||||
output = append(output, fmt.Sprintf("pid=%d", s.Pid))
|
||||
|
@ -57,7 +57,7 @@ func (s Session) String() string {
|
|||
}
|
||||
|
||||
// IsIdle returns true when a session is doing nothing
|
||||
func (s Session) IsIdle() bool {
|
||||
func (s *Session) IsIdle() bool {
|
||||
if s.State == "idle" || s.State == "idle in transaction" || s.State == "idle in transaction (aborted)" {
|
||||
return true
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue