pg_monitor 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +8 -1
- data/lib/pg_monitor/db_connection.rb +23 -7
- data/lib/pg_monitor/index_usage.rb +3 -1
- data/lib/pg_monitor/slow_queries.rb +3 -1
- data/lib/pg_monitor/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c4c7d58e46ed8ee3d95495bb02fc8476bbc38b6f58e00f372b685b69691f37c
|
4
|
+
data.tar.gz: f59c2029bb6a99e861c65702ab590fdc6980e9b46eca30186629165da1b43e94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5480cd130a99bd63468032c7cfbb45ce012b89fabbaba67495eaa418a723b08eec1b0ee67765447b84bad37211f1185d78b10244fb5f78bd46d05baaa937f34
|
7
|
+
data.tar.gz: d2a72a77da40a346dee9edc1e573c9c668dce9a291e7edb043a2e4c13e05db1518aa3dc70ec65b0868a8e20bb6f12f4b0d0a700b5b60f86b78ce86cf6f712f8c
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@ It would integrate seamlessly with a Rails application in the future, and would
|
|
7
7
|
|
8
8
|
- View index usage statistics (last used, scan count, etc.)
|
9
9
|
- Identify slow queries using `pg_stat_statements`
|
10
|
-
-
|
10
|
+
- Works with the existing Rails database configuration
|
11
11
|
- [TBD] Provides a simple HTML interface for monitoring
|
12
12
|
|
13
13
|
## Installation
|
@@ -50,6 +50,13 @@ Restart PostgreSQL after making the changes:
|
|
50
50
|
sudo systemctl restart postgresql
|
51
51
|
```
|
52
52
|
|
53
|
+
Ensure that the extension is enabled in your database:
|
54
|
+
|
55
|
+
```sql
|
56
|
+
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
|
57
|
+
```
|
58
|
+
Execute the above SQL query by connecting to your database using `psql` or any other client.
|
59
|
+
|
53
60
|
## Usage
|
54
61
|
|
55
62
|
Mount the engine in `config/routes.rb`:
|
@@ -3,13 +3,29 @@ require "pg"
|
|
3
3
|
module PgMonitor
|
4
4
|
class DBConnection
|
5
5
|
def self.connection
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
if active_record_present?
|
7
|
+
ActiveRecord::Base.connection.raw_connection
|
8
|
+
else
|
9
|
+
@connection ||= PG.connect(connection_params)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.active_record_present?
|
14
|
+
defined?(ActiveRecord::Base)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.connection_params
|
18
|
+
{
|
19
|
+
dbname: ENV.fetch("PG_DATABASE"),
|
20
|
+
user: ENV.fetch("PG_USER"),
|
21
|
+
password: ENV.fetch("PG_PASSWORD"),
|
22
|
+
host: ENV.fetch("PG_HOST"),
|
23
|
+
port: ENV.fetch("PG_PORT")
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.clear_connection!
|
28
|
+
@connection = nil
|
13
29
|
end
|
14
30
|
end
|
15
31
|
end
|
data/lib/pg_monitor/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pg_monitor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hassan Murtaza
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-03-
|
11
|
+
date: 2025-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|