/// <summary> /// Traite une requête HTTP. /// </summary> /// <param name="context">Context HTTP de la requête.</param> public void ProcessRequest(HttpContext context) { if (context == null) { throw new ArgumentNullException("context"); } Context requestContext = new Context(context, null); if (HtmlPageRenderer.IsCounterPage(requestContext.Content)) { ProcessPageRequest(context, requestContext); } else if (HtmlPageRenderer.IsExportPage(requestContext.Content)) { HtmlPageRenderer.SetHeaderCsv(context.Response); HtmlPageHelper.ToCsv( Analytics.Instance.GetDataBase(requestContext.ActionDataBase).HyperCube, requestContext, context.Response.Output); } else if (requestContext.Content != null) { ProcessContentRequest(context, requestContext); } else { // On ne sait pas traiter la requête context.Response.StatusCode = 500; } }
/// <summary> /// Crée un axe en HTML. /// </summary> /// <param name="hyperCube">Cube.</param> /// <param name="context">Contexte.</param> /// <param name="writer">Writer HTML.</param> /// <param name="requestName">Nom de la requête.</param> /// <param name="activeCounters">Compteurs actifs.</param> /// <param name="odd">Parité.</param> /// <param name="axis">Axe.</param> /// <param name="criteria">Critères.</param> /// <param name="cube">Cube.</param> private static void CreateHtmlAxis(IHyperCube hyperCube, Context context, HtmlTextWriter writer, string requestName, Dictionary <string, string> activeCounters, bool odd, string axis, CounterCubeCriteria criteria, ICube cube) { writer.Write(HtmlPageRenderer.Indent); writer.WriteLine("<tr " + (odd ? "class=\"odd\"" : string.Empty) + '>'); writer.Write(HtmlPageRenderer.Indent2); writer.Write("<td class=\"monitoring\">"); Context localContext = context.Zoom(hyperCube.Name, axis); writer.Write(HtmlPageRenderer.GetLink(localContext, axis, !axis.Equals(requestName))); writer.WriteLine("</td>"); writer.Write(HtmlPageRenderer.Indent2); writer.Write("<td class=\"monitoring\" align=\"right\">"); double total = cube.GetCounter(Analytics.ElapsedTime).GetValue(CounterStatType.Total); writer.Write(Convert.ToString(total, CultureInfo.CurrentCulture)); writer.WriteLine("</td>"); writer.Write(HtmlPageRenderer.Indent2); double avg = cube.GetCounter(Analytics.ElapsedTime).GetValue(CounterStatType.Avg); writer.Write("<td class=\"monitoring\" align=\"right\" " + GetHtmlStyle(1000, 10000, avg) + '>'); writer.Write(string.Format(CultureInfo.CurrentCulture, "{0:0.##}", avg)); writer.WriteLine("</td>"); writer.Write(HtmlPageRenderer.Indent2); writer.Write("<td class=\"monitoring\" align=\"right\">"); double hits = cube.GetCounter(Analytics.ElapsedTime).GetValue(CounterStatType.Hits); writer.Write(Convert.ToString(hits, CultureInfo.CurrentCulture)); writer.WriteLine("</td>"); writer.Write(HtmlPageRenderer.Indent2); PrintChartSparkLines(hyperCube, new CounterCubeCriteria(axis, TimeLevel.Minute), writer, localContext); double midValue; foreach (ICounterDefinition counterDefinition in hyperCube.AllDefinitions) { if (activeCounters.ContainsKey(counterDefinition.Code)) { ICounter counter = hyperCube.GetCube(criteria.CreateCubeKey(context.EndDate)).GetCounter(counterDefinition.Code); midValue = (counter != null) ? counter.GetValue(CounterStatType.Avg) : 0; writer.Write(HtmlPageRenderer.Indent2); writer.Write("<td class=\"monitoring\" align=\"right\" " + GetHtmlStyle(counterDefinition, midValue) + '>'); writer.Write(string.Format(CultureInfo.CurrentCulture, "{0:0.##}", midValue)); writer.WriteLine("</td>"); } } writer.Write(HtmlPageRenderer.Indent); writer.WriteLine("</tr>"); }
/// <summary> /// Réalise le rendu du résumé d'un hypercube. /// </summary> /// <param name="hyperCube">Hypercube à rendre.</param> /// <param name="context">Context courant de la requête.</param> /// <param name="writer">Writer HTML.</param> internal static void ToSummary(IHyperCube hyperCube, Context context, HtmlTextWriter writer) { if (writer == null) { throw new ArgumentNullException("writer"); } string requestName = context.GetRequestName(hyperCube.Name); writer.WriteLine("<ul>"); writer.Write("<li>"); writer.WriteLine(HtmlPageRenderer.GetLink(context, "Rafraîchir", true)); writer.WriteLine("</li>"); if (hyperCube.IsResetable) { writer.Write("<li>"); writer.WriteLine(HtmlPageRenderer.GetLink(context.Reset(hyperCube.Name), "Remettre à zéro", true)); writer.WriteLine("</li>"); } // Si on est sur une page locale on rend accès aux statistiques globales if (requestName != null) { writer.Write("<li>"); writer.WriteLine(HtmlPageRenderer.GetLink(context.Zoom(null, null), "Statistiques globales", true)); writer.WriteLine("</li>"); } writer.WriteLine("</ul>"); Context targetContext; if (requestName == null) { writer.Write("<h2>Statistiques globales</h2>"); targetContext = context; } else { writer.Write("<h2>Statistiques pour "); writer.Write(requestName); writer.WriteLine("</h2>"); targetContext = context.Zoom(null, null); } ICube cube = hyperCube.GetCube(new CounterCubeCriteria(requestName, TimeLevel.Hour).CreateCubeKey(context.EndDate)); if (cube != null) { // On affiche les données relative au cube bool link = requestName == null; // Si pas de request précisé on met les liens. RenderCube(hyperCube, cube, writer, link, targetContext); } }
/// <summary> /// Rend une statistique au format HTML. /// </summary> /// <param name="hyperCube">Hypercube contenant les données.</param> /// <param name="writer">Writer HTML.</param> /// <param name="counter">Compteur.</param> /// <param name="counterDefinition">Définition du compteur.</param> /// <param name="link">Indique si un lien doit être créé pour la selection des graphiques.</param> /// <param name="context">Contexte courant de la requête.</param> /// <param name="counterStatType">Type de statistique du compteur à rendre.</param> private static void StatToHtml(IHyperCube hyperCube, HtmlTextWriter writer, ICounter counter, ICounterDefinition counterDefinition, bool link, Context context, CounterStatType counterStatType) { writer.Write(HtmlPageRenderer.Indent2); writer.Write("<td class=\"monitoring\" align=\"right\" " + GetHtmlStyle(counterDefinition, counter.GetValue(counterStatType)) + '>'); writer.Write(string.Format(CultureInfo.CurrentCulture, "{0:0.##}", counter.GetValue(counterStatType))); writer.WriteLine("</td>"); if (counter.HasInfo(counterStatType)) { writer.Write(HtmlPageRenderer.Indent2); writer.Write("<td class=\"monitoring\">"); writer.Write(HtmlPageRenderer.GetLink(context.Zoom(hyperCube.Name, counter.GetInfo(counterStatType)), counter.GetInfo(counterStatType), link)); writer.WriteLine("</td>"); } }
/// <summary> /// Rendu html des managers. /// </summary> /// <param name="context">Context courant.</param> /// <param name="writer">Writer HTML.</param> private static void RenderManagers(Context context, HtmlTextWriter writer) { // Rendu du reset global. writer.Write("<div>"); writer.WriteLine("<ul>"); writer.Write("<li>"); writer.WriteLine(HtmlPageRenderer.GetLink(context.Reset("ALL"), "Tout remettre à zéro", true)); writer.WriteLine("</li>"); writer.WriteLine("</ul>"); writer.WriteLine("</div>"); writer.WriteLine("<div id=\"managers\">"); writer.WriteLine("</div>"); CurrentContext = context; foreach (IManager manager in ManagerContainer.Instance.ManagerList) { writer.WriteLine("<div id=\"manager\">"); IManagerDescription description = manager.Description; string name = (description != null) ? description.Name : manager.GetType().Name; string image = (description != null) ? description.Image : "misc.png"; writer.WriteLine("<h1 style=\"background-image: url('?CONTENT=img_manager&MON_ID=" + image + "');\">"); writer.WriteLine(name); writer.WriteLine("</h1>"); if (description != null) { writer.WriteLine("<div id=\"description\">"); // On ne passe pas le contexte opour ne pas créer une adhérence au niveau de l'API. description.ToHtml(writer); writer.WriteLine("</div>"); // description } writer.WriteLine("</div>"); // manager writer.WriteLine("</td>"); } writer.WriteLine("</div>"); }
/// <summary> /// Traite un requête pour retourner un page de résultat. /// </summary> /// <param name="context">Contexte HTTP.</param> /// <param name="requestContext">Contexte de la requête.</param> private static void ProcessPageRequest(HttpContext context, Context requestContext) { TextWriter textWriter; if (context == null) { textWriter = new StringWriter(CultureInfo.CurrentCulture); } else { textWriter = context.Response.Output; } using (HtmlTextWriter writer = new HtmlTextWriter(textWriter)) { // Page HTML des compteurs if (context != null) { HtmlPageRenderer.SetHeaderHtml(context.Response); } HtmlPageRenderer.HeadPage(writer); if ("RESET".Equals(requestContext.Action)) { Analytics.Instance.Reset(requestContext.ActionDataBase); writer.WriteLine("Les compteurs ont été remis à zéro.<br/>"); HtmlPageRenderer.DoEnd(requestContext, writer); } else if (requestContext.Action != null && requestContext.ListenerClassName != null) { HtmlPageRenderer.DoEnd(requestContext, writer); } else { HtmlPageRenderer.CounterPage(requestContext, writer); } writer.WriteLine("<!--"); writer.WriteLine(AnalyticsHandler.AssemblyVersion); writer.WriteLine("-->"); writer.WriteLine("</body></html>"); } }
/// <summary> /// Traite une requête pour du contenu attaché à la page. /// </summary> /// <param name="context">Contexte HTTP.</param> /// <param name="requestContext">Contexte de la requête.</param> private static void ProcessContentRequest(HttpContext context, Context requestContext) { if (requestContext.Content.Equals("img_manager")) { string mimeType = null; IManagerDescription managerDescription = null; foreach (IManager manager in ManagerContainer.Instance.ManagerList) { IManagerDescription description = manager.Description; if (description != null && description.Image != null && description.Image.Equals(requestContext.Id)) { managerDescription = description; break; } } if (managerDescription == null) { byte[] imageData = IR.Misc_png; mimeType = "image/png"; context.Response.ContentType = mimeType; context.Response.OutputStream.Write(imageData, 0, imageData.Length); } else { context.Response.ContentType = managerDescription.ImageMimeType; byte[] img = managerDescription.ImageData; context.Response.OutputStream.Write(img, 0, img.Length); } } else if (requestContext.Content.Equals("sparklines.png")) { context.Response.ContentType = "image/png"; CounterDataBase counterDataBase = Analytics.Instance.GetDataBase(requestContext.Id); HtmlPageRenderer.ToChart(counterDataBase.HyperCube, requestContext, context.Response.OutputStream); } else { throw new NotImplementedException(); } }
/// <summary> /// Réalise le rendu des labels. /// </summary> /// <param name="writer">Writer.</param> /// <param name="hyperCube">Hypercube contenant les valeurs.</param> /// <param name="context">Contexte de la requête.</param> /// <param name="requestName">Element demandé.</param> /// <returns>Liste des compteurs à rendre.</returns> private static Dictionary <string, string> RenderLabels(TextWriter writer, IHyperCube hyperCube, Context context, string requestName) { bool renderToHtml = writer is HtmlTextWriter; Dictionary <string, string> activeCounters = new Dictionary <string, string>(); ICube globalCube = hyperCube.GetCube(new CounterCubeCriteria(requestName, TimeLevel.Hour).CreateCubeKey(context.EndDate)); if (globalCube != null) { foreach (ICounterDefinition counterDefinition in hyperCube.AllDefinitions) { ICounter counter = globalCube.GetCounter(counterDefinition.Code); if (counter != null && counter.GetValue(CounterStatType.Hits) > 0) { activeCounters.Add(counterDefinition.Code, counterDefinition.Code); if (renderToHtml) { writer.Write(HtmlPageRenderer.Indent2); writer.Write("<th>"); string newSort = counterDefinition.Code; // Le lien n'est actif que si le tri n'est pas déjà effectué writer.Write(HtmlPageRenderer.GetLink(context.ChangeSort(newSort), counterDefinition.Label, !newSort.Equals(context.Sort))); writer.WriteLine("</th>"); } else { writer.Write(counterDefinition.Label); writer.Write(";"); } } } writer.WriteLine(); } return(activeCounters); }
/// <summary> /// Traite une requête HTTP. /// </summary> /// <param name="context">Context HTTP de la requête.</param> void IHttpHandler.ProcessRequest(HttpContext context) { if (context == null) { throw new ArgumentNullException("context"); } Context requestContext = new Context(context, null); if (requestContext.Content.Equals("sparklines.png")) { context.Response.ContentType = "image/png"; HtmlPageRenderer.ToChart(_databaseSet.GetDatabase(requestContext.Id), requestContext, context.Response.OutputStream); } else if (requestContext.Content.Equals("img_manager")) { foreach (IManagerDescription description in this.DatabaseDefinition.Values) { if (description.Image == requestContext.Id) { context.Response.ContentType = description.ImageMimeType; context.Response.OutputStream.Write(description.ImageData, 0, description.ImageData.Length); break; } } } else if (HtmlPageRenderer.IsExportPage(requestContext.Content)) { HtmlPageRenderer.SetHeaderCsv(context.Response); HtmlPageHelper.ToCsv(_databaseSet.GetDatabase(requestContext.ActionDataBase), requestContext, context.Response.Output); } else { throw new NotImplementedException(); } }
/// <summary> /// Extension de la méthode toString(). /// Permet à chaque Manager de présenter son propre état. /// </summary> /// <param name="writer">Writer HTML.</param> public void ToHtml(System.Web.UI.HtmlTextWriter writer) { HtmlPageRenderer.ToHtml(RequestHyperCube, writer); }
/// <summary> /// Réalise le rendu d'un hypercube axe par axe. /// </summary> /// <param name="hyperCube">Hypercube contenant les valeurs.</param> /// <param name="context">Contexte de la requête.</param> /// <param name="writer">Writer HTML.</param> internal static void ToTable(IHyperCube hyperCube, Context context, HtmlTextWriter writer) { string requestName = context.GetRequestName(hyperCube.Name); List <string> axisList = GetAllAxis(context.EndDate, hyperCube, context.Sort); writer.WriteLine("<h2>Nombre de requêtes (" + axisList.Count + ")</h2>"); writer.Write("Filtre : "); writer.Write(HtmlPageRenderer.GetLink(context.ChangeFiltre("NONE"), "aucun", !"NONE".Equals(context.Filtre))); writer.Write(", "); writer.Write(HtmlPageRenderer.GetLink(context.ChangeFiltre("WARNING"), "warning", !"WARNING".Equals(context.Filtre))); writer.Write(", "); writer.WriteLine(HtmlPageRenderer.GetLink(context.ChangeFiltre(null), "critique", context.Filtre != null)); writer.WriteLine(string.Empty); writer.WriteLine("<table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" width=\"100%\">"); writer.Write(HtmlPageRenderer.Indent); writer.WriteLine("<tr>"); writer.Write(HtmlPageRenderer.Indent2); writer.Write("<th>"); writer.Write(HtmlPageRenderer.GetLink(context.ChangeSort(null), "Requête", context.Sort != null)); writer.WriteLine("</th>"); writer.Write(HtmlPageRenderer.Indent2); writer.Write("<th>"); writer.Write(HtmlPageRenderer.GetLink(context.ChangeSort("TOTAL"), "total (ms)", !"TOTAL".Equals(context.Sort))); writer.WriteLine("</th>"); writer.Write(HtmlPageRenderer.Indent2); writer.Write("<th>"); writer.Write(HtmlPageRenderer.GetLink(context.ChangeSort(Analytics.ElapsedTime), "avg (ms)", !Analytics.ElapsedTime.Equals(context.Sort))); writer.WriteLine("</th>"); writer.Write(HtmlPageRenderer.Indent2); writer.Write("<th colspan='2'>"); writer.Write(HtmlPageRenderer.GetLink(context.ChangeSort("HITS"), "hits", !"HITS".Equals(context.Sort))); writer.WriteLine("</th>"); Dictionary <string, string> activeCounters = RenderLabels(writer, hyperCube, context, requestName); writer.Write(HtmlPageRenderer.Indent); writer.WriteLine("</tr>"); bool odd = true; foreach (string axis in axisList) { CounterCubeCriteria criteria = new CounterCubeCriteria(axis, TimeLevel.Hour); ICube cube = hyperCube.GetCube(criteria.CreateCubeKey(context.EndDate)); if (cube != null && IsShown(context.EndDate, context.Filtre, hyperCube, criteria)) { CreateHtmlAxis(hyperCube, context, writer, requestName, activeCounters, odd, axis, criteria, cube); odd = !odd; } } writer.WriteLine("</table>"); writer.WriteLine(string.Empty); writer.WriteLine("<a href=\"" + context.Export(hyperCube.Name).GetHandlerUrl() + "\">Exporter</a>"); }