Exemplo n.º 1
0
        public void GetCustomMonitors(OutputType output)
        {
            var monitors = customMonitor.GetMonitors(output);

            if (output == OutputType.XML)
            {
                XElement.Parse(monitors.Content);
            }
            else if (output == OutputType.JSON)
            {
                JArray.Parse(monitors.Content);
            }
        }
Exemplo n.º 2
0
        private int CreateMonitorIfNotExist(ClrMethodInfo info)
        {
            var name = GetMonitorName(info);

            var monitors        = _monitor.GetMonitors(OutputType.XML);
            var monitorsElement = System.Xml.Linq.XElement.Parse(monitors.Content);
            var monitorss       = monitorsElement.Descendants("monitor").Select(u => new { ID = u.Elements("id").FirstOrDefault(), Name = u.Elements("name").FirstOrDefault(), Monitor = u });
            var monitor         = monitorss.FirstOrDefault(u => u.Name != null && u.Name.Value == name);

            if (monitor == null)
            {
                var agents        = _agent.GetAgents("profiler", true, true, OutputType.XML);
                var agentsElement = System.Xml.Linq.XElement.Parse(agents.Content);

                var agent = agentsElement.Descendants("agent").Select(u => new { ID = u.Elements("id").FirstOrDefault(), Name = u.Elements("name").FirstOrDefault(), Agent = u }).FirstOrDefault(u => u.Name != null && u.ID != null && u.Name.Value == "MonitisProfilerUserAgent");
                int agentID;
                if (agent == null)
                {
                    var result = _agent.AddAgent("MonitisProfilerUserAgent", "profiler", new JObject(), 100000, OutputType.JSON);
                    var res    = JObject.Parse(result.Content);
                    if (res["status"].Value <string>() != "ok")
                    {
                        throw new InvalidOperationException("Cannot create agent!: " + res["status"]);
                    }
                    agentID = int.Parse(res["data"].Value <string>());
                }
                else
                {
                    agentID = int.Parse(agent.ID.Value);
                }

                var resParam = new MonResultParameter("Execution Time", "Execution Time", "Execution Time", DataType.Float);

                var param = new MonitorParameter("param1", "param1d", "val", DataType.String, false);

                var resAddParam = new MonResultParameter("MonAddResparam1", "MonAddResparam1d",
                                                         "MonAddResval", DataType.String);
                _log.InfoFormat("Creating monitor {0}", name);
                var resMon = _monitor.AddMonitor(agentID, name, "profiler", "profiler",
                                                 new List <MonitorParameter>()
                {
                    param
                },
                                                 new List <MonResultParameter>()
                {
                    resParam
                },
                                                 new List <MonResultParameter>()
                {
                    resAddParam
                });

                var resJson = JObject.Parse(resMon.Content);
                if (resJson["status"].Value <string>() != "ok")
                {
                    throw new InvalidOperationException("Cannot create custom monitor!: " + resJson["status"]);
                }
                return(int.Parse(resJson["data"].Value <string>()));
            }
            else
            {
                _log.InfoFormat("Monitor exist {0}", name);
                return(int.Parse(monitor.ID.Value));
            }
        }