diff --git a/src/Makefile.in b/src/Makefile.in index 3e118cd8..f87586a3 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -33,7 +33,7 @@ MAKE = `which make` INSTALL = @INSTALL@ -all: libpiler.a piler pilerconf pilerget pileraget pilerimport pilerexport reindex test piler-smtp +all: libpiler.a piler pilerconf pilerget pileraget pilerimport pilerexport reindex test stats piler-smtp install: install-piler @@ -71,6 +71,9 @@ reindex: reindex.c libpiler.a test: test.c libpiler.a $(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o pilertest $< -lpiler $(LIBS) $(LIBDIR) @LDFLAGS@ +stats: stats.c libpiler.a + $(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o pilerstats $< -lpiler $(LIBS) $(LIBDIR) @LDFLAGS@ + %.o: $(srcdir)/%.c $(CC) $(CFLAGS) -fPIC $(INCDIR) $(DEFS) -c $< -o $@ @@ -90,9 +93,10 @@ install-piler: $(INSTALL) -m 6755 -o $(RUNNING_USER) -g $(RUNNING_GROUP) pilerexport $(DESTDIR)$(bindir) $(INSTALL) -m 6755 -o $(RUNNING_USER) -g $(RUNNING_GROUP) reindex $(DESTDIR)$(bindir) $(INSTALL) -m 6755 -o $(RUNNING_USER) -g $(RUNNING_GROUP) pilertest $(DESTDIR)$(bindir) + $(INSTALL) -m 6755 -o $(RUNNING_USER) -g $(RUNNING_GROUP) pilerstats $(DESTDIR)$(bindir) clean: - rm -f *.o *.a libpiler.so* piler pilerconf pilerget pileraget pilerimport pilerexport pilertest reindex piler-smtp + rm -f *.o *.a libpiler.so* piler pilerconf pilerget pileraget pilerimport pilerexport pilertest pilerstats reindex piler-smtp distclean: clean rm -f Makefile diff --git a/src/config.h b/src/config.h index 562e810d..75aba5fe 100644 --- a/src/config.h +++ b/src/config.h @@ -11,7 +11,7 @@ #define VERSION "1.3.3" -#define BUILD 987 +#define BUILD 988 #define HOSTID "mailarchiver" diff --git a/src/stats.c b/src/stats.c new file mode 100644 index 00000000..9ee50ad1 --- /dev/null +++ b/src/stats.c @@ -0,0 +1,109 @@ +/* + * stats.c, SJ + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +extern char *optarg; +extern int optind; + + +int query_counters(struct session_data *sdata, uint64 *rcvd, uint64 *size, uint64 *ssize){ + int rc=ERR; + struct sql sql; + + if(prepare_sql_statement(sdata, &sql, "select rcvd, size, stored_size from counter") == ERR) return rc; + + p_bind_init(&sql); + + if(p_exec_stmt(sdata, &sql) == OK){ + p_bind_init(&sql); + + sql.sql[sql.pos] = (char *)rcvd; sql.type[sql.pos] = TYPE_LONGLONG; sql.len[sql.pos] = sizeof(uint64); sql.pos++; + sql.sql[sql.pos] = (char *)size; sql.type[sql.pos] = TYPE_LONGLONG; sql.len[sql.pos] = sizeof(uint64); sql.pos++; + sql.sql[sql.pos] = (char *)ssize; sql.type[sql.pos] = TYPE_LONGLONG; sql.len[sql.pos] = sizeof(uint64); sql.pos++; + + p_store_results(&sql); + + if(p_fetch_results(&sql) == OK) rc = OK; + + p_free_results(&sql); + } + + close_prepared_statement(&sql); + + return rc; +} + + +uint64 query_sphinx(struct session_data *sdata){ + uint64 sphx=0; + MYSQL_RES *result; + MYSQL_ROW row; + + p_query(sdata, "SHOW STATUS LIKE 'queries'"); + + result = mysql_store_result(&(sdata->mysql)); + if(result){ + row = mysql_fetch_row(result); + + if(row){ + if(mysql_num_fields(result) == 2){ + sphx = strtoull(row[1], NULL, 10); + } + } + + mysql_free_result(result); + } + + return sphx; +} + + +int main(int argc, char **argv){ + uint64 rcvd=0, size=0, ssize=0, sphx=0; + struct session_data sdata; + struct config cfg; + char *configfile=CONFIG_FILE; + + srand(getpid()); + + (void) openlog("pilerstat", LOG_PID, LOG_MAIL); + + cfg = read_config(configfile); + + if(open_database(&sdata, &cfg) == ERR) return 0; + + setlocale(LC_CTYPE, cfg.locale); + + query_counters(&sdata, &rcvd, &size, &ssize); + + close_database(&sdata); + + + cfg.mysqlsocket[0] = '\0'; + snprintf(cfg.mysqlhost, MAXVAL-2, "127.0.0.1"); + cfg.mysqlport = 9306; + + if(open_database(&sdata, &cfg) == ERR) return 0; + + sphx = query_sphinx(&sdata); + + close_database(&sdata); + + printf("{\n\trcvd=%llu,\n\tsize=%llu,\n\tssize=%llu,\n\tsphx=%llu\n}\n", rcvd, size, ssize, sphx); + + return 0; +}