Ejemplo n.º 1
0
        public void TestConfig()
        {
            MSMQConfig mc     = new MSMQConfig();
            string     msg    = "192.168.10.181|WORKGROUP|yanfa|xxxx@181";
            string     strMsg = EncryptHelper.EncryptDES(msg);// "ESvKEYyK/iZYFW2Zj16BRvdWGjElI+j75K5CLvjfMKgeIl0pvMRcvXWKU/roIuQNV37DiFNdhErwk7YWtXuL7AIn8z+4V6NFHLTLkwn8XsatMhL5OSsvzwAupJuzhbuJEHOINdRDopQ=";

            mc.Domains = new List <ConfigDomain>();
            mc.Domains.Add(new ConfigDomain()
            {
                Name = "181", Value = strMsg
            });

            mc.Nodes = new List <MSMQConfigNode>();
            mc.Nodes.Add(new MSMQConfigNode()
            {
                Instance = @"private$\lxy", Domain = "181", CategoryName = "MSMQ Queue", CounterName = "Messages in Queue"
            });
            mc.Nodes.Add(new MSMQConfigNode()
            {
                Instance = "", Domain = "181", CategoryName = "MSMQ Service", CounterName = "Outgoing Messages/sec"
            });
            mc.Nodes.Add(new MSMQConfigNode()
            {
                Instance = "", Domain = "181", CategoryName = "MSMQ Service", CounterName = "Incoming Messages/sec"
            });
            string strPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "mq.config.demo");

            XmlHelper.Enity2Xml(strPath, mc);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取mq深度
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public static List <MqCount> GetMqCount(MSMQConfig config)
        {
            if (config.Nodes == null)
            {
                return(null);
            }

            List <string>         arrList      = new List <string>();
            List <MSMQConfigNode> arrDomanList = new List <MSMQConfigNode>();

            foreach (MSMQConfigNode node in config.Nodes)
            {
                if (string.IsNullOrEmpty(node.Domain))
                {
                    arrList.Add(node.Instance);
                }
                else
                {
                    arrDomanList.Add(node);
                }
            }
            List <MqCount> arrMqCount = new List <MqCount>();

            if (arrList.Count > 0)
            {
                arrMqCount = GetMqCount(arrList);
            }
            DomainInit(config.Domains);
            foreach (MSMQConfigNode node in arrDomanList)
            {
                if (_performanceMap.ContainsKey(node.Domain))
                {
                    string remark = "";
                    string count  = "";
                    try
                    {
                        //pc.Get("MSMQ Queue", "Messages in Queue", @"highvertest\private$\tx1")
                        count = _performanceMap[node.Domain].Get("MSMQ Queue", "Messages in Queue", node.Instance).ToString();
                    }
                    catch (Exception ex)
                    {
                        remark = "节点获取异常" + (CommonConfig.IsDebug ? ex.ToString() : "");
                    }
                    arrMqCount.Add(new MqCount()
                    {
                        Name   = node.Instance,
                        Count  = count,
                        Remark = remark
                    });
                }
                else
                {
                    throw new Exception("未配置正确的Domain: " + node.Domain);
                }
            }
            return(arrMqCount);
        }
Ejemplo n.º 3
0
 public static void StartRun(MSMQConfig config)
 {
     _config = config;
     if (thread == null)
     {
         thread = new Thread(new ThreadStart(RecycleGuard));
         thread.Start();
     }
 }
Ejemplo n.º 4
0
        private void BindGridView(MSMQConfig config)
        {
            //绑定数据
            List <RowData> list = new List <RowData>();

            config.Nodes.ForEach(p => { list.Add(new RowData(p)); });

            gvMq.DataSource = list;
            gvMq.DataBind();
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            switch (args[0])
            {
            case "mssend":
                if (args.Length > 2)
                {
                    TestSend(args[1], args[2]);
                }
                else
                {
                    TestSend(args[1]);
                }
                break;

            case "mscount":
                TestGetCount(args[1]);
                break;

            case "msallcount":
                TestAllCount();
                break;

            case "msconfig":

                var mqConfig = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "mq.config");
                if (File.Exists(mqConfig) == false)
                {
                    Console.WriteLine("找不到" + mqConfig);
                }
                else
                {
                    MSMQConfig msmqConfig = null;
                    msmqConfig = XmlHelper.Xml2Entity(mqConfig, new MSMQConfig().GetType()) as MSMQConfig;
                    List <MqCount> list = MSMQHelper.GetMqCount(msmqConfig);
                    foreach (MqCount mc in list)
                    {
                        Console.WriteLine(string.Format(" {0} | {1} | {2}", mc.Name, mc.Count, mc.Remark));
                    }
                }
                break;

            default:
                Console.WriteLine("nothing todo ");
                break;
            }
            Console.Read();
        }
Ejemplo n.º 6
0
        private void InitControl()
        {
            ddlCategory.DataSource     = GetCategoryList();
            ddlCategory.DataTextField  = "Text";
            ddlCategory.DataValueField = "Value";
            ddlCategory.DataBind();

            //加载数据
            //MSMQConfig
            if (File.Exists(ConfigPath))
            {
                MSMQConfig config = XmlHelper.Xml2Entity(ConfigPath, new MSMQConfig().GetType()) as MSMQConfig;
                TempConfig = config;
                BindGridView(config);
            }
        }
Ejemplo n.º 7
0
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            List <string> keys = GetSelectKeys();

            if (keys.Count == 0)
            {
                Response.Write("<script>alert('至少选中一项进行删除')</script>");
                return;
            }
            else
            {
                MSMQConfig            config      = this.TempConfig;
                List <MSMQConfigNode> removeNodes = new List <MSMQConfigNode>();
                foreach (string key in keys)
                {
                    foreach (MSMQConfigNode node in config.Nodes)
                    {
                        if (key == node.ToString())
                        {
                            removeNodes.Add(node);
                        }
                    }
                }
                if (removeNodes.Count > 0)
                {
                    removeNodes.ForEach(p => {
                        config.Nodes.Remove(p);
                    });

                    //更新session
                    TempConfig = config;
                    //保存config
                    XmlHelper.Enity2Xml(ConfigPath, config);
                    //刷新表格
                    BindGridView(config);
                    //clear
                    Clear();

                    //更新服务配置文件时间
                    MonitorExe.UpdateLastConfigTime();
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 执行监控
        /// </summary>
        /// <param name="config">监控配置</param>
        /// <returns>结果列表</returns>
        public static List <MonitorResult> RunMonitor(MSMQConfig config)
        {
            if (config == null || config.Nodes == null)
            {
                return(null);
            }
            //初始化所有domain
            DomainInit(config.Domains);
            List <MonitorResult> rs = new List <MonitorResult>();

            foreach (MSMQConfigNode node in config.Nodes)
            {
                MonitorResult mr = new MonitorResult()
                {
                    CategoryName = node.CategoryName,
                    CounterName  = node.CounterName,
                    Domain       = node.Domain,
                    Instance     = node.Instance,
                    Remark       = string.Empty
                };
                try
                {
                    var counter = GetPerformanceCounter(node.Domain, node.CategoryName, node.CounterName, node.Instance);
                    if (counter == null)
                    {
                        mr.Remark = "获取监控器出错,请检查是否正确配置Domain";
                        mr.Result = "";
                    }
                    else
                    {
                        mr.Result = counter.NextValue().ToString();
                    }
                }
                catch (Exception ex)
                {
                    mr.Remark = "节点获取异常:" + (CommonConfig.IsDebug ? ex.ToString() : "");
                    CommonLog.InnerErrorLog.Error("节点获取异常:" + ex.ToString());
                }
                rs.Add(mr);
            }
            return(rs);
        }
Ejemplo n.º 9
0
        protected void btnEdit_Click(object sender, EventArgs e)
        {
            List <string> keys = GetSelectKeys();

            if (keys.Count == 0 || keys.Count > 1)
            {
                Response.Write("<script>alert('有仅只能选中一项进行编辑')</script>");
                return;
            }
            else
            {
                MSMQConfig config = this.TempConfig;
                foreach (MSMQConfigNode node in config.Nodes)
                {
                    if (keys[0] == node.ToString())
                    {
                        ddlCategory.SelectedValue = node.CategoryName;
                        //绑定数据
                        ddlCounter.DataSource     = GetCounterList(node.CategoryName);
                        ddlCounter.DataTextField  = "Text";
                        ddlCounter.DataValueField = "Value";
                        ddlCounter.DataBind();

                        ddlCounter.SelectedValue = node.CounterName;
                        txtInstance.Text         = node.Instance;
                        //获取Domain
                        ConfigDomain cd = config.Domains.Find(p => (p.Name == node.Domain));
                        if (cd != null)
                        {
                            string[] strs = EncryptHelper.DecryptDES(cd.Value).Split('|');

                            txtIP.Text      = strs[0];
                            txtDomain.Text  = strs[1];
                            txtAccount.Text = strs[2];
                            txtPwd.Text     = strs[3];
                        }
                    }
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 核心方法
        /// </summary>
        private static void RecycleGuard()
        {
            //加载本地配置
            var mqConfig = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "mq.config");

            try
            {
                if (File.Exists(mqConfig))
                {
                    _config = XmlHelper.Xml2Entity(mqConfig, new MSMQConfig().GetType()) as MSMQConfig;
                }
            }
            catch (Exception ex)
            {
                CommonLog.InnerErrorLog.Error("读取本地mq.config出错:" + ex.ToString() + ",继续逻辑");
            }
            int count = 0;

            while (Common.IsRun)
            {
                Thread.Sleep(Config.Internal);

                try
                {
                    //获取网络连接器
                    IStateCenterConnector connector = StateCenterConnectorFactory.GetConnector("web");

                    string lastConfigTime = connector.Promise("getLastConfigTime", "", "");
                    if (string.IsNullOrEmpty(lastConfigTime))
                    {
                        if (count++ > 10000)
                        {
                            //一直连不上
                            return;
                        }
                        //无法连接的web服务器时,等待重试
                        continue;
                    }
                    if (string.IsNullOrEmpty(_lastConfigTime) || lastConfigTime != _lastConfigTime)
                    {
                        _lastConfigTime = lastConfigTime;
                        //进行下载云端配置
                        string remoteConfig = connector.Promise("getMSMQConfig", "", "");
                        //空时,认为远端未配置,不进行读取执行
                        if (string.IsNullOrEmpty(remoteConfig) == false)
                        {
                            //存储到本地
                            File.WriteAllText(mqConfig, remoteConfig);

                            //重新加载配置
                            try
                            {
                                _config = XmlHelper.Xml2Entity(mqConfig, new MSMQConfig().GetType()) as MSMQConfig;
                            }
                            catch (Exception ex)
                            {
                                CommonLog.InnerErrorLog.Error("读取Remote mq.config出错:" + ex.ToString() + ",中断运行");
                                return;
                            }
                        }
                    }

                    //判断是否成功读取配置文件
                    if (_config == null)
                    {
                        //如果为空继续抓取远端配置
                        continue;
                    }
                    //执行监控
                    List <MonitorResult> mrs = WinMonitorHelper.RunMonitor(_config);
                    //推送数据到服务器
                    string msg = string.Empty;
                    foreach (MonitorResult mr in mrs)
                    {
                        msg += (mr.Domain ?? "") + "~" + (mr.CategoryName ?? "") + "~" + (mr.CounterName ?? "") + "~"
                               + (mr.Instance ?? "") + "~" + (mr.Result ?? "") + "~" + (mr.Remark ?? "") + "|";
                    }
                    connector.Promise("sendMonitorMsg", "key", msg.TrimEnd(new char[] { '|' }));
                }
                catch (Exception ex)
                {
                    CommonLog.InnerErrorLog.Error("mq监控出错:" + ex.ToString());
                }
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //非空判断
            string ip       = txtIP.Text.Trim();
            string domain   = txtDomain.Text.Trim();
            string account  = txtAccount.Text.Trim();
            string pwd      = txtPwd.Text.Trim();
            string category = ddlCategory.SelectedValue;
            string counter  = ddlCounter.SelectedValue;
            string instance = txtInstance.Text.Trim();

            if (string.IsNullOrEmpty(ip))
            {
                Response.Write("<script>alert('IP必须填写')</script>");
                return;
            }
            if (string.IsNullOrEmpty(domain))
            {
                Response.Write("<script>alert('所属域必须填写')</script>");
                return;
            }
            if (string.IsNullOrEmpty(account))
            {
                Response.Write("<script>alert('账号必须填写')</script>");
                return;
            }
            if (string.IsNullOrEmpty(pwd))
            {
                Response.Write("<script>alert('密码必须填写')</script>");
                return;
            }
            if (string.IsNullOrEmpty(category))
            {
                Response.Write("<script>alert('监控类型必须选择')</script>");
                return;
            }
            if (string.IsNullOrEmpty(counter))
            {
                Response.Write("<script>alert('计数器必须选择')</script>");
                return;
            }
            if (category == "MSMQ Queue" && string.IsNullOrEmpty(instance))
            {
                Response.Write("<script>alert('实例必须填写')</script>");
                return;
            }

            MSMQConfig config = TempConfig;

            List <string> keys = GetSelectKeys();

            if (keys.Count == 0)
            {
                //新增

                string key = ip + category + counter + (instance ?? "");
                if (config.Nodes.Any(p => p.ToString() == key))
                {
                    //已经有这个配置
                    Response.Write("<script>alert('不能重复进行配置')</script>");
                    return;
                }
                else
                {
                    config.Nodes.Add(new MSMQConfigNode()
                    {
                        Domain       = ip,
                        CategoryName = category,
                        CounterName  = counter,
                        Instance     = instance
                    });
                }
            }
            else if (keys.Count == 1)
            {
                //修改情况
                MSMQConfigNode node = config.Nodes.Find(p => { return(p.ToString() == keys[0]); });
                if (node != null)
                {
                    node.Domain       = ip;
                    node.CategoryName = category;
                    node.CounterName  = counter;
                    node.Instance     = instance;
                }
            }
            else
            {
                //多个时不处理
                Response.Write("<script>alert('不能同时修改多个值')</script>");
                return;
            }
            //更新domain
            var    listDomains = config.Domains.Where(p => { return(p.Name == ip); }).ToList <ConfigDomain>();
            string domainValue = EncryptHelper.EncryptDES(ip + "|" + domain + "|" + account + "|" + pwd);

            if (listDomains.Count == 0)
            {
                //新增情况
                config.Domains.Add(new ConfigDomain()
                {
                    Name  = ip,
                    Value = domainValue
                });
            }
            else
            {
                //修改
                listDomains[0].Value = domainValue;
            }
            //更新session
            TempConfig = config;
            //保存config
            XmlHelper.Enity2Xml(ConfigPath, config);
            //刷新表格
            BindGridView(config);
            //clear
            Clear();

            //更新服务配置文件时间
            MonitorExe.UpdateLastConfigTime();
        }
Ejemplo n.º 12
0
 public void TestConfigRead()
 {
     string     strPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "mq.config.demo");
     MSMQConfig config  = XmlHelper.Xml2Entity(strPath, new MSMQConfig().GetType()) as MSMQConfig;
 }