Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcba87df

Browse files
Fixed stats_reset metric
1 parent82679b9 commitcba87df

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

‎config/pgwatch-prometheus/metrics.yml‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,9 +1889,8 @@ metrics:
18891889
11:|
18901890
select
18911891
datname as tag_database_name,
1892-
stats_reset,
1893-
extract(epoch from stats_reset) as stats_reset_epoch,
1894-
extract(epoch from now() - stats_reset) as seconds_since_reset
1892+
extract(epoch from stats_reset)::int as stats_reset_epoch,
1893+
extract(epoch from now() - stats_reset)::int as seconds_since_reset
18951894
from pg_stat_database
18961895
where datname = current_database()
18971896
and stats_reset is not null;

‎reporter/postgres_reports.py‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,20 @@ def generate_h002_unused_indexes_report(self, cluster: str = "local", node_name:
317317

318318
unused_indexes_by_db= {}
319319
fordb_nameindatabases:
320+
# Query stats_reset timestamp for this database
321+
stats_reset_query=f'last_over_time(pgwatch_stats_reset_stats_reset_epoch{{cluster="{cluster}", node_name="{node_name}", database_name="{db_name}"}}[10h])'
322+
stats_reset_result=self.query_instant(stats_reset_query)
323+
324+
stats_reset_epoch=None
325+
days_since_reset=None
326+
stats_reset_time=None
327+
328+
ifstats_reset_result.get('status')=='success'andstats_reset_result.get('data', {}).get('result'):
329+
stats_reset_epoch=float(stats_reset_result['data']['result'][0]['value'][1])ifstats_reset_result['data']['result']elseNone
330+
ifstats_reset_epoch:
331+
stats_reset_time=datetime.fromtimestamp(stats_reset_epoch).isoformat()
332+
days_since_reset= (datetime.now()-datetime.fromtimestamp(stats_reset_epoch)).days
333+
320334
# Query unused indexes for each database using last_over_time to get most recent value
321335
unused_indexes_query=f'last_over_time(pgwatch_unused_indexes_index_size_bytes{{cluster="{cluster}", node_name="{node_name}", dbname="{db_name}"}}[10h])'
322336
unused_result=self.query_instant(unused_indexes_query)
@@ -363,7 +377,12 @@ def generate_h002_unused_indexes_report(self, cluster: str = "local", node_name:
363377
"unused_indexes":unused_indexes,
364378
"total_count":len(unused_indexes),
365379
"total_size_bytes":total_unused_size,
366-
"total_size_pretty":self.format_bytes(total_unused_size)
380+
"total_size_pretty":self.format_bytes(total_unused_size),
381+
"stats_reset": {
382+
"stats_reset_epoch":stats_reset_epoch,
383+
"stats_reset_time":stats_reset_time,
384+
"days_since_reset":days_since_reset
385+
}
367386
}
368387

369388
returnself.format_report_data("H002",unused_indexes_by_db,node_name)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp