Skip to content

Commit

Permalink
Capture more details in LongTransactions events (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
jturkel committed Feb 7, 2020
1 parent c66ffe4 commit 1bf5902
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# postgres-vacuum-monitor
## v.0.5.0
- Add `wait_event_type`, `transaction_id` and `min_transaction_id` to `LongTransactions` events.

## v.0.5.0
- Renamed `LongQueries` event to `LongTransactions`.
- Renamed `LongTransactions.query` to `LongTransactions.most_recent_query` and added a
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ For long running transactions, the event name is `LongTransactions` and the attr
running_time: # How long has it been running in seconds.
application_name: # What's the application name that is running the query.
most_recent_query: # The last query started by the transaction
state: # The state of the transaction - either "active" or ""
state: # The state of the transaction - either "active" or "idle in transaction"
wait_event_type: # The type of lock the transaction is waiting for if applicable
transaction_id: # The transaction_id which will be null for read-only transactions
min_transaction_id: # The mininum transaction id horizon
}
```

Expand Down
5 changes: 4 additions & 1 deletion lib/postgres/vacuum/jobs/monitor_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ def perform(*)
running_time: row['seconds'],
application_name: row['application_name'],
most_recent_query: row['query'],
state: row['state']
state: row['state'],
wait_event_type: row['wait_event_type'],
transaction_id: row['backend_xid'],
min_transaction_id: row['backend_xmin']
)
end

Expand Down
5 changes: 4 additions & 1 deletion lib/postgres/vacuum/monitor/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ def long_running_transactions
EXTRACT(EPOCH FROM (now() - xact_start)) AS seconds,
application_name,
query,
state
state,
backend_xid,
backend_xmin,
wait_event_type
FROM pg_stat_activity
WHERE state IN (#{STATES.join(', ')})
ORDER BY seconds DESC
Expand Down
2 changes: 1 addition & 1 deletion lib/postgres/vacuum/monitor/version.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Postgres
module Vacuum
module Monitor
VERSION = '0.5.0'.freeze
VERSION = '0.6.0'.freeze
end
end
end
10 changes: 8 additions & 2 deletions spec/postgres/vacuum/jobs/monitor_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ def self.report_event(name, attributes = {})
'seconds' => 'test_seconds',
'application_name' => 'test_application_name',
'query' => 'test_query',
'state' => 'test_state'
'state' => 'test_state',
'wait_event_type' => 'test_wait_event_type',
'backend_xid' => 'test_backend_xid',
'backend_xmin' => 'test_backend_xmin'
]
)

Expand All @@ -40,7 +43,10 @@ def self.report_event(name, attributes = {})
running_time: 'test_seconds',
application_name: 'test_application_name',
most_recent_query: 'test_query',
state: 'test_state'
state: 'test_state',
wait_event_type: 'test_wait_event_type',
transaction_id: 'test_backend_xid',
min_transaction_id: 'test_backend_xmin'
)
end

Expand Down

0 comments on commit 1bf5902

Please sign in to comment.