in postgresql_metrics/postgres_queries.py [0:0]
def get_heap_hit_statistics(conn):
sql = ("SELECT current_database(), now(), sum(heap_blks_read), sum(heap_blks_hit) "
"FROM pg_statio_user_tables")
results = query(conn, sql)
if not results or None in results[0]:
LOG.error("fetching heap_hit_statistics got empty results: {}", str(results))
return None, None, None, None
db_name, time_now, heap_read_now, heap_hit_now = results[0]
recent_heap_read = get_metric_diff(db_name, 'heap_read', time_now, heap_read_now)
recent_heap_hit = get_metric_diff(db_name, 'heap_hit', time_now, heap_hit_now)
recent_heap_hit_ratio = None
if recent_heap_read is not None:
if recent_heap_hit == 0:
recent_heap_hit_ratio = 0
else:
recent_heap_hit_ratio = recent_heap_hit / float(recent_heap_hit + recent_heap_read)
return db_name, recent_heap_read, recent_heap_hit, recent_heap_hit_ratio