X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fmemcached_stats.c;h=791c00d9891ef75950cca606c1958ae43a74704e;hb=ef0dfae9de06beccc4ba1b7008c62bbbd0e30d47;hp=4ba2dd966497d3491ab43af72f5f9d0938d88a20;hpb=f562c49d93b63a33b4c914a1c5b0ec43576aaafc;p=awesomized%2Flibmemcached diff --git a/libmemcached/memcached_stats.c b/libmemcached/memcached_stats.c index 4ba2dd96..791c00d9 100644 --- a/libmemcached/memcached_stats.c +++ b/libmemcached/memcached_stats.c @@ -84,6 +84,14 @@ static void set_data(memcached_stat_st *stat, char *key, char *value) { stat->total_items= strtol(value, (char **)NULL, 10); } + else if (!strcmp("bytes_read", key)) + { + stat->bytes_read= strtoll(value, (char **)NULL, 10); + } + else if (!strcmp("bytes_written", key)) + { + stat->bytes_written= strtoll(value, (char **)NULL, 10); + } else if (!strcmp("bytes", key)) { stat->bytes= strtoll(value, (char **)NULL, 10); @@ -120,14 +128,6 @@ static void set_data(memcached_stat_st *stat, char *key, char *value) { stat->evictions= (uint64_t)strtoll(value, (char **)NULL, 10); } - else if (!strcmp("bytes_read", key)) - { - stat->bytes_read= strtoll(value, (char **)NULL, 10); - } - else if (!strcmp("bytes_written", key)) - { - stat->bytes_written= strtoll(value, (char **)NULL, 10); - } else if (!strcmp("limit_maxbytes", key)) { stat->limit_maxbytes= strtoll(value, (char **)NULL, 10); @@ -136,14 +136,25 @@ static void set_data(memcached_stat_st *stat, char *key, char *value) { stat->threads= strtol(value, (char **)NULL, 10); } - else + else if (!(strcmp("delete_misses", key) == 0 ||/* New stats in the 1.3 beta */ + strcmp("delete_hits", key) == 0 ||/* Just swallow them for now.. */ + strcmp("incr_misses", key) == 0 || + strcmp("incr_hits", key) == 0 || + strcmp("decr_misses", key) == 0 || + strcmp("decr_hits", key) == 0 || + strcmp("cas_misses", key) == 0 || + strcmp("cas_hits", key) == 0 || + strcmp("cas_badval", key) == 0 || + strcmp("cmd_flush", key) == 0 || + strcmp("accepting_conns", key) == 0 || + strcmp("listen_disabled_num", key) == 0)) { fprintf(stderr, "Unknown key %s\n", key); } } char *memcached_stat_get_value(memcached_st *ptr, memcached_stat_st *stat, - char *key, memcached_return *error) + const char *key, memcached_return *error) { char buffer[SMALL_STRING_LEN]; size_t length; @@ -211,7 +222,74 @@ char *memcached_stat_get_value(memcached_st *ptr, memcached_stat_st *stat, return ret; } -static memcached_return memcached_stats_fetch(memcached_st *ptr, +static memcached_return binary_stats_fetch(memcached_st *ptr, + memcached_stat_st *stat, + char *args, + unsigned int server_key) +{ + memcached_return rc; + + char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; + protocol_binary_request_stats request= {.bytes= {0}}; + request.message.header.request.magic= PROTOCOL_BINARY_REQ; + request.message.header.request.opcode= PROTOCOL_BINARY_CMD_STAT; + request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES; + + if (args != NULL) + { + int len= strlen(args); + + rc= memcached_validate_key_length(len, true); + unlikely (rc != MEMCACHED_SUCCESS) + return rc; + + request.message.header.request.keylen= htons((uint16_t)len); + request.message.header.request.bodylen= htonl(len); + + if ((memcached_do(&ptr->hosts[server_key], request.bytes, + sizeof(request.bytes), 0) != MEMCACHED_SUCCESS) || + (memcached_io_write(&ptr->hosts[server_key], args, len, 1) == -1)) + { + memcached_io_reset(&ptr->hosts[server_key]); + return MEMCACHED_WRITE_FAILURE; + } + } + else + { + if (memcached_do(&ptr->hosts[server_key], request.bytes, + sizeof(request.bytes), 1) != MEMCACHED_SUCCESS) + { + memcached_io_reset(&ptr->hosts[server_key]); + return MEMCACHED_WRITE_FAILURE; + } + } + + memcached_server_response_decrement(&ptr->hosts[server_key]); + do + { + rc= memcached_response(&ptr->hosts[server_key], buffer, + sizeof(buffer), NULL); + if (rc == MEMCACHED_END) + break; + + unlikely (rc != MEMCACHED_SUCCESS) + { + memcached_io_reset(&ptr->hosts[server_key]); + return rc; + } + + set_data(stat, buffer, buffer + strlen(buffer) + 1); + } while (1); + + /* shit... memcached_response will decrement the counter, so I need to + ** reset it.. todo: look at this and try to find a better solution. + */ + ptr->hosts[server_key].cursor_active= 0; + + return MEMCACHED_SUCCESS; +} + +static memcached_return ascii_stats_fetch(memcached_st *ptr, memcached_stat_st *stat, char *args, unsigned int server_key) @@ -273,6 +351,12 @@ memcached_stat_st *memcached_stat(memcached_st *ptr, char *args, memcached_retur memcached_return rc; memcached_stat_st *stats; + if (ptr->flags & MEM_USE_UDP) + { + *error= MEMCACHED_NOT_SUPPORTED; + return NULL; + } + if (ptr->call_malloc) stats= (memcached_stat_st *)ptr->call_malloc(ptr, sizeof(memcached_stat_st)*(ptr->number_of_hosts)); else @@ -281,11 +365,6 @@ memcached_stat_st *memcached_stat(memcached_st *ptr, char *args, memcached_retur if (!stats) { *error= MEMCACHED_MEMORY_ALLOCATION_FAILURE; - if (ptr->call_free) - ptr->call_free(ptr, stats); - else - free(stats); - return NULL; } memset(stats, 0, sizeof(memcached_stat_st)*(ptr->number_of_hosts)); @@ -294,8 +373,12 @@ memcached_stat_st *memcached_stat(memcached_st *ptr, char *args, memcached_retur for (x= 0; x < ptr->number_of_hosts; x++) { memcached_return temp_return; - - temp_return= memcached_stats_fetch(ptr, stats + x, args, x); + + if (ptr->flags & MEM_BINARY_PROTOCOL) + temp_return= binary_stats_fetch(ptr, stats + x, args, x); + else + temp_return= ascii_stats_fetch(ptr, stats + x, args, x); + if (temp_return != MEMCACHED_SUCCESS) rc= MEMCACHED_SOME_ERRORS; } @@ -314,7 +397,10 @@ memcached_return memcached_stat_servername(memcached_stat_st *stat, char *args, memcached_server_add(&memc, hostname, port); - rc= memcached_stats_fetch(&memc, stat, args, 0); + if (memc.flags & MEM_BINARY_PROTOCOL) + rc= binary_stats_fetch(&memc, stat, args, 0); + else + rc= ascii_stats_fetch(&memc, stat, args, 0); memcached_free(&memc); @@ -325,7 +411,7 @@ memcached_return memcached_stat_servername(memcached_stat_st *stat, char *args, We make a copy of the keys since at some point in the not so distant future we will add support for "found" keys. */ -char ** memcached_stat_get_keys(memcached_st *ptr, memcached_stat_st *stat, +char ** memcached_stat_get_keys(memcached_st *ptr, memcached_stat_st *stat __attribute__((unused)), memcached_return *error) { char **list;