public void CreateCustomMonitor()
        {
            authentication = new Authentication(apiKey: MonitisAccountInformation.ApiKey,
                                              secretKey: MonitisAccountInformation.SekretKey);
            customMonitor = new CustomMonitor();
            customMonitor.SetAuthenticationParams(authentication);
            agent = new CustomUserAgent();
            agent.SetAuthenticationParams(authentication);

            var a1 = agent.AddAgent("TestAgent1" + DateTime.Now.Ticks.ToString(), "internal", new JObject(), 100000, OutputType.JSON);
            _agentID = JObject.Parse(a1.Content).Value<int>("data");

            customMonitor = new CustomMonitor();
            customMonitor.SetAuthenticationParams(authentication);

            MonitorParameter param = new MonitorParameter("param1", "param1d", "val", DataType.String, false);
            MonResultParameter resParam = new MonResultParameter("MonResparam1", "MonResparam1d", "MonResval",
                                                                 DataType.String);
            MonResultParameter resAddParam = new MonResultParameter("MonAddResparam1", "MonAddResparam1d",
                                                                    "MonAddResval", DataType.String);

            var s = customMonitor.AddMonitor(_agentID, TestCustomMonitorName + DateTime.Now.Ticks.ToString(), "Test", "internal",
                                             new List<MonitorParameter>() { param },
                                             new List<MonResultParameter>() { resParam },
                                             new List<MonResultParameter>() { resAddParam });
            _customMonitorID = JObject.Parse(s.Content).Value<int>("data");

            GetTestMonitor();
        }
Exemplo n.º 2
0
        public void CreateCustomMonitor()
        {
            authentication = new Authentication(apiKey: MonitisAccountInformation.ApiKey,
                                                secretKey: MonitisAccountInformation.SekretKey);
            customMonitor = new CustomMonitor();
            customMonitor.SetAuthenticationParams(authentication);
            agent = new CustomUserAgent();
            agent.SetAuthenticationParams(authentication);

            var a1 = agent.AddAgent("TestAgent1" + DateTime.Now.Ticks.ToString(), "internal", new JObject(), 100000, OutputType.JSON);

            _agentID = JObject.Parse(a1.Content).Value <int>("data");

            customMonitor = new CustomMonitor();
            customMonitor.SetAuthenticationParams(authentication);

            MonitorParameter   param    = new MonitorParameter("param1", "param1d", "val", DataType.String, false);
            MonResultParameter resParam = new MonResultParameter("MonResparam1", "MonResparam1d", "MonResval",
                                                                 DataType.String);
            MonResultParameter resAddParam = new MonResultParameter("MonAddResparam1", "MonAddResparam1d",
                                                                    "MonAddResval", DataType.String);

            var s = customMonitor.AddMonitor(_agentID, TestCustomMonitorName + DateTime.Now.Ticks.ToString(), "Test", "internal",
                                             new List <MonitorParameter>()
            {
                param
            },
                                             new List <MonResultParameter>()
            {
                resParam
            },
                                             new List <MonResultParameter>()
            {
                resAddParam
            });

            _customMonitorID = JObject.Parse(s.Content).Value <int>("data");


            GetTestMonitor();
        }
Exemplo n.º 3
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));
            }
        }