mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-11-08 02:11:59 +01:00
improved the sphinx stats
Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
parent
ce0bd526a6
commit
3f7fdb7f08
59
src/stats.c
59
src/stats.c
@ -19,8 +19,18 @@
|
|||||||
extern char *optarg;
|
extern char *optarg;
|
||||||
extern int optind;
|
extern int optind;
|
||||||
|
|
||||||
|
struct stats {
|
||||||
|
uint64 rcvd;
|
||||||
|
uint64 size;
|
||||||
|
uint64 ssize;
|
||||||
|
|
||||||
int query_counters(struct session_data *sdata, uint64 *rcvd, uint64 *size, uint64 *ssize){
|
uint64 sphx;
|
||||||
|
uint64 ram_bytes;
|
||||||
|
uint64 disk_bytes;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
int query_counters(struct session_data *sdata, struct stats *stats){
|
||||||
int rc=ERR;
|
int rc=ERR;
|
||||||
struct sql sql;
|
struct sql sql;
|
||||||
|
|
||||||
@ -31,9 +41,9 @@ int query_counters(struct session_data *sdata, uint64 *rcvd, uint64 *size, uint6
|
|||||||
if(p_exec_stmt(sdata, &sql) == OK){
|
if(p_exec_stmt(sdata, &sql) == OK){
|
||||||
p_bind_init(&sql);
|
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 *)&(stats->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 *)&(stats->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++;
|
sql.sql[sql.pos] = (char *)&(stats->ssize); sql.type[sql.pos] = TYPE_LONGLONG; sql.len[sql.pos] = sizeof(uint64); sql.pos++;
|
||||||
|
|
||||||
p_store_results(&sql);
|
p_store_results(&sql);
|
||||||
|
|
||||||
@ -48,8 +58,7 @@ int query_counters(struct session_data *sdata, uint64 *rcvd, uint64 *size, uint6
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint64 query_sphinx(struct session_data *sdata){
|
void sphinx_queries(struct session_data *sdata, struct stats *stats){
|
||||||
uint64 sphx=0;
|
|
||||||
MYSQL_RES *result;
|
MYSQL_RES *result;
|
||||||
MYSQL_ROW row;
|
MYSQL_ROW row;
|
||||||
|
|
||||||
@ -61,23 +70,47 @@ uint64 query_sphinx(struct session_data *sdata){
|
|||||||
|
|
||||||
if(row){
|
if(row){
|
||||||
if(mysql_num_fields(result) == 2){
|
if(mysql_num_fields(result) == 2){
|
||||||
sphx = strtoull(row[1], NULL, 10);
|
stats->sphx = strtoull(row[1], NULL, 10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mysql_free_result(result);
|
mysql_free_result(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
return sphx;
|
p_query(sdata, "SHOW INDEX main1 STATUS");
|
||||||
|
|
||||||
|
result = mysql_store_result(&(sdata->mysql));
|
||||||
|
if(result){
|
||||||
|
while((row = mysql_fetch_row(result))){
|
||||||
|
if(strcmp((char*)row[0], "ram_bytes") == 0) stats->ram_bytes = strtoull(row[1], NULL, 10);
|
||||||
|
if(strcmp((char*)row[0], "disk_bytes") == 0) stats->disk_bytes = strtoull(row[1], NULL, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
mysql_free_result(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void print_json_results(struct stats *stats){
|
||||||
|
printf("{\n");
|
||||||
|
printf("\t\"rcvd\": %llu,\n", stats->rcvd);
|
||||||
|
printf("\t\"size\": %llu,\n", stats->size);
|
||||||
|
printf("\t\"ssize\": %llu,\n", stats->ssize);
|
||||||
|
printf("\t\"sphx\": %llu,\n", stats->sphx);
|
||||||
|
printf("\t\"ram_bytes\": %llu,\n", stats->ram_bytes);
|
||||||
|
printf("\t\"disk_bytes\": %llu\n", stats->disk_bytes);
|
||||||
|
printf("}\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv){
|
int main(int argc, char **argv){
|
||||||
uint64 rcvd=0, size=0, ssize=0, sphx=0;
|
|
||||||
struct session_data sdata;
|
struct session_data sdata;
|
||||||
|
struct stats stats;
|
||||||
struct config cfg;
|
struct config cfg;
|
||||||
char *configfile=CONFIG_FILE;
|
char *configfile=CONFIG_FILE;
|
||||||
|
|
||||||
|
memset(&stats, 0, sizeof(stats));
|
||||||
|
|
||||||
srand(getpid());
|
srand(getpid());
|
||||||
|
|
||||||
(void) openlog("pilerstat", LOG_PID, LOG_MAIL);
|
(void) openlog("pilerstat", LOG_PID, LOG_MAIL);
|
||||||
@ -86,9 +119,7 @@ int main(int argc, char **argv){
|
|||||||
|
|
||||||
if(open_database(&sdata, &cfg) == ERR) return 0;
|
if(open_database(&sdata, &cfg) == ERR) return 0;
|
||||||
|
|
||||||
setlocale(LC_CTYPE, cfg.locale);
|
query_counters(&sdata, &stats);
|
||||||
|
|
||||||
query_counters(&sdata, &rcvd, &size, &ssize);
|
|
||||||
|
|
||||||
close_database(&sdata);
|
close_database(&sdata);
|
||||||
|
|
||||||
@ -99,11 +130,11 @@ int main(int argc, char **argv){
|
|||||||
|
|
||||||
if(open_database(&sdata, &cfg) == ERR) return 0;
|
if(open_database(&sdata, &cfg) == ERR) return 0;
|
||||||
|
|
||||||
sphx = query_sphinx(&sdata);
|
sphinx_queries(&sdata, &stats);
|
||||||
|
|
||||||
close_database(&sdata);
|
close_database(&sdata);
|
||||||
|
|
||||||
printf("{\n\t\"rcvd\": %llu,\n\t\"size\": %llu,\n\t\"ssize\": %llu,\n\t\"sphx\": %llu\n}\n", rcvd, size, ssize, sphx);
|
print_json_results(&stats);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user