int memcache_stats (struct connection *c) { int len = isearch_prepare_stats (); int len2 = prepare_stats (c, stats_buff + len, STATS_BUFF_SIZE - len); write_out (&c->Out, stats_buff, len + len2); write_out (&c->Out, "END\r\n", 5); return 0; }
void ProxyLogger::log() { std::vector<stat_t> stats(num_stats); try { proxy_->router->startupLock.wait(); std::lock_guard<ShutdownLock> lg(proxy_->router->shutdownLock()); std::lock_guard<std::mutex> guard(proxy_->stats_lock); prepare_stats(proxy_, stats.data()); } catch (const shutdown_started_exception& e) { return; } for (int i = 0; i < num_stats; ++i) { if (stats[i].group & rate_stats) { stats[i].type = stat_double; stats[i].data.dbl = stats_rate_value(proxy_, i); } } write_stats_to_disk(proxy_, stats); write_config_sources_info_to_disk(proxy_); for (const auto& filepath : touchStatsFilepaths_) { touchFile(filepath); } if (additionalLogger_) { additionalLogger_->log(stats); } }
void McrouterLogger::log() { std::vector<stat_t> stats(num_stats); prepare_stats(router_, stats.data()); for (int i = 0; i < num_stats; ++i) { if (stats[i].group & rate_stats) { stats[i].type = stat_double; stats[i].data.dbl = stats_aggregate_rate_value(router_, i); } else if (stats[i].group & max_stats) { stats[i].type = stat_uint64; stats[i].data.uint64 = stats_aggregate_max_value(router_, i); } } write_stats_to_disk(router_.opts(), stats); write_config_sources_info_to_disk(router_); for (const auto& filepath : touchStatsFilepaths_) { touchFile(filepath); } if (additionalLogger_) { additionalLogger_->log(stats); } }
int memcache_get (struct connection *c, const char *old_key, int old_key_len) { INIT; if (verbosity > 1) { fprintf (stderr, "memcache_get: key='%s', key_len=%d\n", old_key, old_key_len); } char *key; int key_len; eat_at (old_key, old_key_len, &key, &key_len); int mode = 0, st = 0; if (key_len >= 5 && !strncmp (key, "hints", 5)) { mode = 1; st = 5; } #ifdef TYPES if (key_len >= 5 && !strncmp (key, "types", 5)) { mode = 2; st = 5; } if (key_len >= 11 && !strncmp (key, "hints_debug", 11)) { mode = 3; st = 11; } #endif if (mode) { if (key[st] != '(' || key[key_len - 1] != ')') { RETURN(get, 0); } int len = key_len - st - 2; memcpy (buf, key + st + 1, sizeof (char) * len); buf[len] = 0; if (verbosity >= 2) { fprintf (stderr, "run get_hints (%s, %d)\n", buf, mode); } get_hints (buf, mode, MAX_VALUE_LEN); return_one_key (c, old_key, buf, strlen (buf)); if (verbosity > 0) { if (mytime() + cmd_time > 0.005) { fprintf (stderr, "Warning!!! Search query (%s) was %lf seconds.\n", key, mytime() + cmd_time); } } RETURN(get, 0); } if (key_len >= 10 && !strncmp (key, "suggestion", 10)) { if (key[10] != '(' || key[key_len - 1] != ')') { RETURN(get, 0); } int len = key_len - 12; memcpy (buf, key + 11, sizeof (char) * len); buf[len] = 0; if (verbosity >= 2) { fprintf (stderr, "run get_suggestion (%s)\n", buf); } get_suggestion (buf, MAX_VALUE_LEN); return_one_key (c, old_key, buf, strlen (buf)); if (verbosity > 0) { if (mytime() + cmd_time > 0.005) { fprintf (stderr, "Warning!!! Search query (%s) was %lf seconds.\n", key, mytime() + cmd_time); } } RETURN(get, 0); } if (key_len >= 5 && !strncmp (key, "stats", 5)) { int len = isearch_prepare_stats (); int len2 = prepare_stats (c, stats_buff + len, STATS_BUFF_SIZE - len); return_one_key (c, old_key, stats_buff, len + len2 - 1); return 0; } if (key_len >= 3 && !strncmp (key, "top", 3)) { int cnt; if (sscanf (key, "top%d", &cnt) == 1) { get_top (buf, cnt, MAX_VALUE_LEN); return_one_key (c, old_key, buf, strlen (buf)); } RETURN(get, 0); } if (key_len >= 4 && !strncmp (key, "best", 4)) { int cnt; if (sscanf (key, "best%d", &cnt) == 1) { get_best (buf, cnt, MAX_VALUE_LEN); return_one_key (c, old_key, buf, strlen (buf)); } RETURN(get, 0); } if (key_len >= 10 && !strncmp (key, "black_list", 10)) { if (key_len >= 16 && !strncmp (key, "black_list_force", 16)) { black_list_force(); } else { char *s = black_list_get(); int len = strlen (s); return_one_key (c, old_key, s, len); } RETURN(get, 0); } RETURN(get, 0); }
static int filesys_prepare_stats (struct connection *c) { dyn_update_stats (); char *stats_buffer = value_buff; int STATS_BUFF_SIZE = MAX_VALUE_LEN; int stats_len = snprintf (stats_buffer, STATS_BUFF_SIZE, "heap_allocated\t%ld\n" "heap_max\t%ld\n" "wasted_heap_blocks\t%d\n" "wasted_heap_bytes\t%ld\n" "free_heap_blocks\t%d\n" "free_heap_bytes\t%ld\n" "binlog_original_size\t%lld\n" "binlog_loaded_bytes\t%lld\n" "binlog_load_time\t%.6lfs\n" "current_binlog_size\t%lld\n" "binlog_path\t%s\n" "binlog_first_timestamp\t%d\n" "binlog_read_timestamp\t%d\n" "binlog_last_timestamp\t%d\n" "max_binlog_size\t%lld\n" "index_size\t%lld\n" "index_path\t%s\n" "index_load_time\t%.6lfs\n" "cmd_get\t%lld\n" "cmd_set\t%lld\n" "get_hits\t%lld\n" "get_misses\t%lld\n" "cmd_incr\t%lld\n" "cmd_decr\t%lld\n" "cmd_delete\t%lld\n" "cmd_version\t%lld\n" "cmd_stats\t%lld\n" "alloc_updates_tree_nodes\t%d\n" "directory_nodes\t%d\n" "inodes\t%d\n" "write_allocated_data\t%lld\n" "loaded_metafiles\t%d\n" "loaded_metafiles_bytes\t%lld\n" "max_loaded_metafiles_bytes\t%lld\n" "version\t" VERSION_STR " compiled at " __DATE__ " " __TIME__ " by gcc " __VERSION__ " " #ifdef __LP64__ "64-bit" #else "32-bit" #endif "\n", (long)(dyn_cur - dyn_first), (long)(dyn_last - dyn_first), wasted_blocks, wasted_bytes, freed_blocks, freed_bytes, binlog_loaded_size, log_readto_pos - jump_log_pos, binlog_load_time, log_pos, binlogname ? (strlen (binlogname) < 250 ? binlogname : "(too long)") : "(none)", log_first_ts, log_read_until, log_last_ts, max_binlog_size, index_size, engine_snapshot_name, index_load_time, cmd_get, cmd_set, get_hits, get_missed, cmd_incr, cmd_decr, cmd_delete, cmd_version, cmd_stats, alloc_tree_nodes, tot_directory_nodes, tot_inodes, tot_allocated_data, tot_loaded_metafiles, tot_loaded_index_data, max_loaded_index_data); if (stats_len >= STATS_BUFF_SIZE) { return STATS_BUFF_SIZE - 1; } stats_len += prepare_stats (c, stats_buffer + stats_len, STATS_BUFF_SIZE - stats_len); return stats_len; }