#include <sys/socket.h>
#include <sys/types.h>
#include <sys/un.h>
+#include <time.h>
#include <unistd.h>
#include "charfuncs.h"
#include "parsekey.h"
#include "version.h"
+static struct keyd_stats *stats;
+
void daemonize(void)
{
pid_t pid;
}
if (ret == 0) {
+ if (cmd < KEYD_CMD_LAST) {
+ stats->command_stats[cmd]++;
+ } else {
+ stats->command_stats[KEYD_CMD_UNKNOWN]++;
+ }
switch (cmd) {
case KEYD_CMD_VERSION:
cmd = KEYD_REPLY_OK;
ret = 1;
trytocleanup();
break;
+ case KEYD_CMD_STATS:
+ cmd = KEYD_REPLY_OK;
+ write(fd, &cmd, sizeof(cmd));
+ cmd = sizeof(*stats);
+ write(fd, &cmd, sizeof(cmd));
+ write(fd, stats,
+ sizeof(*stats));
+ break;
default:
logthing(LOGTHING_ERROR, "Got unknown command: %d",
cmd);
}
if (ret != -1) {
+ stats->connects++;
while (!sock_do(srv)) ;
sock_close(srv);
}
catchsignals();
signal(SIGPIPE, SIG_IGN);
+
+ stats = calloc(1, sizeof(*stats));
+ if (!stats) {
+ logthing(LOGTHING_ERROR,
+ "Couldn't allocate memory for stats structure.");
+ exit(EXIT_FAILURE);
+ }
+ stats->started = time(NULL);
+
snprintf(sockname, 1023, "%s/%s", config.db_dir, KEYD_SOCKET);
fd = sock_init(sockname);
unlink(sockname);
}
+ free(stats);
+
cleanuplogthing();
cleanupconfig();
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <time.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
static void keyd_status(void)
{
uint32_t reply;
+ struct keyd_stats stats;
keyd_do_command(KEYD_CMD_VERSION, &reply, sizeof(reply));
printf("Using keyd protocol version %d.\n", reply);
+ keyd_do_command(KEYD_CMD_STATS, &stats, sizeof(stats));
+ printf("keyd running since %s", ctime(&stats.started));
+ printf("%d client connections received\n", stats.connects);
+
+ printf("Command statistics:\n");
+ printf(" Version: %d\n",
+ stats.command_stats[KEYD_CMD_VERSION]);
+ printf(" Get key: %d\n", stats.command_stats[KEYD_CMD_GET]);
+ printf(" Store key: %d\n",
+ stats.command_stats[KEYD_CMD_STORE]);
+ printf(" Delete key: %d\n",
+ stats.command_stats[KEYD_CMD_DELETE]);
+ printf(" Search key: %d\n",
+ stats.command_stats[KEYD_CMD_GETTEXT]);
+ printf(" Get full keyid: %d\n",
+ stats.command_stats[KEYD_CMD_GETFULLKEYID]);
+ printf(" Iterate all keys: %d\n",
+ stats.command_stats[KEYD_CMD_KEYITER]);
+ printf(" Close: %d\n",
+ stats.command_stats[KEYD_CMD_CLOSE]);
+ printf(" Quit: %d\n", stats.command_stats[KEYD_CMD_QUIT]);
+ printf(" Get statistics: %d\n",
+ stats.command_stats[KEYD_CMD_STATS]);
+ printf(" Unknown: %d\n",
+ stats.command_stats[KEYD_CMD_UNKNOWN]);
+
return;
}