Skip to content

Commit

Permalink
fixes in stats
Browse files Browse the repository at this point in the history
  • Loading branch information
antleb committed Feb 22, 2024
1 parent f8ad780 commit c8f5a63
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public class CacheEntry {
private Result shadowResult;
private Date created = new Date();
private Date updated = new Date();
private int totalHits = 0;
private int sessionHits = 0;
private int totalHits = 1;
private int sessionHits = 1;
private boolean pinned = false;

private String profile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,19 @@ public void deleteEntry(String key) {

public Map<String, Object> stats() {
DatasourceContext.setContext(CACHE_DB_NAME);

Map<String, Object> stats = new LinkedHashMap<>();

stats.put("total", jdbcTemplate.queryForObject("select count(*) from cache_entry",new Object[] {}, Integer.class));
stats.put("with_shadow", jdbcTemplate.queryForObject("select count(*) from cache_entry where shadow is not null and shadow != ''",new Object[] {}, Integer.class));
stats.put("profiles", jdbcTemplate.queryForMap("select profile, count(key) as c from cache_entry where key not in ('SHADOW_STATS_NUMBERS', 'STATS_NUMBERS') order by count(key) desc group by profile"));
stats.put("profiles", jdbcTemplate.query("select profile, count(key) as queries, avg(exectime) as avg_exec_time from cache_entry where key not in ('SHADOW_STATS_NUMBERS', 'STATS_NUMBERS') group by profile order by count(key) desc", (rs, rowNum) -> {
Map<String, Object> map = new LinkedHashMap<>();

map.put("profile", rs.getString("profile"));
map.put("queries", rs.getInt("queries"));
map.put("avg_exec_time", rs.getInt("avg_exec_time"));

return map;
}));

stats.put("total.top10", jdbcTemplate.query("select * from cache_entry where key not in ('SHADOW_STATS_NUMBERS', 'STATS_NUMBERS') order by total_hits desc limit 10", (rs, rowNum) -> {
CacheEntry entry = null;
Expand Down

0 comments on commit c8f5a63

Please sign in to comment.