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);
}
# 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 <class> is defined the it is used as the
+# own website. If <class> is defined it is used as the
# CSS class in the created HTML page.
#
+# Command : writerel { filename = <filename>; class = <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 <class>
+# is defined it is used as the CSS class in the created HTML
+# file.
+#
# Command : cut { lat = <lat>; lon = <lon>; width = <width>;
# height = <height>; filename = <filename>; };
# Example : cut { lat = "20"; lon = "5"; width = "1000"; height = "700";
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;
/* Output methods */
SilcMapCommandStruct writemap;
SilcMapCommandStruct writehtml;
+ SilcMapCommandStruct writerel;
SilcMapCommandStruct *writemaphtml;
SilcMapCommandStruct *cut;
SilcUInt32 writemaphtml_count;
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 */
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"));
/* 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,
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);
{ 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 },
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,
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)
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, "<!-- Automatically generated by silcmap --!>\n");
+ fprintf(fp, "<br />\n");
+ fprintf(fp, "<table cellspacing=\"0\" cellpadding=\"0\" "
+ "class=\"%s\" border=\"0\">\n", class);
+ fprintf(fp,
+ "<tr>\n"
+ "<td align=\"center\" class=\"%s_header\"><b>Server</b></td>\n"
+ "<td colspan=\"2\" align=\"center\" class=\"%s_header\"><b>Reliability</b></td>\n"
+ "</tr>\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, "<tr>\n");
+ if (mapconn->html_url)
+ fprintf(fp,
+ "<td align = \"center\" class=\"%s\"> <a href=\"%s\">%s</a></td>\n", class, mapconn->html_url, hostname);
+ else
+ fprintf(fp,
+ "<td align = \"center\" class=\"%s\"> <a href=\"%s_%d.html\">%s</a></td>\n", class, hostname, mapconn->port, hostname);
+ fprintf(fp,
+ "<td class=\"%s\" width=\"200\">"
+ "<table style=\"border: solid 1px black; width: 200px;\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"%s\"><tr>"
+ "<td style=\"width: %fpx; height: 10px;\" bgcolor=\"gray\"></td>"
+ "<td style=\"width: %fpx; height: 10px;\" bgcolor=\"white\"></td>"
+ "</tr></table></td>\n"
+ "<td class=\"%s\">%.2f%%</td>\n"
+ "</tr>\n",
+ class, class, rel, 200 - rel, class,
+ ((double)success / (double)try) * (double)100.0);
+ }
+
+ fprintf(fp, "</table><br />\n");
+
+ return TRUE;
+}