/// <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> /// 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> /// 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>"); }