public override void GetMetrics(string apiKey, HttpClient client) { // Get the 'base' name of the monitor to make sure we requesting the correct monitor results. (drive_C becomes: drive) string baseMonitorName = Util.BaseMonitorName(this.Name, '_'); // Post the requests using (HttpResponseMessage response = client.Get("api?action=top" + baseMonitorName + "&apikey=" + apiKey + "&output=xml&detailedResults=true")) { response.EnsureStatusIsSuccessful(); String data = response.Content.ReadAsString(); XDocument xml = XDocument.Parse(data); IEnumerable<XElement> allMetrics = null; foreach (MonitorDefinition sm in monitorsDefinitions) { allMetrics = from metricNode in xml.Descendants("test") where (string)metricNode.Element("id") == this.Id select metricNode; foreach (XElement xe in allMetrics) foreach (string s in sm.Names) if (xe.Element(s) != null) { Metric m = new Metric(this); m.Name = s; m.Result = xe.Element(s).Value; m.Suffix = sm.Suffixes[sm.Names.IndexOf(s)]; this.AddMetric(m); } } } }
/// <summary> /// Get the results for the process monitor /// </summary> /// <param name="apiKey"></param> /// <param name="client"></param> public override void GetMetrics(string apiKey, HttpClient client) { base.GetMetrics(apiKey, client); using (HttpResponseMessage response = client.Get("api?action=topProcessByCPUUsage&limit=50&apikey=" + apiKey + "&output=xml&detailedResults=true")) { response.EnsureStatusIsSuccessful(); String data = response.Content.ReadAsString(); XDocument xml = XDocument.Parse(data); IEnumerable<XElement> allMetrics = null; foreach (MonitorDefinition sm in monitorsDefinitions) { // Query the xml data to retrieve each test result matching the ID of the current monitor allMetrics = from metricNode in xml.Descendants("test") where (string)metricNode.Element("id") == this.Id select metricNode; // Enumerate the metrics and store them in their own Metric object foreach (XElement xe in allMetrics) foreach (string s in sm.Names) if (xe.Element(s) != null) { Metric m = new Metric(this); m.Name = s; m.Result = xe.Element(s).Value; m.Suffix = sm.Suffixes[sm.Names.IndexOf(s)]; this.AddMetric(m); } } } }
/// <summary> /// Get the metrics for this monitor /// </summary> /// <param name="apiKey"></param> /// <param name="client"></param> public override void GetMetrics(string apiKey, HttpClient client) { base.GetMetrics(apiKey, client); // Get the serial date DateTime dt = new DateTime(); dt = DateTime.Now; // Send the http request using (HttpResponseMessage response = client.Get("api?action=testresult&apikey=" + apiKey + "&output=xml&testId=" + this.Id + "&day=" + dt.Day + "&month=" + dt.Month + "&year=" + dt.Year)) { response.EnsureStatusIsSuccessful(); String data = response.Content.ReadAsString(); XDocument xml = XDocument.Parse(data); IEnumerable<XElement> allMetrics = null; allMetrics = from metricNode in xml.Descendants("location") select metricNode; // Enumerate the metrics and store them in their own Metric object foreach (XElement xe in allMetrics) if (xe.Attribute("name") != null) { Metric m = new Metric(this); m.Name = xe.Attribute("name").Value; foreach (XElement node in xe.Elements("row")) { foreach (XElement el in node.Elements("cell")) m.Result = el.Value; m.Suffix = ""; } this.AddMetric(m); } } }
/// <summary> /// Add a metric to the list of metrics for this monitor and keep track of the /// maximum display width of the metric name /// </summary> /// <param name="_metric"></param> protected virtual void AddMetric(Metric _metric) { if (_metric.Name.Length > maxMetricWidth) maxMetricWidth = _metric.Name.Length; metrics.Add(_metric); }