X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=src%2Fmemstat.c;h=bc81cb07f195f375444e645d46c61eef4d71e048;hb=c93c9ddbc37c21f33ab152b5121bb69baf437ad1;hp=939f806b681a3a0ad847373a815f36772a872c07;hpb=6030db2543337976c1df861272ce90b25ef83820;p=m6w6%2Flibmemcached diff --git a/src/memstat.c b/src/memstat.c index 939f806b..bc81cb07 100644 --- a/src/memstat.c +++ b/src/memstat.c @@ -14,9 +14,9 @@ /* Prototypes */ void options_parse(int argc, char *argv[]); -static int opt_verbose; -static int opt_displayflag; -static char *opt_servers; +static int opt_verbose= 0; +static int opt_displayflag= 0; +static char *opt_servers= NULL; int main(int argc, char *argv[]) { @@ -25,7 +25,53 @@ int main(int argc, char *argv[]) memc= memcached_init(NULL); options_parse(argc, argv); - parse_opt_servers(memc, opt_servers); + if (opt_servers) + { + unsigned int x; + memcached_return rc; + memcached_stat_st *stat; + memcached_server_st *server_list; + + parse_opt_servers(memc, opt_servers); + stat= memcached_stat(memc, NULL, &rc); + + if (rc != MEMCACHED_SUCCESS || rc != MEMCACHED_SOME_ERRORS); + { + printf("Failure to communicate with servers (%s)\n", + memcached_strerror(memc, rc)); + exit(1); + } + + server_list= memcached_server_list(memc); + + printf("Listing %u Server\n\n", memcached_server_count(memc)); + for (x= 0; x < memcached_server_count(memc); x++) + { + char **list; + char **ptr; + + list= memcached_stat_get_keys(memc, &stat[x], &rc); + assert(list); + assert(rc == MEMCACHED_SUCCESS); + + printf("Server: %s (%u)\n", memcached_server_name(memc, server_list[x]), + memcached_server_port(memc, server_list[x])); + for (ptr= list; *ptr; ptr++) + { + memcached_return rc; + char *value= memcached_stat_get_value(memc, &stat[x], *ptr, &rc); + + printf("\t %s: %s\n", *ptr, value); + free(value); + } + + free(list); + printf("\n"); + } + + free(stat); + free(opt_servers); + } memcached_deinit(memc); @@ -34,7 +80,7 @@ int main(int argc, char *argv[]) void options_parse(int argc, char *argv[]) { - static struct option long_options[] = + static struct option long_options[]= { {"version", no_argument, NULL, OPT_VERSION}, {"help", no_argument, NULL, OPT_HELP}, @@ -45,26 +91,33 @@ void options_parse(int argc, char *argv[]) {0, 0, 0, 0}, }; - int option_index = 0; + int option_index= 0; int option_rv; while (1) { - option_rv = getopt_long(argc, argv, "", long_options, &option_index); + option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index); if (option_rv == -1) break; - switch (option_rv) { + switch (option_rv) + { case 0: break; - case OPT_VERSION: /* --version */ + case OPT_VERBOSE: /* --verbose or -v */ + opt_verbose = OPT_VERBOSE; + break; + case OPT_DEBUG: /* --debug or -d */ + opt_verbose = OPT_DEBUG; + break; + case OPT_VERSION: /* --version or -V */ printf("memcache tools, memcat, v1.0\n"); exit(0); break; - case OPT_HELP: /* --help */ + case OPT_HELP: /* --help or -h */ printf("useful help messages go here\n"); exit(0); break; - case OPT_SERVERS: /* --servers */ - opt_servers = strdup(optarg); + case OPT_SERVERS: /* --servers or -s */ + opt_servers= strdup(optarg); break; case '?': /* getopt_long already printed an error message. */