graph_reports.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <!DOCTYPE html>
  2. <html lang="es">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>Dashboard de Navegación</title>
  7. <script src="{{ url_for('static', filename='js/tailwindcss.js') }}"></script>
  8. <script src="{{ url_for('static', filename='js/chart.js') }}"></script>
  9. <script src="{{ url_for('static', filename='js/chartjs-plugin-datalabels.js') }}"></script>
  10. </head>
  11. <body class="bg-gray-100">
  12. <div class="container mx-auto px-4 py-8">
  13. <header class="mb-8">
  14. <h1 class="text-3xl font-bold text-gray-800">
  15. Dashboard de Navegación
  16. </h1>
  17. <div class="flex flex-wrap justify-between mt-4">
  18. <div
  19. class="bg-white p-4 rounded-lg shadow-md w-full md:w-auto mb-4 md:mb-0"
  20. >
  21. <h3 class="text-lg font-semibold text-gray-700">
  22. Usuarios Totales
  23. </h3>
  24. <p class="text-2xl font-bold text-blue-600">
  25. {{ metrics.total_stats.total_users }}
  26. </p>
  27. </div>
  28. <div
  29. class="bg-white p-4 rounded-lg shadow-md w-full md:w-auto mb-4 md:mb-0"
  30. >
  31. <h3 class="text-lg font-semibold text-gray-700">
  32. Registros de Log
  33. </h3>
  34. <p class="text-2xl font-bold text-green-600">
  35. {{ metrics.total_stats.total_log_entries }}
  36. </p>
  37. </div>
  38. <div
  39. class="bg-white p-4 rounded-lg shadow-md w-full md:w-auto mb-4 md:mb-0"
  40. >
  41. <h3 class="text-lg font-semibold text-gray-700">
  42. Datos Transmitidos
  43. </h3>
  44. <p class="text-2xl font-bold text-purple-600">
  45. {{ "%.2f"|format(metrics.total_stats.total_data_transmitted /
  46. (1024**3)) }} GB
  47. </p>
  48. </div>
  49. <div class="bg-white p-4 rounded-lg shadow-md w-full md:w-auto">
  50. <h3 class="text-lg font-semibold text-gray-700">Total Requests</h3>
  51. <p class="text-2xl font-bold text-orange-600">
  52. {{ metrics.total_stats.total_requests }}
  53. </p>
  54. </div>
  55. </div>
  56. </header>
  57. <div class="grid grid-cols-1 lg:grid-cols-2 gap-6 mb-8">
  58. <div class="bg-white p-6 rounded-lg shadow-md">
  59. <h2 class="text-xl font-bold mb-4 text-gray-800">
  60. Top 20 Usuarios por Actividad
  61. </h2>
  62. <div class="h-80">
  63. <canvas id="usersActivityChart"></canvas>
  64. </div>
  65. </div>
  66. <div class="bg-white p-6 rounded-lg shadow-md">
  67. <h2 class="text-xl font-bold mb-4 text-gray-800">
  68. Top 20 Usuarios por Datos Transmitidos
  69. </h2>
  70. <div class="h-80">
  71. <canvas id="usersDataChart"></canvas>
  72. </div>
  73. </div>
  74. </div>
  75. <div class="bg-white p-6 rounded-lg shadow-md mb-8">
  76. <h2 class="text-xl font-bold mb-4 text-gray-800">
  77. Distribución de Códigos HTTP
  78. </h2>
  79. <div class="h-96">
  80. <canvas id="httpCodesChart"></canvas>
  81. </div>
  82. </div>
  83. <div class="bg-white p-6 rounded-lg shadow-md mb-8">
  84. <h2 class="text-xl font-bold mb-4 text-gray-800">
  85. Top 20 Páginas Más Visitadas
  86. </h2>
  87. <div class="overflow-x-auto">
  88. <table class="min-w-full divide-y divide-gray-200">
  89. <thead class="bg-gray-50">
  90. <tr>
  91. <th
  92. class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
  93. >
  94. URL
  95. </th>
  96. <th
  97. class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
  98. >
  99. Total Requests
  100. </th>
  101. <th
  102. class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
  103. >
  104. Visitas Únicas
  105. </th>
  106. <th
  107. class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
  108. >
  109. Datos Transmitidos
  110. </th>
  111. </tr>
  112. </thead>
  113. <tbody class="bg-white divide-y divide-gray-200">
  114. {% for page in metrics.top_pages %}
  115. <tr class="hover:bg-gray-50">
  116. <td
  117. class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900 truncate max-w-xs"
  118. >
  119. {{ page.url }}
  120. </td>
  121. <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
  122. {{ page.total_requests }}
  123. </td>
  124. <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
  125. {{ page.unique_visits }}
  126. </td>
  127. <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
  128. {{ "%.2f"|format(page.total_data_bytes / (1024**2)) }} MB
  129. </td>
  130. </tr>
  131. {% endfor %}
  132. </tbody>
  133. </table>
  134. </div>
  135. </div>
  136. <div class="bg-white p-6 rounded-lg shadow-md">
  137. <h2 class="text-xl font-bold mb-4 text-gray-800">
  138. IPs Compartidas por Múltiples Usuarios
  139. </h2>
  140. <div class="overflow-x-auto">
  141. <table class="min-w-full divide-y divide-gray-200">
  142. <thead class="bg-gray-50">
  143. <tr>
  144. <th
  145. class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
  146. >
  147. IP
  148. </th>
  149. <th
  150. class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
  151. >
  152. Número de Usuarios
  153. </th>
  154. <th
  155. class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
  156. >
  157. Usuarios
  158. </th>
  159. </tr>
  160. </thead>
  161. <tbody class="bg-white divide-y divide-gray-200">
  162. {% for ip in metrics.users_per_ip %}
  163. <tr class="hover:bg-gray-50">
  164. <td
  165. class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900"
  166. >
  167. {{ ip.ip }}
  168. </td>
  169. <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
  170. {{ ip.user_count }}
  171. </td>
  172. <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
  173. {{ ip.usernames }}
  174. </td>
  175. </tr>
  176. {% endfor %}
  177. </tbody>
  178. </table>
  179. </div>
  180. </div>
  181. </div>
  182. <script>
  183. const chartColors = [
  184. '#3B82F6', '#10B981', '#F59E0B', '#EF4444', '#8B5CF6',
  185. '#EC4899', '#14B8A6', '#F97316', '#64748B', '#84CC16',
  186. '#06B6D4', '#D946EF', '#F43F5E', '#0EA5E9', '#22C55E',
  187. '#EAB308', '#F43F5E', '#8B5CF6', '#EC4899', '#14B8A6'
  188. ];
  189. const usersActivityCtx = document.getElementById('usersActivityChart').getContext('2d');
  190. new Chart(usersActivityCtx, {
  191. type: 'bar',
  192. data: {
  193. labels: {{ metrics.top_users_by_activity | map(attribute='username') | list | tojson }},
  194. datasets: [{
  195. label: 'Visitas',
  196. data: {{ metrics.top_users_by_activity | map(attribute='total_visits') | list | tojson }},
  197. backgroundColor: chartColors,
  198. borderColor: chartColors.map(color => color.replace('0.6', '1')),
  199. borderWidth: 1
  200. }]
  201. },
  202. options: {
  203. responsive: true,
  204. maintainAspectRatio: false,
  205. plugins: {
  206. legend: { display: false },
  207. tooltip: { mode: 'index', intersect: false },
  208. datalabels: { display: false }
  209. },
  210. scales: {
  211. y: { beginAtZero: true, title: { display: true, text: 'Número de Visitas' } },
  212. x: { ticks: { autoSkip: false } }
  213. }
  214. }
  215. });
  216. const usersDataCtx = document.getElementById('usersDataChart').getContext('2d');
  217. new Chart(usersDataCtx, {
  218. type: 'bar',
  219. data: {
  220. labels: {{ metrics.top_users_by_data_transferred | map(attribute='username') | list | tojson }},
  221. datasets: [{
  222. label: 'Datos (MB)',
  223. data: {{ metrics.top_users_by_data_transferred | map(attribute='total_data_bytes') |
  224. map('divide', 1048576) | list | tojson }},
  225. backgroundColor: chartColors,
  226. borderColor: chartColors.map(color => color.replace('0.6', '1')),
  227. borderWidth: 1
  228. }]
  229. },
  230. options: {
  231. responsive: true,
  232. maintainAspectRatio: false,
  233. plugins: {
  234. legend: { display: false },
  235. tooltip: {
  236. mode: 'index',
  237. intersect: false,
  238. callbacks: {
  239. label: function(context) {
  240. return `${context.dataset.label}: ${context.raw.toFixed(2)} MB`;
  241. }
  242. }
  243. },
  244. datalabels: { display: false }
  245. },
  246. scales: {
  247. y: {
  248. beginAtZero: true,
  249. title: { display: true, text: 'Datos Transmitidos (MB)' }
  250. },
  251. x: { ticks: { autoSkip: false } }
  252. }
  253. }
  254. });
  255. const httpCodesCtx = document.getElementById('httpCodesChart').getContext('2d');
  256. new Chart(httpCodesCtx, {
  257. type: 'pie',
  258. data: {
  259. labels: {{ metrics.http_response_distribution_chart.labels | tojson }},
  260. datasets: [{
  261. data: {{ metrics.http_response_distribution_chart.data | tojson }},
  262. backgroundColor: {{ metrics.http_response_distribution_chart.colors | tojson }},
  263. borderColor: '#fff',
  264. borderWidth: 1
  265. }]
  266. },
  267. options: {
  268. responsive: true,
  269. maintainAspectRatio: false,
  270. plugins: {
  271. legend: {
  272. position: 'right',
  273. labels: {
  274. font: {
  275. size: 12
  276. }
  277. }
  278. },
  279. tooltip: {
  280. callbacks: {
  281. label: function(context) {
  282. const total = context.dataset.data.reduce((a, b) => a + b, 0);
  283. const percentage = (context.raw / total * 100).toFixed(1);
  284. return `${context.label}: ${context.raw} (${percentage}%)`;
  285. }
  286. }
  287. },
  288. datalabels: {
  289. formatter: (value, ctx) => {
  290. const total = ctx.chart.data.datasets[0].data.reduce((a, b) => a + b, 0);
  291. const percentage = (value / total * 100).toFixed(1);
  292. return percentage > 3 ? `${percentage}%` : '';
  293. },
  294. color: '#fff',
  295. font: {
  296. weight: 'bold',
  297. size: 12
  298. }
  299. }
  300. }
  301. },
  302. plugins: [ChartDataLabels]
  303. });
  304. </script>
  305. </body>
  306. </html>