~ubuntu-branches/ubuntu/raring/ntop/raring-proposed

« back to all changes in this revision

Viewing changes to graph.c

  • Committer: Package Import Robot
  • Author(s): Ludovico Cavedon
  • Date: 2012-06-27 00:24:42 UTC
  • mfrom: (1.1.7)
  • Revision ID: package-import@ubuntu.com-20120627002442-9ljq6fhjqzx9qsu6
Tags: 3:4.99.3+ndpi5517+dfsg1-1
* Imported Upstream version 4.99.3 and nDPI r5517.
* get-orig-source.sh: incude nDPI in the orig tarball.
* No longer suggest ntop-graphs and update NEWS about that.
* Update copyright for the new jqPlot library.
* Refresh patches.
* Enable hardening flags.
* Add install-jqplot.patch to install jqPlot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
 
48
48
  sendJSLibraries(1);
49
49
 
50
 
  sendString("<script type=\"text/javascript\">\n");
51
 
  sendString("     var chart;\n");
52
 
  sendString("  $(document).ready(function() {\n");
53
 
  sendString("      chart = new Highcharts.Chart({\n");
54
 
  sendString("  chart: {\n");
55
 
  sendString("    renderTo: 'container',\n");
56
 
  sendString("        plotBackgroundColor: null,\n");
57
 
  sendString("        plotBorderWidth: null,\n");
58
 
  sendString("        plotShadow: false\n");
59
 
  sendString("        },\n");
60
 
  sendString("      title: {\n");
61
 
  sendString("    text: '");
62
 
  sendString(title);
63
 
  sendString("'\n");
64
 
  sendString("        },\n");
65
 
  sendString("      tooltip: {\n");
66
 
  sendString("    formatter: function() {\n");
67
 
  sendString("        return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';\n");
68
 
  sendString("      }\n");
69
 
  sendString("    },\n");
70
 
  sendString("      plotOptions: {\n");
71
 
  sendString("    pie: {\n");
72
 
  sendString("      allowPointSelect: true,\n");
73
 
  sendString("          cursor: 'pointer',\n");
74
 
  sendString("          dataLabels: {\n");
75
 
  sendString("              enabled: true,\n");
76
 
  sendString("          },\n");
77
 
  sendString("          showInLegend: true\n");
78
 
  sendString("        }\n");
79
 
  sendString("    },\n");
80
 
  sendString("      series: [{\n");
81
 
  sendString("      type: 'pie',\n");
82
 
  sendString("          name: '");
83
 
  sendString(title);
84
 
  sendString("',\n");
85
 
  sendString("          data: [\n");  
 
50
  sendString("</head>\n<body>\n");
 
51
 
 
52
  sendString("\n\n<script type=\"text/javascript\">\n");
 
53
  sendString("var data = [\n");
86
54
}
87
55
 
88
56
/**********************************************************/
89
57
 
90
58
static void send_graph_footer(void) {
91
 
  sendString("                 ]\n");
92
 
  sendString("          }]\n");
93
 
  sendString("      });\n");
 
59
  sendString("$(document).ready(function(){\n\n");
 
60
  sendString("  $.jqplot('container', [data], \n");
 
61
  sendString("                       { \n");
 
62
  sendString("                       seriesDefaults: {\n");
 
63
  sendString("                         renderer: jQuery.jqplot.PieRenderer, \n");
 
64
  sendString("                             rendererOptions: {\n");
 
65
  sendString("                           showDataLabels: true\n");
 
66
  sendString("                               }\n");
 
67
  sendString("                         }, \n");
 
68
 
 
69
  /* Remove border around graphs */
 
70
  sendString(" grid: { \n");
 
71
  sendString("  gridLineColor: 'transparent', \n");
 
72
  sendString("      background: 'transparent', \n");
 
73
  sendString("      borderColor: 'transparent', \n");
 
74
  sendString("      borderWidth: '1', \n");
 
75
  sendString("      shadow: false \n");
 
76
  sendString("      }, \n");
 
77
 
 
78
  sendString("                           legend: { show:true, location: 'e' }\n");
 
79
  sendString("                       }\n");
 
80
  sendString("                       );\n");
94
81
  sendString("    });\n");
95
 
  sendString("  </script>\n");
 
82
  sendString("  </script>\n\n");
96
83
 
97
84
  sendString("<div id=\"container\" style=\"width: 350px; height: 320px; margin: 0 auto\"></div>\n");
 
85
  sendString("</body>\n</html>\n");
98
86
}
99
87
 
100
88
/**********************************************************/
125
113
    }
126
114
  }
127
115
 
 
116
  sendString("];\n");
128
117
  sendString("\n");
129
118
  send_graph_footer();
130
119
}
334
323
 
335
324
  for(i=0; i<myGlobals.l7.numSupportedProtocols; i++) {
336
325
    float val;
337
 
    
 
326
 
338
327
    val = (float)myGlobals.device[myGlobals.actualReportDeviceId].l7.protoTraffic[i];
339
328
    if(val > 0) {
340
329
      val = (float)((val * 100) / totTraffic);
344
333
      if(num == 20) break;
345
334
    }
346
335
  }
347
 
  
 
336
 
348
337
  if(num == 0) {
349
338
    traceEvent(CONST_TRACE_WARNING, "Graph failure (1)");
350
339
    return; /* TODO: this has to be handled better */
351
340
  }
352
 
  
 
341
 
353
342
  if(num == 1) p[0] = 100; /* just to be safe */
354
 
  
 
343
 
355
344
  build_pie("Service Distribution", num, p, lbl);
356
345
}
357
346
 
1009
998
 
1010
999
  sendJSLibraries(1);
1011
1000
 
 
1001
  sendString("</head>\n<body>\n");
 
1002
 
1012
1003
  sendString("<script type=\"text/javascript\">\n");
1013
 
  sendString("    var chart;\n");
1014
1004
  sendString("  $(document).ready(function() {\n");
1015
 
  sendString("      chart = new Highcharts.Chart({\n");
1016
 
  sendString("  chart: {\n");
1017
 
  sendString("    renderTo: 'container',\n");
1018
 
  sendString("        defaultSeriesType: 'bar'\n");
1019
 
  sendString("        },\n");
1020
 
  sendString("      title: {\n");
1021
 
  sendString("    text: 'Top Host Talkers'\n");
1022
 
  sendString("        },\n");
1023
 
  sendString("      xAxis: {\n");
1024
 
  sendString("    categories: [\n");
 
1005
 
 
1006
  sendString("    var ticks = [ ");
1025
1007
 
1026
1008
  for(i=0; i<num_datapoints; i++) {
1027
1009
    char buf[32];
1031
1013
    sendString(buf);
1032
1014
  }
1033
1015
 
1034
 
  sendString("]\n");
1035
 
  sendString("        },\n");
1036
 
  sendString("      yAxis: {\n");
1037
 
  sendString("    min: 0,\n");
1038
 
  sendString("        title: {\n");
1039
 
  sendString("      text: 'Host Traffic %'\n");
1040
 
  sendString("          },\n");
1041
 
  sendString("        stackLabels: {\n");
1042
 
  sendString("      enabled: true,\n");
1043
 
  sendString("          style: {\n");
1044
 
  sendString("        fontWeight: 'bold',\n");
1045
 
  sendString("            color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'\n");
1046
 
  sendString("            }\n");
1047
 
  sendString("      }\n");
1048
 
  sendString("    },\n");
1049
 
 
1050
 
#if 0
1051
 
  sendString("      legend: {\n");
1052
 
  sendString("    align: 'right',\n");
1053
 
  sendString("        x: -100,\n");
1054
 
  sendString("        verticalAlign: 'top',\n");
1055
 
  sendString("        y: 20,\n");
1056
 
  sendString("        floating: true,\n");
1057
 
  sendString("        backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColorSolid) || 'white',\n");
1058
 
  sendString("        borderColor: '#CCC',\n");
1059
 
  sendString("        borderWidth: 1,\n");
1060
 
  sendString("        shadow: false\n");
1061
 
  sendString("        },\n");
1062
 
#endif
1063
 
 
1064
 
  sendString("      tooltip: {\n");
1065
 
  sendString("    formatter: function() {\n");
1066
 
#if 0
1067
 
  sendString("        return '<b>'+ this.x +'</b><br/>'+\n");
1068
 
  sendString("           this.series.name +': '+ this.y +'<br/>'+\n");
1069
 
  sendString("          'Total: '+ this.point.stackTotal;\n");
1070
 
#else
1071
 
  sendString("        return ''+ this.series.name +': '+ Math.round(this.percentage) +'%';\n");
1072
 
#endif
1073
 
  sendString("      }\n");
1074
 
  sendString("    },\n");
1075
 
  sendString("      plotOptions: {\n");
1076
 
  sendString("    series: {\n");
1077
 
  sendString("      stacking: 'percent',\n");
1078
 
  sendString("          dataLabels: {\n");
1079
 
  sendString("        enabled: false,\n");
1080
 
  sendString("            color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white'\n");
1081
 
  sendString("            }\n");
1082
 
  sendString("      }\n");
1083
 
  sendString("    },\n");
1084
 
  sendString("      series: [\n");
 
1016
  sendString("];\n");
 
1017
  sendString("    var series = [ ");
1085
1018
 
1086
1019
  for(i=0; i<num_talkers; i++) {
1087
1020
    HostTraffic *el, tmpEl;
1088
1021
    char buf[LEN_GENERAL_WORK_BUFFER], *c;
1089
1022
 
1090
1023
    el = quickHostLink(talkers[i].hostSerial, myGlobals.actualReportDeviceId, &tmpEl);
1091
 
    
 
1024
 
1092
1025
    if((el->hostResolvedNameType == FLAG_HOST_SYM_ADDR_TYPE_NONE)
1093
1026
       || (el->hostResolvedName[0] == '\0') /* Safety check */
1094
1027
       ) {
1099
1032
    }
1100
1033
 
1101
1034
    c = (el->hostResolvedName[0] != '\0') ? el->hostResolvedName : el->hostNumIpAddress;
1102
 
    
 
1035
 
1103
1036
    if(el->hostResolvedName[0] != '\0') {
1104
1037
      c = el->hostResolvedName, j = 0;
1105
1038
 
1108
1041
          c[j] = '\0';
1109
1042
          break;
1110
1043
        }
1111
 
        
 
1044
 
1112
1045
        j++;
1113
1046
      }
1114
1047
    } else
1115
1048
      c = el->hostNumIpAddress;
1116
 
    
1117
 
    safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "\t\t{\n\t\tname: '%s',\n", c);
1118
 
                  
1119
 
    sendString(buf);
1120
 
 
1121
 
    sendString("\t\t\tdata: [\n");
 
1049
 
 
1050
    safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "{ label: '%s'}, ", c);
 
1051
    sendString(buf);
 
1052
  }
 
1053
  sendString("];\n\n");
 
1054
 
 
1055
  for(i=0; i<num_talkers; i++) {
 
1056
    char buf[64];
 
1057
 
 
1058
    safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "var data%d =  [ ", i);
 
1059
    sendString(buf);
 
1060
 
1122
1061
    for(j=0; j<num_datapoints; j++) {
1123
1062
 
1124
1063
      if(j > 0) sendString(", ");
1126
1065
      sendString(buf);
1127
1066
    }
1128
1067
 
1129
 
    sendString("]\n\t\t},\n");
1130
 
  }
1131
 
 
1132
 
  sendString("                 ]\n");
 
1068
    sendString("];\n");
 
1069
  }
 
1070
 
 
1071
  sendString("        $.jqplot('container', [ ");
 
1072
  for(i=0; i<num_talkers; i++) {
 
1073
    char buf[32];
 
1074
 
 
1075
    if(i > 0) sendString(", ");
 
1076
    safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "data%d", i);
 
1077
    sendString(buf);
 
1078
  }
 
1079
 
 
1080
  sendString("   ], {\n");
 
1081
  sendString("   animate: !$.jqplot.use_excanvas,\n");
 
1082
  sendString("            stackSeries: true,\n");
 
1083
  //  sendString("            title : 'Top Host Talkers',\n");
 
1084
  sendString("            seriesDefaults:{\n");
 
1085
  sendString("                renderer:$.jqplot.BarRenderer,\n");
 
1086
  sendString("\n");
 
1087
  sendString("            },\n");
 
1088
 
 
1089
  sendString(" grid: { \n");
 
1090
  //  sendString("  gridLineColor: 'transparent', \n");
 
1091
  //  sendString("      background: 'transparent', \n");
 
1092
  sendString("      borderColor: 'transparent', \n");
 
1093
  sendString("      borderWidth: '1', \n");
 
1094
  sendString("      shadow: false \n");
 
1095
  sendString("  }, \n");
 
1096
 
 
1097
 
 
1098
  sendString("            axes: {\n");
 
1099
  sendString("                xaxis: {\n");
 
1100
  sendString("                    renderer: $.jqplot.CategoryAxisRenderer,\n");
 
1101
  sendString("                    ticks: ticks\n");
 
1102
  sendString("                }\n");
 
1103
  sendString("            },\n");
 
1104
  sendString("            series: series,\n");
 
1105
  sendString("            axesDefaults: { showTickMarks: false },\n");
 
1106
  sendString("            legend: {\n");
 
1107
  sendString("                show: true,\n");
 
1108
  sendString("                location: 'e',\n");
 
1109
  sendString("                placement: 'outside'\n");
 
1110
  sendString("      }\n");
 
1111
 
 
1112
  sendString("  });\n");
 
1113
  sendString("});\n");
 
1114
  sendString("</script>\n");
 
1115
 
 
1116
  sendString("<div id=\"container\" align=left style=\"width: 800px; margin: 0 auto\"></div>\n");
 
1117
}
 
1118
 
 
1119
/* ************************ */
 
1120
 
 
1121
void drawThroughputMeter() {
 
1122
  char buf[256];
 
1123
 
 
1124
  sendString("<HTML>\n"
 
1125
             "<HEAD>\n"
 
1126
             "<META HTTP-EQUIV=REFRESH CONTENT=120>\n"
 
1127
             "<META HTTP-EQUIV=Pragma CONTENT=no-cache>\n"
 
1128
             "<META HTTP-EQUIV=Cache-Control CONTENT=no-cache>\n");
 
1129
 
 
1130
  sendJSLibraries(1);
 
1131
 
 
1132
  sendString("</head>\n<body>\n");
 
1133
 
 
1134
  sendString("<script type=\"text/javascript\">\n");
 
1135
  sendString("  $(document).ready(function() {\n");
 
1136
  sendString("    s1 = [\n");
 
1137
  safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%.1f", myGlobals.device[myGlobals.actualReportDeviceId].actualThpt); sendString(buf);
 
1138
  sendString("];\n");
 
1139
      
 
1140
  sendString("    $.jqplot('netspeed',[s1],{\n");
 
1141
  sendString("      seriesDefaults: {\n");
 
1142
  sendString("        renderer: $.jqplot.MeterGaugeRenderer,\n");
 
1143
  sendString("            rendererOptions: {\n");
 
1144
  sendString("            showTickLabels: false,\n");
 
1145
  sendString("          min: 0,\n");
 
1146
  sendString("              max: ");
 
1147
  safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%.1f,\n",
 
1148
                myGlobals.device[myGlobals.actualReportDeviceId].peakThroughput); sendString(buf);
 
1149
  sendString("              intervals:[");
 
1150
  safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%.1f, %.1f, %.1f],\n", 
 
1151
                myGlobals.device[myGlobals.actualReportDeviceId].peakThroughput*0.33,
 
1152
                myGlobals.device[myGlobals.actualReportDeviceId].peakThroughput*0.75,
 
1153
                myGlobals.device[myGlobals.actualReportDeviceId].peakThroughput);
 
1154
  sendString(buf);
 
1155
  sendString("              intervalColors:['#66cc66', '#E7E658', '#cc6666']\n");
 
1156
  sendString("              }\n");
 
1157
  sendString("        }\n");
1133
1158
  sendString("      });\n");
1134
 
  sendString("    });\n");
1135
 
  sendString("  </script>\n");
1136
 
 
1137
 
  sendString("<div id=\"container\" style=\"width: 100%; height: 100%; margin: 0 auto\"></div>\n");
 
1159
  sendString("  });\n");
 
1160
 
 
1161
  sendString("</script>\n");
 
1162
 
 
1163
  sendString("<div id=\"netspeed\" style=\"align: center; width: 180px; height: 120px; margin: 0 auto\"></div>\n");
 
1164
  sendString("</body>\n</html>\n");
1138
1165
}
1139
 
 
1140
 
/* ************************ */