From a551776cf06d335920c87a5f2f30ab9336da9ae6 Mon Sep 17 00:00:00 2001 From: Ron Pedde Date: Fri, 26 Mar 2004 20:59:28 +0000 Subject: [PATCH] Start adding some stats stuff --- src/configfile.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ src/daapd.h | 15 +++++++------ src/main.c | 4 +++- 3 files changed, 66 insertions(+), 8 deletions(-) diff --git a/src/configfile.c b/src/configfile.c index 191ee68c..c42cf990 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -508,6 +508,8 @@ void config_emit_int(WS_CONNINFO *pwsc, void *value, char *arg) { void config_emit_service_status(WS_CONNINFO *pwsc, void *value, char *arg) { int mdns_running; char *html; + char buf[256]; + int r_days, r_hours, r_mins, r_secs; ws_writefd(pwsc,""); ws_writefd(pwsc,"\n"); @@ -536,6 +538,59 @@ void config_emit_service_status(WS_CONNINFO *pwsc, void *value, char *arg) { } ws_writefd(pwsc,"
ServiceStatusControl
\n"); + + ws_writefd(pwsc,"\n"); + ws_writefd(pwsc,"\n"); + ws_writefd(pwsc," \n"); + + r_secs=time(NULL)-config.stats.start_time; + + r_days=r_secs/(3600 * 24); + r_secs -= ((3600 * 24) * r_days); + + r_hours=r_secs/3600; + r_secs -= (3600 * r_hours); + + r_mins=r_secs/60; + r_secs -= 60 * r_mins; + + memset(buf,0x0,sizeof(buf)); + if(r_days) + sprintf((char*)&buf[strlen(buf)],"%d day%s, ", r_days, + r_days == 1 ? "" : "s"); + + if(r_days || r_hours) + sprintf((char*)&buf[strlen(buf)],"%d hour%s, ", r_hours, + r_hours == 1 ? "" : "s"); + + if(r_days || r_hours || r_mins) + sprintf((char*)&buf[strlen(buf)],"%d minute%s, ", r_mins, + r_mins == 1 ? "" : "s"); + + sprintf((char*)&buf[strlen(buf)],"%d second%s ", r_secs, + r_secs == 1 ? "" : "s"); + + ws_writefd(pwsc," \n",buf); + ws_writefd(pwsc,"\n"); + + ws_writefd(pwsc,"\n"); + ws_writefd(pwsc," \n"); + ws_writefd(pwsc," \n",db_get_song_count()); + ws_writefd(pwsc,"\n"); + + ws_writefd(pwsc,"\n"); + ws_writefd(pwsc," \n"); + ws_writefd(pwsc," \n",config.stats.songs_served); + ws_writefd(pwsc,"\n"); + + /* + ws_writefd(pwsc,"\n"); + ws_writefd(pwsc," \n"); + ws_writefd(pwsc," \n",config.stats.songs_served); + ws_writefd(pwsc,"\n"); + */ + + ws_writefd(pwsc,"
Uptime%s
Songs%d
Songs Served%d
Bytes Served%d
\n"); } /* diff --git a/src/daapd.h b/src/daapd.h index c94520d5..5ad214cb 100644 --- a/src/daapd.h +++ b/src/daapd.h @@ -22,12 +22,13 @@ #ifndef _DAAPD_H_ #define _DAAPD_H_ -typedef struct tag_songentry { - int index; - char *file; - - struct tag_songentry *next; -} SONGENTRY; +typedef struct tag_stats { + time_t start_time; + int songs_served; + + unsigned int gb_served; + unsigned int bytes_served; +} STATS; typedef struct tag_config { int use_mdns; @@ -43,7 +44,7 @@ typedef struct tag_config { char *runas; char *dbdir; char *extensions; - SONGENTRY songlist; + STATS stats; } CONFIG; extern CONFIG config; diff --git a/src/main.c b/src/main.c index 59a722af..e8f00806 100644 --- a/src/main.c +++ b/src/main.c @@ -275,6 +275,8 @@ void daap_handler(WS_CONNINFO *pwsc) { config_set_status(pwsc,session_id,"Streaming file '%s'",pmp3->fname); DPRINTF(ERR_INFO,"Streaming %s\n",pmp3->fname); + config.stats.songs_served++; /* FIXME: remove stat races */ + if(offset) { DPRINTF(ERR_INFO,"Seeking to offset %d\n",offset); lseek(file_fd,offset,SEEK_SET); @@ -462,7 +464,7 @@ int main(int argc, char *argv[]) { /* read the configfile, if specified, otherwise * try defaults */ - start_time=time(NULL); + config.stats.start_time=start_time=time(NULL); if(config_read(configfile)) { perror("config_read");