Пример #1
0
        /// <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);
                    }
                }
            }
        }
Пример #2
0
        /// <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);
                    }
                }
            }
        }