Roxen.git / server / config_interface / actions / cachestatus.pike

version» Context lines:

Roxen.git/server/config_interface/actions/cachestatus.pike:1: - // $Id: cachestatus.pike,v 1.27 2011/01/20 17:23:46 mast Exp $ + // $Id$      #include <roxen.h>   //<locale-token project="admin_tasks">LOCALE</locale-token>   #define LOCALE(X,Y) _STR_LOCALE("admin_tasks",X,Y)      constant action = "status";      string name= LOCALE(59, "Cache status");   string doc = LOCALE(60,    "Show information about the main memory cache in Roxen");    -  + #define VALUE_NA "<span class='dimtext'>n/a</span>" +    string format_hit_rate (int|float hits, int|float misses)   { -  float res = 0.0; -  catch (res = hits * 100.0 / (hits + misses)); -  return sprintf ("%.2f%%", res); +  catch { +  float res = hits * 100.0 / (hits + misses); +  return sprintf ("%.1f%%", res); +  }; +  return VALUE_NA;   }      // Should use external css instead. I'm lazy..   #define TABLE_ATTRS \ -  "style='border-collapse: collapse; white-space: nowrap;'" +  "style='font-size: 85%; border-collapse: collapse; white-space: nowrap; line-height: 1.3; background: #f4f6f8; border: 8px solid #f4f6f8;'"   #define HDR_TR_ATTRS \ -  "style='text-align: center; border-bottom: 1px solid #666;'" +  "style='text-align: right; border-bottom: 1px solid #678;'"   #define BODY_TR_ATTRS(ROW) \    "style='text-align: right; " + \    (ROW ? "border-top: 2px solid transparent;" : "") + "'"   #define FTR_TR_ATTRS \ -  "style='text-align: right; border-top: 1px solid #666;'" +  "style='text-align: right; border-top: 1px solid #678;'"   #define FIRST_CELL \    "style='text-align: left; padding: 0;'"   #define REST_CELLS \ -  "style='white-space: nowrap; padding: 0 0 0 1ex;'" +  "style='white-space: nowrap; padding: 0 0 0 3ex;'"      #define DESCR_ROW(ROW, DESCR, VALUE) \    "<tr " BODY_TR_ATTRS (ROW) ">" \    "<td " FIRST_CELL ">" + (DESCR) + "</td>" \    "<td " REST_CELLS ">" + (VALUE) + "</td>" \    "</tr>"      string parse( RequestID id )   {    string res =    "<input type='hidden' name='action' value='cachestatus.pike' />" -  "<p><cf-refresh/> <cf-cancel href='?class=&form.class;'/></p>\n" +  "<p><cf-refresh/> <cf-cancel href='?class=&form.class;&amp;&usr.set-wiz-id;'/></p>\n"    "<h3>"+    LOCALE(61, "WebServer Memory Cache")+    "</h3>\n" -  "<p><a href='/global_settings/?section=Cache'>" + -  LOCALE(380, "Configure cache settings") + "</a></p>\n"; +  "<p><a href='/global_settings/?section=Cache&amp;&usr.set-wiz-id;'>" + +  LOCALE(380, "Configure Cache Settings") + "</a></p>\n";       mapping(cache.CacheManager:mapping(string:cache.CacheStats)) stats =    cache.cache_stats();       mapping trans = ([    "supports":LOCALE(68,"Supports database"),    "fonts":LOCALE(69,"Fonts"),    "hosts":LOCALE(70,"DNS"),    ]);       string mgr_summary = "<p>" +    sprintf (LOCALE(381, #"\   The configured maximum size %s is divided dynamically between the   cache managers based on the usage for the last half hour. If the   caches are not full then all free space is assigned to each one of   them. They will shrink to the configured maximum size as they fill up."), -  Roxen.sizetostring (cache->total_size_limit)) + "</p>\n" +  "<b>" + Roxen.sizetostring (cache->total_size_limit) + "</b>") + +  "</p>\n"    "<table " TABLE_ATTRS ">\n"    "<tr " HDR_TR_ATTRS ">"    "<th " FIRST_CELL ">" + LOCALE(382, "Cache manager") + "</th>"    "<th " REST_CELLS ">" + LOCALE(64, "Size") + "</th>"    "<th " REST_CELLS ">" + LOCALE(383, "Size limit") + "</th>"    "<th " REST_CELLS ">" + LOCALE(384, "Input rate") + "</th>"    "<th " REST_CELLS ">" + LOCALE(67, "Hit rate") + "</th>"    "<th " REST_CELLS ">" + LOCALE(385, "Cost HR") + "</th>"   #ifdef DEBUG_CACHE_MANAGER    "<th " REST_CELLS " colspan='2'>Entry size</th>"
Roxen.git/server/config_interface/actions/cachestatus.pike:115:   #endif    int|float tot_cost_hits, tot_cost_misses, tot_cost;   #ifdef DEBUG_CACHE_MANAGER    int min_size = Int.NATIVE_MAX, max_size;    int|float min_cost = Float.MAX, max_cost;    int|float min_value = Float.MAX, max_value;    int|float min_pval = Float.MAX, max_pval;   #endif       mapping(string:array(string)) cache_groups = ([]); +  // FIXME: The following should be redundant given the +  // integrated grouping of CacheStats.    foreach (caches; string cache_name;) {    sscanf (cache_name, "%[^:]", string group_name);    cache_groups[group_name] += ({cache_name});    }    -  +  // FIXME: The following looks broken.    mapping(string:string) name_trans =    mkmapping (indices (cache_groups), indices (cache_groups));    foreach (trans; string name; string trans)    if (m_delete (name_trans, name))    name_trans[trans] = name;       foreach (sort (indices (name_trans)); int row; string trans_name) {    string group_name = name_trans[trans_name];       num_caches++;
Roxen.git/server/config_interface/actions/cachestatus.pike:191:    "<td " REST_CELLS ">" +    Roxen.sizetostring (grp_size) + "</td>"    "<td " REST_CELLS ">" +    Roxen.sizetostring (grp_count && (float) grp_size / grp_count) +    "</td>"   #ifdef CACHE_BYTE_HR_STATS    "<td " REST_CELLS ">" +    format_hit_rate (grp_byte_hits, grp_byte_misses) + "</td>"   #endif    "<td " REST_CELLS ">" + -  (mgr->has_cost ? mgr->format_cost (grp_cost) : "n/a") + "</td>" +  (mgr->has_cost ? mgr->format_cost (grp_cost) : VALUE_NA) + "</td>"    "<td " REST_CELLS ">" +    (mgr->has_cost ? -  mgr->format_cost (grp_count && grp_cost / grp_count) : "n/a") + +  mgr->format_cost (grp_count && grp_cost / grp_count) : VALUE_NA) +    "</td>"    "<td " REST_CELLS ">" +    (mgr->has_cost ? -  format_hit_rate (grp_cost_hits, grp_cost_misses) : "n/a") + "</td>" +  format_hit_rate (grp_cost_hits, grp_cost_misses) : VALUE_NA) + "</td>"    "</tr>\n";       tot_count += grp_count;    tot_hits += grp_hits;    tot_misses += grp_misses;    tot_size += grp_size;   #ifdef CACHE_BYTE_HR_STATS    tot_byte_hits += grp_byte_hits;    tot_byte_misses += grp_byte_misses;   #endif
Roxen.git/server/config_interface/actions/cachestatus.pike:241: Inside #if defined(DEBUG_CACHE_MANAGER)
   Roxen.sizetostring (min_size) + " ..</td>"    "<td " REST_CELLS " align='left'>" +    Roxen.sizetostring (max_size) + "</td>" +    (mgr->has_cost ?    "<td " REST_CELLS ">" +    (floatp (min_cost) ? sprintf ("%.3g", min_cost) : min_cost) +    " ..</td>" +    "<td " REST_CELLS " align='left'>" +    (floatp (max_cost) ? sprintf ("%.3g", max_cost) : max_cost) +    "</td>" : -  "<td " REST_CELLS " colspan='2' align='center'>n/a</td>") + +  "<td " REST_CELLS " colspan='2' align='center'>" VALUE_NA "</td>") +    "<td " REST_CELLS ">" +    (floatp (min_value) ? sprintf ("%.3g", min_value) : min_value) +    " ..</td>" +    "<td " REST_CELLS " align='left'>" +    (floatp (max_value) ? sprintf ("%.3g", max_value) : max_value) +    "</td>"    "<td " REST_CELLS ">" +    (floatp (min_pval) ? sprintf ("%.3g", min_pval) : min_pval) +    " ..</td>" +    "<td " REST_CELLS " align='left'>" +
Roxen.git/server/config_interface/actions/cachestatus.pike:278:    "<td " REST_CELLS ">" +    Roxen.sizetostring (tot_size) + "</td>"    "<td " REST_CELLS ">" +    Roxen.sizetostring (tot_count && (float) tot_size / tot_count) +    "</td>"   #ifdef CACHE_BYTE_HR_STATS    "<td " REST_CELLS ">" +    format_hit_rate (tot_byte_hits, tot_byte_misses) + "</td>"   #endif    "<td " REST_CELLS ">" + -  (mgr->has_cost ? mgr->format_cost (tot_cost) : "n/a") + "</td>" +  (mgr->has_cost ? mgr->format_cost (tot_cost) : VALUE_NA) + "</td>"    "<td " REST_CELLS ">" +    (mgr->has_cost ? -  mgr->format_cost (tot_count && tot_cost / tot_count) : "n/a") + +  mgr->format_cost (tot_count && tot_cost / tot_count) : VALUE_NA) +    "</td>"    "<td " REST_CELLS ">" +    (mgr->has_cost ? -  format_hit_rate (tot_cost_hits, tot_cost_misses) : "n/a") + "</td>" +  format_hit_rate (tot_cost_hits, tot_cost_misses) : VALUE_NA) + "</td>"    "</tr>\n";    mgr_stats += "</table>\n";    }    }       mgr_stats += "<div style='font-size: smaller;'><p>" +    LOCALE(392, #"\   <i>Cost HR</i> is the cost hit rate, i.e. every hit and miss is   weighted with the cost for each entry according to the cost metric of   the cache manager. Note that it uses the approximation that every
Roxen.git/server/config_interface/actions/cachestatus.pike:386:    if (row >= 1)    res += "<tr " FTR_TR_ATTRS ">"    "<td " FIRST_CELL "><b>"+LOCALE(178, "Total")+"</b></td>"    "<td " REST_CELLS ">" + totale + "</td>"    "<td " REST_CELLS ">" + Roxen.sizetostring(totalm) + "</td></tr>\n";    res += "</table>\n";    }       // ---    +  { +  int tot_entries = 0; +  int tot_hits = 0; +  int tot_misses = 0; +  int tot_current_size = 0; +  int tot_max_size = 0; +  +  string prot_cache_desc = +  "<p>" + +  LOCALE(422, "RAM-based cache per configuration that stores " +  "commonly requested files. Note that entries here don't " +  "count toward the aforementioned size limit for RAM caches in " +  "general, but instead is bound by a specific setting in each " +  "configuration.") + +  "</p>"; +  +  res += +  "<br/><h3>" + LOCALE(423, "Protocol Cache") + "</h3>" + +  prot_cache_desc + +  "<table " TABLE_ATTRS ">\n" +  "<tr " HDR_TR_ATTRS ">" +  "<th " FIRST_CELL ">" + LOCALE(424, "Configuration") + "</th>" +  "<th " REST_CELLS ">" + LOCALE(295, "Entries") + "</th>" +  "<th " REST_CELLS ">" + LOCALE(387, "Lookups") + "</th>" +  "<th " REST_CELLS ">" + LOCALE(67, "Hit rate") + "</th>" +  "<th " REST_CELLS ">" + LOCALE(64, "Size") + "</th>" +  "<th " REST_CELLS ">" + LOCALE(388, "Size/entry") + "</th>" +  "<th " REST_CELLS ">" + LOCALE(425, "Max file size") + "</th>" +  "<th " REST_CELLS ">" + LOCALE(426, "Max size") + "</th>" +  "</tr>"; +  +  array(Configuration) configs = roxen->configurations; +  string wiz_id = +  (id->real_variables->_roxen_wizard_id || ({ "" }) )[0]; +  string wiz_quoted = Roxen.html_encode_string(wiz_id || ""); +  sort(configs->name, configs); +  foreach (configs; int row; Configuration c) { +  string conf_link = +  "<a href='../sites/site.html/" + +  Roxen.http_encode_url(c->name) + +  "/?section=Cache&_roxen_wizard_id=" + wiz_quoted + "'>" + +  Roxen.html_encode_string(c->query_name()) + +  "</a>"; +  mapping stats = c->datacache && c->datacache->get_cache_stats(); +  if (!stats) +  continue; +  int lookups = stats->hits + stats->misses; +  string hit_rate = format_hit_rate(stats->hits, stats->misses); +  string entry_size = +  stats->entries ? +  Roxen.sizetostring(1.0 * stats->current_size / stats->entries) : +  VALUE_NA; +  res += +  "<tr " BODY_TR_ATTRS (row) ">" +  "<td " FIRST_CELL ">" + conf_link + "</td>" +  "<td " REST_CELLS ">" + stats->entries + "</td>" +  "<td " REST_CELLS ">" + lookups + "</td>" +  "<td " REST_CELLS ">" + hit_rate + "</td>" +  "<td " REST_CELLS ">" + Roxen.sizetostring(stats->current_size) + "</td>" +  "<td " REST_CELLS ">" + entry_size + "</td>" +  "<td " REST_CELLS ">" + Roxen.sizetostring(stats->max_file_size) + "</td>" +  "<td " REST_CELLS ">" + Roxen.sizetostring(stats->max_size) + "</td>" +  "</tr>"; +  +  // Aggregate stats +  tot_entries += stats->entries; +  tot_hits += stats->hits; +  tot_misses += stats->misses; +  tot_current_size += stats->current_size; +  tot_max_size += stats->max_size; +  } +  +  res += +  "<tr " FTR_TR_ATTRS ">" +  "<td " FIRST_CELL "><b>" + LOCALE(178, "Total") + "</b></td>" +  "<td " REST_CELLS ">" + tot_entries + "</td>" +  "<td " REST_CELLS ">" + (tot_hits + tot_misses) + "</td>" +  "<td " REST_CELLS ">" + format_hit_rate(tot_hits, tot_misses) + "</td>" +  "<td " REST_CELLS ">" + Roxen.sizetostring(tot_current_size) + "</td>" +  "<td " REST_CELLS ">" + +  (tot_entries ? +  Roxen.sizetostring((float) tot_current_size / tot_entries) : VALUE_NA) + +  "</td>" +  "<td " REST_CELLS ">" VALUE_NA "</td>" +  "<td " REST_CELLS ">" + Roxen.sizetostring(tot_max_size) + "</td>" +  "</tr>" +  "</table>"; +  } +  +  // --- +     mapping l=Locale.cache_status();    res += "<br/><h3>"+LOCALE(71, "Locale Cache")+"</h3>"    "<table " TABLE_ATTRS ">\n"    DESCR_ROW (0, LOCALE(72, "Used languages:"), l->languages)    DESCR_ROW (1, LOCALE(73, "Registered projects:"), l->reg_proj)    DESCR_ROW (2, LOCALE(74, "Loaded project files:"), l->load_proj)    DESCR_ROW (3, LOCALE(75, "Current cache size:"),    Roxen.sizetostring(l->bytes))    "</table>\n";       return res;   }