Created
October 27, 2011 20:56
-
-
Save abarnas/1320841 to your computer and use it in GitHub Desktop.
Agent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace MonitisTop | |
{ | |
public class Agent | |
{ | |
private string id; | |
private string name; | |
private int maxMonitorWidth; | |
private List<Monitor> monitors; | |
public string Id { get { return id; } set { id = value;} } | |
public string Name { get { return name; } set { name = value; } } | |
public int MaxMonitorWidth { get { return maxMonitorWidth; } set { maxMonitorWidth = value; } } | |
public List<Monitor> Monitors { get { return monitors; } set { monitors = value; } } | |
public Agent() | |
{ | |
maxMonitorWidth = 0; | |
monitors = new List<Monitor>(); | |
} | |
/// <summary> | |
/// Get the global monitors specified on the commandline | |
/// </summary> | |
/// <param name="apiKey"></param> | |
/// <param name="client"></param> | |
/// <param name="showMonitors"></param> | |
public void GetGlobalMonitors(string apiKey, HttpClient client, List<string> argMonitors) | |
{ | |
using (HttpResponseMessage response = client.Get("api?action=agentInfo&apikey=" + apiKey + "&output=xml&agentId=" + this.Id + "&loadTests=true")) | |
{ | |
response.EnsureStatusIsSuccessful(); | |
String data = response.Content.ReadAsString(); | |
XDocument xml = XDocument.Parse(data); | |
// copy the list of monitors from the command line | |
List<string> showMonitors = new List<string>(argMonitors); | |
// check if the list of monitors to show is 'all' or 'empty' | |
if (showMonitors.Count == 0) | |
{ | |
foreach (MonitorDefinition md in GlobalMonitor.GetMonitorDefinitions()) | |
showMonitors.Add(md.Metric); | |
} | |
// Loop through the list of monitors to show and retrieve the monitor details | |
foreach (string m in showMonitors) | |
{ | |
// select the monitor having the name that is requested | |
var allMonitors = from monitorNode in xml.Descendants(m) | |
select new | |
{ | |
Id = monitorNode.Element("id").Value, | |
Name = Util.BaseMonitorName(monitorNode.Element("name").Value, '@') | |
}; | |
// create the monitor objects and copy in the values from the | |
// XML results | |
foreach (var a in allMonitors) | |
{ | |
Monitor monitor = new GlobalMonitor(this); | |
monitor.Id = a.Id; | |
monitor.Name = a.Name; | |
monitor.GetMetrics(apiKey, client); | |
this.AddMonitor(monitor); | |
} | |
} | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment