@cryptotaxi247 / netdata-1 / commits / e68eba25b

support for single graphs

Costa Tsaousis (ktsaou) committed Mar 26, 2014 at 00:42 UTC e68eba25b16000718d84cc784a7d4b658b656bc9
2 files changed +64 -20
netdata.c
+57 -16
@@ -536,29 +536,47 @@ void rrd_stats_dimension_set(RRD_STATS *st, const char *id, void *data)
536 #define GROUP_AVERAGE 0
537 #define GROUP_MAX 1
538
539 -size_t rrd_stats_all_xml(char *buffer, size_t len)
539 +size_t rrd_stats_one_xml(RRD_STATS *st, char *buffer, size_t len)
540 {
541 - RRD_STATS *st;
541 size_t i = 0;
542 + if(i + 200 > len) return(0);
543 +
544 + i += sprintf(&buffer[i], "\t<graph>\n");
545 + i += sprintf(&buffer[i], "\t\t<id>%s</id>\n", st->id);
546 + i += sprintf(&buffer[i], "\t\t<name>%s</name>\n", st->name);
547 + i += sprintf(&buffer[i], "\t\t<type>%s</type>\n", st->type);
548 + i += sprintf(&buffer[i], "\t\t<title>%s%s</title>\n", st->title, st->name);
549 + i += sprintf(&buffer[i], "\t\t<vtitle>%s</vtitle>\n", st->vtitle);
550 + i += sprintf(&buffer[i], "\t\t<dataurl>/data/%s</dataurl>\n", st->name);
551 + i += sprintf(&buffer[i], "\t\t<entries>%ld</entries>\n", st->entries);
552 + i += sprintf(&buffer[i], "\t</graph>\n");
553
544 - i += sprintf(&buffer[i], "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<?xml-stylesheet type=\"text/xsl\" href=\"all.xsl\"?>\n\n<catalog>\n");
554 + return(i);
555 +}
556
546 - for(st = root; st ; st = st->next) {
547 - if(i+ 200 > len) break;
557 +#define RRD_GRAPH_XML_HEADER "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<?xml-stylesheet type=\"text/xsl\" href=\"/file/all.xsl\"?>\n\n<catalog>\n"
558 +#define RRD_GRAPH_XML_FOOTER "</catalog>\n"
559
549 - i += sprintf(&buffer[i], "\t<graph>\n");
550 - i += sprintf(&buffer[i], "\t\t<id>%s</id>\n", st->id);
551 - i += sprintf(&buffer[i], "\t\t<name>%s</name>\n", st->name);
552 - i += sprintf(&buffer[i], "\t\t<type>%s</type>\n", st->type);
553 - i += sprintf(&buffer[i], "\t\t<title>%s%s</title>\n", st->title, st->name);
554 - i += sprintf(&buffer[i], "\t\t<vtitle>%s</vtitle>\n", st->vtitle);
555 - i += sprintf(&buffer[i], "\t\t<dataurl>/data/%s</dataurl>\n", st->name);
556 - i += sprintf(&buffer[i], "\t\t<entries>%ld</entries>\n", st->entries);
557 - i += sprintf(&buffer[i], "\t</graph>\n");
558 - }
560 +size_t rrd_stats_graph_xml(RRD_STATS *st, char *buffer, size_t len)
561 +{
562 + size_t i = 0;
563 + i += sprintf(&buffer[i], RRD_GRAPH_XML_HEADER);
564 + i += rrd_stats_one_xml(st, &buffer[i], len - i);
565 + i += sprintf(&buffer[i], RRD_GRAPH_XML_FOOTER);
566 + return(i);
567 +}
568 +
569 +size_t rrd_stats_all_xml(char *buffer, size_t len)
570 +{
571 + size_t i = 0;
572 + RRD_STATS *st;
573
560 - i += sprintf(&buffer[i], "</catalog>\n");
574 + i += sprintf(&buffer[i], RRD_GRAPH_XML_HEADER);
575
576 + for(st = root; st ; st = st->next)
577 + i += rrd_stats_one_xml(st, &buffer[i], len - i);
578 +
579 + i += sprintf(&buffer[i], RRD_GRAPH_XML_FOOTER);
580 return(i);
581 }
582
@@ -866,6 +884,8 @@ int mysendfile(struct web_client *w, char *filename)
884 {
885 debug(D_WEB_CLIENT, "%llu: Looking for file '%s'...", w->id, filename);
886
887 + if(filename[0] == '/') filename = &filename[1];
888 +
889 if(strstr(filename, "/") != 0 || strstr(filename, "..") != 0) {
890 debug(D_WEB_CLIENT_ACCESS, "%llu: File '%s' is not acceptable.", w->id, filename);
891 w->data->bytes = sprintf(w->data->buffer, "File '%s' is not acceptable. Filenames cannot contain / or ..", filename);
@@ -1038,6 +1058,27 @@ void web_client_process(struct web_client *w)
1058 w->data->bytes = rrd_stats_json(st, w->data->buffer, w->data->size, lines, group_count, group_method);
1059 }
1060 }
1061 + else if(strcmp(tok, "graph") == 0) {
1062 + // the client is requesting an rrd graph
1063 +
1064 + // get the name of the data to show
1065 + tok = mystrsep(&url, "/?");
1066 + debug(D_WEB_CLIENT, "%llu: Searching for RRD data with name '%s'.", w->id, tok);
1067 +
1068 + // do we have such a data set?
1069 + RRD_STATS *st = rrd_stats_find_byname(tok);
1070 + if(!st) {
1071 + // we don't have it
1072 + code = 404;
1073 + w->data->bytes = sprintf(w->data->buffer, "There are not statistics for '%s'\r\n", tok);
1074 + }
1075 + else {
1076 + code = 200;
1077 + debug(D_WEB_CLIENT_ACCESS, "%llu: Sending %s.xml of RRD_STATS...", w->id, st->name);
1078 + w->data->contenttype = CT_TEXT_XML;
1079 + w->data->bytes = rrd_stats_graph_xml(st, w->data->buffer, w->data->size);
1080 + }
1081 + }
1082 else if(strcmp(tok, "mirror") == 0) {
1083 code = 200;
1084
netdata.js
+7 -4
@@ -99,12 +99,15 @@
99 if(width * height < charts.length) height++;
100 // console.log('final: width = ' + width + ', height = ' + height);
101
102 - if(width == 0) width = (document.documentElement.clientWidth - 40) / 2;
103 - if(width <= 10) width = (document.documentElement.clientWidth - 40) / width;
102 + ww = (window.innerWidth < document.documentElement.clientWidth)?window.innerWidth:document.documentElement.clientWidth;
103 + wh = (window.innerHeight < document.documentElement.clientHeight)?window.innerHeight:document.documentElement.clientHeight;
104 +
105 + if(width == 0) width = (ww - 40) / 2;
106 + if(width <= 10) width = (ww - 40) / width;
107 if(width < 200) width = 200;
108
106 - if(height == 0) height = (document.documentElement.clientHeight - 20) / 2;
107 - if(height <= 10) height = (document.documentElement.clientHeight - 20) / height;
109 + if(height == 0) height = (wh - 20) / 2;
110 + if(height <= 10) height = (wh - 20) / height;
111 if(height < 100) height = 100;
112
113 // console.log('width = ' + width + ', height = ' + height);