Пример #1
0
        public ActionResult Add(tb_cluster_model model)
        {
            tb_cluster_dal dal = new tb_cluster_dal();

            try
            {
                using (DbConn PubConn = DbConfig.CreateConn(Config.PlatformManageConnectString))
                {
                    PubConn.Open();
                    if (dal.CheckServerIp(PubConn, model.serverip))
                    {
                        CheckJsonFormat(model);
                        model.createtime     = PubConn.GetServerDate();
                        model.lastupdatetime = PubConn.GetServerDate();
                        model.onlinetime     = PubConn.GetServerDate().AddDays(-1);
                        dal.Add(PubConn, model);
                        return(RedirectToAction("index"));
                    }
                    else
                    {
                        ModelState.AddModelError("Error", "IP已存在");
                        return(View(model));
                    }
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("Error", ex.Message);
                return(View(model));
            }
        }
Пример #2
0
        public virtual bool Edit(DbConn PubConn, tb_cluster_model model)
        {
            List <ProcedureParameter> Par = new List <ProcedureParameter>()
            {
                //服务器名
                new ProcedureParameter("@servername", model.servername),
                //服务器ip
                new ProcedureParameter("@serverip", model.serverip),
                //是否开启服务器监控
                new ProcedureParameter("@ifmonitor", model.ifmonitor),
                //
                new ProcedureParameter("@performancecollectconfigjson", model.performancecollectconfigjson),
                //监控的配置json
                new ProcedureParameter("@monitorcollectconfigjson", model.monitorcollectconfigjson),
                //创建时间
                new ProcedureParameter("@createtime", model.createtime),
                //上次更新时间
                new ProcedureParameter("@lastupdatetime", model.lastupdatetime),
                //
                new ProcedureParameter("@onlinetime", model.onlinetime)
            };

            Par.Add(new ProcedureParameter("@id", model.id));

            int rev = PubConn.ExecuteSql("update tb_cluster set servername=@servername,serverip=@serverip,ifmonitor=@ifmonitor,performancecollectconfigjson=@performancecollectconfigjson,monitorcollectconfigjson=@monitorcollectconfigjson,createtime=@createtime,lastupdatetime=@lastupdatetime,onlinetime=@onlinetime where id=@id", Par);

            return(rev == 1);
        }
Пример #3
0
        public virtual bool Add(DbConn PubConn, tb_cluster_model model)
        {
            List <ProcedureParameter> Par = new List <ProcedureParameter>()
            {
                //服务器名
                new ProcedureParameter("@servername", model.servername),
                //服务器ip
                new ProcedureParameter("@serverip", model.serverip),
                //是否开启服务器监控
                new ProcedureParameter("@ifmonitor", model.ifmonitor),
                //
                new ProcedureParameter("@performancecollectconfigjson", model.performancecollectconfigjson),
                //监控的配置json
                new ProcedureParameter("@monitorcollectconfigjson", model.monitorcollectconfigjson),
                //创建时间
                new ProcedureParameter("@createtime", model.createtime),
                //上次更新时间
                new ProcedureParameter("@lastupdatetime", model.lastupdatetime),
                //
                new ProcedureParameter("@onlinetime", model.onlinetime)
            };
            int rev = PubConn.ExecuteSql(@"insert into tb_cluster(servername,serverip,ifmonitor,performancecollectconfigjson,monitorcollectconfigjson,createtime,lastupdatetime,onlinetime)
										   values(@servername,@serverip,@ifmonitor,@performancecollectconfigjson,@monitorcollectconfigjson,@createtime,@lastupdatetime,@onlinetime)"                                        , Par);

            return(rev == 1);
        }
Пример #4
0
        public virtual tb_cluster_model CreateModel(DataRow dr)
        {
            var o = new tb_cluster_model();

            //
            if (dr.Table.Columns.Contains("id"))
            {
                o.id = dr["id"].Toint();
            }
            //服务器名
            if (dr.Table.Columns.Contains("servername"))
            {
                o.servername = dr["servername"].Tostring();
            }
            //服务器ip
            if (dr.Table.Columns.Contains("serverip"))
            {
                o.serverip = dr["serverip"].Tostring();
            }
            //是否开启服务器监控
            if (dr.Table.Columns.Contains("ifmonitor"))
            {
                o.ifmonitor = dr["ifmonitor"].Tobool();
            }
            //
            if (dr.Table.Columns.Contains("performancecollectconfigjson"))
            {
                o.performancecollectconfigjson = dr["performancecollectconfigjson"].Tostring();
            }
            //监控的配置json
            if (dr.Table.Columns.Contains("monitorcollectconfigjson"))
            {
                o.monitorcollectconfigjson = dr["monitorcollectconfigjson"].Tostring();
            }
            //创建时间
            if (dr.Table.Columns.Contains("createtime"))
            {
                o.createtime = dr["createtime"].ToDateTime();
            }
            //上次更新时间
            if (dr.Table.Columns.Contains("lastupdatetime"))
            {
                o.lastupdatetime = dr["lastupdatetime"].ToDateTime();
            }
            //
            if (dr.Table.Columns.Contains("onlinetime"))
            {
                o.onlinetime = dr["onlinetime"].ToDateTime();
            }
            return(o);
        }
Пример #5
0
 public int Update(DbConn PubConn, tb_cluster_model model)
 {
     return(SqlHelper.Visit(ps =>
     {
         ps.Add("id", model.id);
         ps.Add("servername", model.servername);
         ps.Add("serverip", model.serverip);
         ps.Add("ifmonitor", model.ifmonitor);
         ps.Add("performancecollectconfigjson", model.performancecollectconfigjson);
         ps.Add("monitorcollectconfigjson", model.monitorcollectconfigjson);
         ps.Add("onlinetime", model.onlinetime);
         string sql = "update tb_cluster set servername=@servername,serverip=@serverip,ifmonitor=@ifmonitor,performancecollectconfigjson=@performancecollectconfigjson,";
         sql += "monitorcollectconfigjson=@monitorcollectconfigjson,lastupdatetime=getdate(),onlinetime=@onlinetime where id=@id";
         return PubConn.ExecuteSql(sql, ps.ToParameters());
     }));
 }
Пример #6
0
        public List <tb_cluster_model> GetList(DbConn PubConn, string id, string keyword, string CStime, string CEtime, int pagesize, int pageindex, out int count)
        {
            int _count = 0;
            List <tb_cluster_model> model = new List <tb_cluster_model>();
            DataSet dsList = SqlHelper.Visit <DataSet>(ps =>
            {
                string sqlwhere   = " where 1=1 ";
                StringBuilder sql = new StringBuilder();
                sql.Append("select ROW_NUMBER() over(order by id desc) as rownum,* from tb_cluster ");
                if (!string.IsNullOrWhiteSpace(keyword))
                {
                    ps.Add("keyword", keyword);
                    sqlwhere += " and ( servername like '%'+@keyword+'%' or serverip like '%'+@keyword+'%' )";
                }
                if (!string.IsNullOrWhiteSpace(id))
                {
                    ps.Add("id", id);
                    sqlwhere += " and ( id=@id )";
                }
                DateTime d = DateTime.Now;
                if (DateTime.TryParse(CStime, out d))
                {
                    ps.Add("CStime", Convert.ToDateTime(CStime));
                    sqlwhere += " and createtime>=@CStime";
                }
                if (DateTime.TryParse(CEtime, out d))
                {
                    ps.Add("CEtime", Convert.ToDateTime(CEtime));
                    sqlwhere += " and createtime<=@CEtime";
                }
                _count        = Convert.ToInt32(PubConn.ExecuteScalar("select count(1) from tb_cluster " + sqlwhere, ps.ToParameters()));
                DataSet ds    = new DataSet();
                string sqlSel = "select * from (" + sql + sqlwhere + ") A where rownum between " + ((pageindex - 1) * pagesize + 1) + " and " + pagesize * pageindex;
                PubConn.SqlToDataSet(ds, sqlSel, ps.ToParameters());
                return(ds);
            });

            foreach (DataRow dr in dsList.Tables[0].Rows)
            {
                tb_cluster_model m = CreateModel(dr);
                model.Add(m);
            }
            count = _count;
            return(model);
        }
Пример #7
0
 private void CheckJsonFormat(tb_cluster_model model)
 {
     if (!string.IsNullOrWhiteSpace(model.monitorcollectconfigjson))
     {
         try {
             new XXF.Serialization.JsonHelper().Deserialize <List <Dyd.BaseService.Monitor.Core.CollectConfig> >(model.monitorcollectconfigjson);
         }
         catch (Exception exp)
         {
             throw new Exception("监控配置json格式不对");
         }
     }
     if (!string.IsNullOrWhiteSpace(model.performancecollectconfigjson))
     {
         try
         {
             new XXF.Serialization.JsonHelper().Deserialize <List <Dyd.BaseService.Monitor.Core.CollectConfig> >(model.performancecollectconfigjson);
         }
         catch (Exception exp)
         {
             throw new Exception("性能检测配置json格式不对");
         }
     }
 }
Пример #8
0
        private string GetWarnningInfo(CollectConfig config, tb_cluster_monitorinfo_model model, tb_cluster_model cluster)
        {
            string msg = "";

            var monitorinfos = new XXF.Serialization.JsonHelper().Deserialize <List <ClusterMonitorInfo> >(model.monitorinfojson);

            foreach (var info in monitorinfos)
            {
                if (info.Name == config.CollectName)
                {
                    if (config.EqualWarningValue != null && config.EqualWarningValue.IsWarning == true && config.EqualWarningValue.Value == info.MonitorValue)
                    {
                        msg += string.Format("【id:{2},{4}】检测项【{0}】等于预警值{3},当前值为{1}\r\n", config.CollectName, info.MonitorValue, model.serverid, config.EqualWarningValue.Value, cluster.servername);
                    }
                    if (config.LessThanWarningValue != null && config.LessThanWarningValue.IsWarning == true && config.LessThanWarningValue.Value > info.MonitorValue)
                    {
                        msg += string.Format("【id:{2},{4}】检测项【{0}】小于预警值{3},当前值为{1}\r\n", config.CollectName, info.MonitorValue, model.serverid, config.LessThanWarningValue.Value, cluster.servername);
                    }
                    if (config.MoreThanWarningValue != null && config.MoreThanWarningValue.IsWarning == true && config.MoreThanWarningValue.Value < info.MonitorValue)
                    {
                        msg += string.Format("【id:{2},{4}】检测项【{0}】大于预警值{3},当前值为{1}\r\n", config.CollectName, info.MonitorValue, model.serverid, config.MoreThanWarningValue.Value, cluster.servername);
                    }
                }
            }
            return(msg);
        }