Пример #1
0
        public static void BulkToDb(DataTable dt)
        {
            var setting  = JsonOperater.GetAppSetting();
            var sqlConn  = new SqlConnection(setting.Connection);
            var bulkCopy = new SqlBulkCopy(sqlConn)
            {
                DestinationTableName = "IISLogger", BatchSize = dt.Rows.Count
            };

            try
            {
                sqlConn.Open();
                if (dt.Rows.Count != 0)
                {
                    bulkCopy.WriteToServer(dt);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                sqlConn.Close();
                bulkCopy.Close();
            }
        }
Пример #2
0
        public bool Start(HostControl hostControl)
        {
            _log.Info("SampleService Starting...");

            hostControl.RequestAdditionalTime(TimeSpan.FromSeconds(10));

            _server.OpenAsync();
            var setting = JsonOperater.GetAppSetting();

            _timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
            _timer.Interval = 1000 * 60 * setting.Period;
            _timer.Enabled  = true;
            _timer.Start();
            //var setting = JsonOperater.GetAppSetting();
            //FileManager.InitStates(setting);

            //foreach (var key in setting.Directory.Keys)
            //{
            //    if (FileShare.ConnectState(setting.Directory[key], setting.UserName, setting.PassWord))
            //    {
            //        var needAnalyzes = FileManager.GetNeedAnalyzeFiles(setting.Directory[key], key);
            //        Analyzer.AnalyzeRecord(needAnalyzes, setting, key);
            //    }
            //}
            _log.Info("SampleService Started");

            return(true);
        }
Пример #3
0
        private void timer_Elapsed(object sender, EventArgs e)
        {
            //#region 开始分析iis日志
            try
            {
                var setting = JsonOperater.GetAppSetting();
                FileManager.InitStates(setting);

                foreach (var key in setting.Directory.Keys)
                {
                    //  if (FileShare.ConnectState(setting.Directory[key]))
                    //   {
                    var needAnalyzes = FileManager.GetNeedAnalyzeFiles(setting.Directory[key], key);
                    Analyzer.AnalyzeRecord(needAnalyzes, setting, key);
                    //    }
                }
                _log.Info("this turn completeed,time is:" + DateTime.Now);
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message);
            }


            //#endregion
        }
Пример #4
0
        public static IISTable GetIisData(string date, string ip, string domain)
        {
            var param         = int.Parse(date.Replace("-", string.Empty).Substring(2, 6));
            var connectionStr = JsonOperater.GetAppSetting().Connection;
            var connection    = new SqlConnection(connectionStr);
            var sql           = string.Format("select * from IISLogger with(nolock) where hour like '{0}%' order by hour", param);
            var list          = connection.Query <HourModel>(sql).Where(s => s.Domain == domain && s.IP == ip).OrderByDescending(s => s.Hour).ToList();
            var item          = new IISTable();

            item.List  = list;
            item.Count = 1;
            return(item);
        }
Пример #5
0
        public static chartData GetChartData(string date, string ip, string domain)
        {
            var param         = int.Parse(date.Replace("-", string.Empty).Substring(2, 6));
            var chartData     = new chartData();
            var connectionStr = JsonOperater.GetAppSetting().Connection;
            var connection    = new SqlConnection(connectionStr);
            var sql           = string.Format("select * from IISLogger with(nolock) where hour like '{0}%' order by hour", param);
            var list          = connection.Query <HourModel>(sql).Where(s => s.Domain == domain && s.IP == ip).ToList();

            chartData.ErrorRequstArray    = new int[list.Count];
            chartData.TimeoutRequestArray = new int[list.Count];
            chartData.ErrorInnerArray     = new int[list.Count];
            for (var i = 0; i < list.Count; i++)
            {
                chartData.ErrorRequstArray[i]    = list[i].ClinetErrorCount;
                chartData.ErrorInnerArray[i]     = list[i].ServerErrorCount;
                chartData.TimeoutRequestArray[i] = list[i].TimeoutCount;
            }
            return(chartData);
        }
Пример #6
0
        public HttpResponseMessage Index()
        {
            var url       = Request.RequestUri.AbsoluteUri.Split('?');
            var startdate = string.Empty;
            var ip        = string.Empty;
            var domain    = string.Empty;

            if (Request.RequestUri.AbsoluteUri.Split('&').Length == 3)
            {
                var parm = url[1].Split('&');
                startdate = parm[0].Split('=')[1];
                ip        = parm[1].Split('=')[1];
                domain    = parm[2].Split('=')[1];
            }
            else
            {
                startdate = DateTime.Now.ToString("yyyy-MM-dd");
            }
            var setting = JsonOperater.GetAppSetting();
            var model   = Repository.GetIisData(startdate, ip, domain);

            model.StartDate      = startdate;
            model.SelectedIp     = ip;
            model.SelectedDomain = domain;
            //获取IP列表
            model.Ips     = new List <string>();
            model.Domains = new List <string>();
            foreach (var key in setting.IpMapping.Keys)
            {
                model.Domains.Add(key);
                model.Ips.Add(setting.IpMapping[key]);
            }

            string content  = new RazorView("Index.cshtml", model).Run();
            var    response = new HttpResponseMessage(HttpStatusCode.OK);

            response.Content = new StringContent(content, System.Text.Encoding.UTF8, "text/html");
            return(response);
        }