https://github.com/postgresml/pg_stat_sysinfo
Query system statistics with SQL.
https://github.com/postgresml/pg_stat_sysinfo
Last synced: 2 months ago
JSON representation
Query system statistics with SQL.
- Host: GitHub
- URL: https://github.com/postgresml/pg_stat_sysinfo
- Owner: postgresml
- License: mit
- Created: 2023-05-05T18:18:53.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-06-09T13:43:31.000Z (about 2 years ago)
- Last Synced: 2025-03-26T11:21:13.667Z (3 months ago)
- Language: Rust
- Size: 43 KB
- Stars: 18
- Watchers: 2
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: MIT-LICENSE.txt
Awesome Lists containing this project
README
# `pg_stat_sysinfo`
Collects system statistics.
```sql
----
CREATE EXTENSION pg_stat_sysinfo;
CREATE EXTENSION
----
SELECT * FROM pg_stat_sysinfo_collect();
metric | dimensions | at | value
------------------+--------------+------------------------------+--------------------
load_average | duration:1m | 2023-01-17 20:40:24.74495+00 | 4.3427734375
load_average | duration:5m | 2023-01-17 20:40:24.74495+00 | 2.740234375
load_average | duration:15m | 2023-01-17 20:40:24.74495+00 | 2.390625
cpu_usage | | 2023-01-17 20:40:24.74495+00 | 0.12653848528862
memory_usage | | 2023-01-17 20:40:24.74495+00 | 10.022946522725185
memory_size | | 2023-01-17 20:40:24.74495+00 | 7966543872
memory_available | | 2023-01-17 20:40:24.74495+00 | 7168061440
swap_usage | | 2023-01-17 20:40:24.74495+00 | 0
swap_size | | 2023-01-17 20:40:24.74495+00 | 0
swap_available | | 2023-01-17 20:40:24.74495+00 | 0
disk_usage | fs:/ | 2023-01-17 20:40:24.74495+00 | 48.68292833372914
disk_size | fs:/ | 2023-01-17 20:40:24.74495+00 | 66404147200
disk_available | fs:/ | 2023-01-17 20:40:24.74495+00 | 34076663808
disk_usage | fs:/boot/efi | 2023-01-17 20:40:24.74495+00 | 4.986992082951202
disk_size | fs:/boot/efi | 2023-01-17 20:40:24.74495+00 | 109422592
disk_available | fs:/boot/efi | 2023-01-17 20:40:24.74495+00 | 103965696
(16 rows)```
## Enabling Caching Collector
Add the extension library to `shared_preload_libraries` and set the collection
interval:```python
shared_preload_libraries = 'pg_stat_sysinfo.so'
pg_stat_sysinfo.interval = '1s' # Accepts any time format Postgres recognizes
```The cache is stored in Postgres shared memory. Up to 1280 KiB is cached -- over
an hour, in most cases, at 1 query per second.```sql
----
CREATE EXTENSION pg_stat_sysinfo;
CREATE EXTENSION
----
SELECT DISTINCT min(at) AS oldest,
max(at) - min(at) AS during
FROM pg_stat_sysinfo;
oldest | during
-------------------------------+-----------------
2023-01-17 20:04:46.220977+00 | 00:55:55.908972
(1 row)----
SELECT DISTINCT dimensions FROM pg_stat_sysinfo;
dimensions
----------------duration:1m
duration:5m
duration:15m
disk:/
disk:/boot/efi
(6 rows)```
Basic cache statistics are available:
```sql
----
SELECT * FROM pg_stat_sysinfo_cache_summary();
bytes_used | items
------------+-------
563159 | 3587
(1 row)```
## Configuration Changes
The `pg_stat_sysinfo.interval` can be updated by changing `postgres.conf` and
sending `SIGHUP` to the Postgres server process. The cache worker will use the
new interval from that point forward.If a long enough time has passed between server startup and a `SIGHUP`, or
between one `SIGHUP` and another, the cache worker will refresh the disk
metadata. This will allow it to pick up any disks that have been added to or
removed from the system.