mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-11-07 23:51:59 +01:00
added pilerstats utility
Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
parent
7310552ffb
commit
6003e08060
@ -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
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
#define VERSION "1.3.3"
|
||||
|
||||
#define BUILD 987
|
||||
#define BUILD 988
|
||||
|
||||
#define HOSTID "mailarchiver"
|
||||
|
||||
|
109
src/stats.c
Normal file
109
src/stats.c
Normal file
@ -0,0 +1,109 @@
|
||||
/*
|
||||
* stats.c, SJ
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <locale.h>
|
||||
#include <syslog.h>
|
||||
#include <getopt.h>
|
||||
#include <piler.h>
|
||||
|
||||
|
||||
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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user