Addes writerel command.
authorPekka Riikonen <priikone@silcnet.org>
Mon, 17 Nov 2003 12:57:20 +0000 (12:57 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Mon, 17 Nov 2003 12:57:20 +0000 (12:57 +0000)
apps/silcmap/silcmap.c
apps/silcmap/silcmap.conf
apps/silcmap/silcmap.h
apps/silcmap/silcmap_client.c
apps/silcmap/silcmap_command.c
apps/silcmap/silcmap_html.c

index 505a1357f8afad7d8e8da4537ba9c8e8f94a0204..6d292b133ccb12a6cdb6ef6434c8455128b4bd71 100644 (file)
@@ -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);
 }
index a91557175dced065f9c8b4c79048aba4e2adc307..aa7ba583ef97d621a0c201c6199c5d7e4f3574aa 100644 (file)
 #               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";
index 7f63318a2ca87c4ec54af1a708acf92ce9507412..b5fe8dd55c50590fd6d419c2223a243e8e0f8432 100644 (file)
@@ -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 */
index b97bf77e481a5bf4b2542eb197e59c51fbcc6f0f..7aa6677b41307fa94976ecde6d3289f991263a0f 100644 (file)
@@ -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,
index 1cc421daa265e072d9daf17248817964b06f29d3..2fcecaee35aece0b53efe60674bba4dc2ed6e8d3 100644 (file)
@@ -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)
index 6e3c8577ddecaf6206f2764c62776fc203189165..5c1aa233aac54f15d8a31dcec618450cb290655c 100644 (file)
@@ -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, "<!-- 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\">&nbsp;<a href=\"%s\">%s</a></td>\n", class, mapconn->html_url, hostname);
+    else
+      fprintf(fp,
+             "<td align = \"center\" class=\"%s\">&nbsp;<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;
+}