From cbe6ddd4007d29b29740b8809db84b1c08c076d5 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Mon, 17 Nov 2003 12:57:20 +0000 Subject: [PATCH] Addes writerel command. --- apps/silcmap/silcmap.c | 2 + apps/silcmap/silcmap.conf | 12 +++- apps/silcmap/silcmap.h | 4 ++ apps/silcmap/silcmap_client.c | 8 +++ apps/silcmap/silcmap_command.c | 41 ++++++++++++ apps/silcmap/silcmap_html.c | 111 +++++++++++++++++++++++++++++++++ 6 files changed, 177 insertions(+), 1 deletion(-) diff --git a/apps/silcmap/silcmap.c b/apps/silcmap/silcmap.c index 505a1357..6d292b13 100644 --- a/apps/silcmap/silcmap.c +++ b/apps/silcmap/silcmap.c @@ -142,6 +142,8 @@ void silc_map_free(SilcMap map) silc_free(map->writemap.filename); silc_free(map->writehtml.filename); silc_free(map->writehtml.text); + silc_free(map->writerel.filename); + silc_free(map->writerel.text); silc_free(map); } diff --git a/apps/silcmap/silcmap.conf b/apps/silcmap/silcmap.conf index a9155717..aa7ba583 100644 --- a/apps/silcmap/silcmap.conf +++ b/apps/silcmap/silcmap.conf @@ -34,9 +34,19 @@ # based on the hostname of the server. The index HTML file # will include list of the servers. The generated HTML files # are quite raw and are intended to be embedded into user's -# own website. If is defined the it is used as the +# own website. If is defined it is used as the # CSS class in the created HTML page. # +# Command : writerel { filename = ; class = }; +# Example : writerel { filename = "reliability.html"; }; +# Description : Writes a reliability graph of the servers. When SILC Map +# is run several times the uptime statistics of the servers +# that measure the reliability of the servers are drawn into +# the reliability graph. The uptime statistics will be +# saved into corresponding server filename. If +# is defined it is used as the CSS class in the created HTML +# file. +# # Command : cut { lat = ; lon = ; width = ; # height = ; filename = ; }; # Example : cut { lat = "20"; lon = "5"; width = "1000"; height = "700"; diff --git a/apps/silcmap/silcmap.h b/apps/silcmap/silcmap.h index 7f63318a..b5fe8dd5 100644 --- a/apps/silcmap/silcmap.h +++ b/apps/silcmap/silcmap.h @@ -56,6 +56,7 @@ typedef struct { unsigned int writemap : 1; unsigned int writehtml : 1; unsigned int writemaphtml : 1; + unsigned int writerel : 1; unsigned int cut : 1; unsigned int draw_line : 1; unsigned int draw_text : 1; @@ -83,6 +84,7 @@ typedef struct { /* Output methods */ SilcMapCommandStruct writemap; SilcMapCommandStruct writehtml; + SilcMapCommandStruct writerel; SilcMapCommandStruct *writemaphtml; SilcMapCommandStruct *cut; SilcUInt32 writemaphtml_count; @@ -204,5 +206,7 @@ bool silc_map_load_font(SilcMap map, const char *filename); bool silc_map_writehtml(SilcMap map, SilcMapConnection mapconn); bool silc_map_writehtml_index(SilcMap map); bool silc_map_writemaphtml(SilcMap map); +bool silc_map_writerel(SilcMap map, SilcMapConnection mapconn); +bool silc_map_writerelhtml(SilcMap map); #endif /* SILCMAP_H */ diff --git a/apps/silcmap/silcmap_client.c b/apps/silcmap/silcmap_client.c index b97bf77e..7aa6677b 100644 --- a/apps/silcmap/silcmap_client.c +++ b/apps/silcmap/silcmap_client.c @@ -125,6 +125,10 @@ void silc_map_process_data(SilcMap map, SilcMapConnection mapconn) if (map->writehtml.writehtml) silc_map_writehtml(map, mapconn); + /* Write uptime reliability data */ + if (map->writerel.writerel) + silc_map_writerel(map, mapconn); + /* If this was last connection, we are done and ready to quit. */ if (map->conn_num == map->conns_num) { SILC_LOG_DEBUG(("All connections processed")); @@ -147,6 +151,10 @@ void silc_map_process_data(SilcMap map, SilcMapConnection mapconn) /* Write the HTML map file(s) */ silc_map_writemaphtml(map); + /* Write uptime reliability graph */ + if (map->writerel.writerel) + silc_map_writerelhtml(map); + /* Schedule to stop */ silc_schedule_task_add(map->client->schedule, 0, silc_map_process_done, map, 0, 1, diff --git a/apps/silcmap/silcmap_command.c b/apps/silcmap/silcmap_command.c index 1cc421da..2fcecaee 100644 --- a/apps/silcmap/silcmap_command.c +++ b/apps/silcmap/silcmap_command.c @@ -28,6 +28,7 @@ SILC_CONFIG_CALLBACK(silc_map_cmd_loadmap); SILC_CONFIG_CALLBACK(silc_map_cmd_writemap); SILC_CONFIG_CALLBACK(silc_map_cmd_writemaphtml); SILC_CONFIG_CALLBACK(silc_map_cmd_writehtml); +SILC_CONFIG_CALLBACK(silc_map_cmd_writerel); SILC_CONFIG_CALLBACK(silc_map_cmd_cut); SILC_CONFIG_CALLBACK(silc_map_cmd_rectangle); SILC_CONFIG_CALLBACK(silc_map_cmd_circle); @@ -62,6 +63,13 @@ static const SilcConfigTable silc_map_table_writehtml[] = { NULL }, }; +static const SilcConfigTable silc_map_table_writerel[] = +{ + { "filename", SILC_CONFIG_ARG_STR, silc_map_cmd_writerel, NULL }, + { "class", SILC_CONFIG_ARG_STRE, silc_map_cmd_writerel, NULL }, + { NULL }, +}; + static const SilcConfigTable silc_map_table_cut[] = { { "lat", SILC_CONFIG_ARG_STR, silc_map_cmd_cut, NULL }, @@ -183,6 +191,8 @@ static const SilcConfigTable silc_map_table_main[] = silc_map_cmd_writemaphtml, silc_map_table_writemaphtml }, { "writehtml", SILC_CONFIG_ARG_BLOCK, silc_map_cmd_writehtml, silc_map_table_writehtml }, + { "writerel", SILC_CONFIG_ARG_BLOCK, + silc_map_cmd_writerel, silc_map_table_writerel }, { "cut", SILC_CONFIG_ARG_BLOCK, silc_map_cmd_cut, silc_map_table_cut }, { "rectangle", SILC_CONFIG_ARG_BLOCK, @@ -498,6 +508,37 @@ SILC_CONFIG_CALLBACK(silc_map_cmd_writehtml) return retval; } +/* Command: writerel, writes the uptime reliability graph. */ + +SILC_CONFIG_CALLBACK(silc_map_cmd_writerel) +{ + SilcMap map = context; + int retval = SILC_CONFIG_OK; + + if (type == SILC_CONFIG_ARG_BLOCK) { + if (!filename) + return SILC_CONFIG_EMISSFIELDS; + + SILC_LOG_DEBUG(("writerel: file: %s", filename)); + + /* Will generate uptime reliability graph */ + map->writerel.filename = filename; + map->writerel.text = text; /* class */ + map->writerel.writerel = TRUE; + filename = text = NULL; + + return retval; + } + if (!strcmp(name, "filename")) + filename = strdup((char *)val); + else if (!strcmp(name, "class")) + text = strdup((char *)val); + else + retval = SILC_CONFIG_ESILENT; + + return retval; +} + /* Command: cut, cut's a specified area from the map. */ SILC_CONFIG_CALLBACK(silc_map_cmd_cut) diff --git a/apps/silcmap/silcmap_html.c b/apps/silcmap/silcmap_html.c index 6e3c8577..5c1aa233 100644 --- a/apps/silcmap/silcmap_html.c +++ b/apps/silcmap/silcmap_html.c @@ -460,3 +460,114 @@ bool silc_map_writemaphtml(SilcMap map) return TRUE; } + +/* Writes the server uptime reliablity data file. */ + +bool silc_map_writerel(SilcMap map, SilcMapConnection mapconn) +{ + FILE *fp; + int try = 0, success = 0; + char f[256], *hostname; + + /* Generate data filename */ + memset(f, 0, sizeof(f)); + silc_dlist_start(mapconn->hostnames); + hostname = silc_dlist_get(mapconn->hostnames); + snprintf(f, sizeof(f) - 1, "%s_%d.rel", hostname, mapconn->port); + + /* Read the current data */ + fp = fopen(f, "r"); + if (fp) { + fscanf(fp, "%d:%d", &try, &success); + fclose(fp); + } + + /* Update the data */ + try++; + success = (mapconn->down == FALSE ? success + 1 : success); + + /* Write the data file */ + fp = fopen(f, "w+"); + if (!fp) { + fprintf(stderr, "Could not open file '%s'\n", map->writerel.filename); + return FALSE; + } + fprintf(fp, "%d:%d", try, success); + + fclose(fp); + return TRUE; +} + +/* Writes the servers' uptime reliability graph as HTML page. */ + +bool silc_map_writerelhtml(SilcMap map) +{ + SilcMapConnection mapconn; + char *hostname, *class; + FILE *fp, *dp; + + /* Open for writing */ + fp = fopen(map->writerel.filename, "w+"); + if (!fp) { + fprintf(stderr, "Could not open file '%s'\n", map->writerel.filename); + return FALSE; + } + + /* Produce the reliability graph as HTML file. */ + class = map->writerel.text ? map->writerel.text : "silcmap"; + + fprintf(fp, "\n"); + fprintf(fp, "
\n"); + fprintf(fp, "\n", class); + fprintf(fp, + "\n" + "\n" + "\n" + "\n", class, class); + + silc_dlist_start(map->conns); + while ((mapconn = silc_dlist_get(map->conns)) != SILC_LIST_END) { + char f[256]; + int try = 0, success = 0; + double rel = 0; + + silc_dlist_start(mapconn->hostnames); + hostname = silc_dlist_get(mapconn->hostnames); + + /* Get the data */ + memset(f, 0, sizeof(f)); + snprintf(f, sizeof(f) - 1, "%s_%d.rel", hostname, mapconn->port); + dp = fopen(f, "r"); + if (dp) { + fscanf(dp, "%d:%d", &try, &success); + fclose(dp); + } + + /* Count the reliability */ + if (try) + rel = ((double)success / (double)try) * (double)200.0; + + fprintf(fp, "\n"); + if (mapconn->html_url) + fprintf(fp, + "\n", class, mapconn->html_url, hostname); + else + fprintf(fp, + "\n", class, hostname, mapconn->port, hostname); + fprintf(fp, + "\n" + "\n" + "\n", + class, class, rel, 200 - rel, class, + ((double)success / (double)try) * (double)100.0); + } + + fprintf(fp, "
ServerReliability
 %s %s" + "" + "" + "" + "
%.2f%%

\n"); + + return TRUE; +} -- 2.24.0