Exemplo n.º 1
0
        public static void WriteMetric(eXMetric item)
        {
            //var list = item.Items.ToList();
            //var requestBegin = list.Find(x => x.Key.Equals("request.begin", StringComparison.OrdinalIgnoreCase));
            //var requestEnd = list.Find(x => x.Key.Equals("request.end", StringComparison.OrdinalIgnoreCase));
            //var cmdBegin = list.Find(x => x.Key.Equals("command.begin", StringComparison.OrdinalIgnoreCase));
            //var cmdEnd = list.Find(x => x.Key.Equals("command.end", StringComparison.OrdinalIgnoreCase));

            //if (requestEnd != null && requestBegin != null)
            //{
            //    DateTime end = (DateTime)requestEnd.Value;
            //    DateTime begin = (DateTime)requestBegin.Value;
            //    var elapsed = end - begin;
            //    ((List<TypedItem>)item.Items).Add(new TypedItem("request.elapsed", elapsed.TotalMilliseconds));
            //}
            //if (cmdEnd != null && cmdBegin != null)
            //{
            //    DateTime end = (DateTime)cmdEnd.Value;
            //    DateTime begin = (DateTime)cmdBegin.Value;
            //    var elaped = end - begin;
            //    ((List<TypedItem>)item.Items).Add(new TypedItem("command.elapsed", elaped.TotalMilliseconds));
            //}

            Writer.WriteMetric(item);
        }
Exemplo n.º 2
0
        private IResponse <T> ExecuteCommand <T>(DataSet ds, ICriterion criterion) where T : class, new()
        {
            IResponse <T> response = null;
            IRequest <T>  request  = new Message <T>(Context, ModelActionOption.ExecuteCommand)
            {
                Criterion = criterion
            };

            if (eXtensibleConfig.CaptureMetrics)
            {
                ((Message <T>)request).Items.Add(new TypedItem(XFConstants.Metrics.Scope.ModelRequestService.Begin, DateTime.Now));
            }

            response = Service.ExecuteCommand <T>(request);

            if (eXtensibleConfig.CaptureMetrics)
            {
                ((Message <T>)request).Items.Add(new TypedItem(XFConstants.Context.RequestEnd, DateTime.Now));
                ((Message <T>)request).Items.Add(new TypedItem(XFConstants.Metrics.StatusCode, response.Status.Code));
                ((Message <T>)request).Items.Add(new TypedItem(XFConstants.Metrics.StatusDesc, response.Status.Description));
                eXMetric metric = response.ToMetric();
                EventWriter.WriteMetric(metric);
            }

            return(response);
        }
Exemplo n.º 3
0
        protected override void Publish(eXMetric metric)
        {
            string url = eXtensibleConfig.BigDataUrl;

            Run(metric, url);
            //RunAsync(metric,url).Wait();
            //new Action<eXMetric, string>(Run).BeginInvoke(metric, url, null, null);
        }
Exemplo n.º 4
0
 private void Run(eXMetric metric, string baseUrl)
 {
     try
     {
         using (var client = new HttpClient())
         {
             client.BaseAddress = new Uri(baseUrl);
             client.DefaultRequestHeaders.Add("Authorization", String.Format("{0} {1}", "basic", eXtensibleConfig.ServiceToken));
             var response = client.PostAsJsonAsync <eXMetric>(String.Format(ApiUrlFormat, eXtensibleConfig.ApiRoot, eXtensibleConfig.ApiMetrics), metric);
             if (response.Result.IsSuccessStatusCode)
             {
             }
             else
             {
             }
         }
     }
     catch
     {
     }
 }
Exemplo n.º 5
0
        private IResponse <T> Post <T>(T model) where T : class, new()
        {
            IResponse <T> response = null;
            IRequest <T>  request  = new Message <T>(Context, ModelActionOption.Post)
            {
            };

            request.Model = model;
            response      = Service.Post <T>(request);

            if (eXtensibleConfig.CaptureMetrics && !typeof(T).IsSubclassOf(typeof(eXBase)))
            {
                ((Message <T>)request).Items.Add(new TypedItem(XFConstants.Context.RequestEnd, DateTime.Now));
                ((Message <T>)request).Items.Add(new TypedItem(XFConstants.Metrics.StatusCode, response.Status.Code));
                ((Message <T>)request).Items.Add(new TypedItem(XFConstants.Metrics.StatusDesc, response.Status.Description));
                eXMetric metric = response.ToMetric();
                EventWriter.WriteMetric(metric);
            }

            return(response);
        }
Exemplo n.º 6
0
        private IResponse <T, U> ExecuteMany <T, U>(IEnumerable <T> list, ICriterion criterion) where T : class, new()
        {
            IResponse <T, U> response = null;
            IRequest <T>     request  = new Message <T, U>(Context, ModelActionOption.ExecuteMany)
            {
                Criterion = criterion
            };

            //request.Model = list;
            request.Content = list;
            response        = Service.ExecuteMany <T, U>(request);

            if (eXtensibleConfig.CaptureMetrics)
            {
                ((Message <T>)request).Items.Add(new TypedItem(XFConstants.Context.RequestEnd, DateTime.Now));
                ((Message <T>)request).Items.Add(new TypedItem(XFConstants.Metrics.StatusCode, response.Status.Code));
                ((Message <T>)request).Items.Add(new TypedItem(XFConstants.Metrics.StatusDesc, response.Status.Description));
                eXMetric metric = response.ToMetric();
                EventWriter.WriteMetric(metric);
            }

            return(response);
        }
Exemplo n.º 7
0
 protected override void Publish(eXMetric metric)
 {
     PublishLocal(EventTypeOption.None, metric.Items.ToList());
 }
Exemplo n.º 8
0
 void IEventWriter.WriteMetric(eXMetric item)
 {
     LocalPublish(item);
 }
Exemplo n.º 9
0
 protected abstract void Publish(eXMetric metric);
Exemplo n.º 10
0
 private void LocalPublish(eXMetric item)
 {
     Publish(item);
 }
Exemplo n.º 11
0
 protected override void Publish(eXMetric metric)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 12
0
 protected override void Publish(eXMetric metric)
 {
 }
Exemplo n.º 13
0
 protected override void Publish(eXMetric metric)
 {
     Debug.WriteLine(metric.ToString());
 }
Exemplo n.º 14
0
 protected override void Publish(eXMetric metric)
 {
     Publish(EventLogEntryType.Information, metric.ToString());
 }
Exemplo n.º 15
0
 public static void WriteMetric(eXMetric item)
 {
     Writer.WriteMetric(item);
 }
Exemplo n.º 16
0
        public Metric(eXMetric item)
        {
            AppKey = !String.IsNullOrWhiteSpace(item.ApplicationKey) ? item.ApplicationKey : item.Items.GetValueAs <string>(XFConstants.Context.Application);
            Zone   = !String.IsNullOrWhiteSpace(item.Zone) ? item.Zone : item.Items.GetValueAs <string>(XFConstants.Context.ZONE);
            Tds    = item.Tds;

            Model            = item.Items.GetValueAs <string>(XFConstants.Context.Model);
            Verb             = item.Items.GetValueAs <string>(XFConstants.Message.Verb);
            User             = item.Items.GetValueAs <string>(XFConstants.Context.USERIDENTITY);
            UIC              = item.Items.GetValueAs <string>(XFConstants.Context.UICULTURE);
            IId              = item.Items.GetValueAs <string>(XFConstants.Context.INSTANCEIDENTIFIER);
            Dbtype           = item.Items.GetValueAs <string>(XFConstants.Metrics.DbType);
            Criteria         = item.Items.GetValueAs <string>(XFConstants.Metrics.Criteria);
            Count            = item.Items.GetValueAs <int>(XFConstants.Metrics.Count);
            RequestBegin     = item.Items.GetValueAs <DateTime>(XFConstants.Context.RequestBegin);
            DataRequestBegin = item.Items.GetValueAs <DateTime>(XFConstants.Metrics.Scope.DataRequestService.Begin);
            DataRequestEnd   = item.Items.GetValueAs <DateTime>(XFConstants.Metrics.Scope.DataRequestService.End);
            RequestEnd       = item.Items.GetValueAs <DateTime>(XFConstants.Context.RequestEnd);
            if (!String.IsNullOrWhiteSpace(Dbtype) && Dbtype.Equals("sqlserver", StringComparison.OrdinalIgnoreCase))
            {
                string datastore = item.Items.GetValueAs <string>(XFConstants.Metrics.Database.Datasource);
                if (!String.IsNullOrWhiteSpace(datastore))
                {
                    string[] cn = datastore.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                    if (cn != null && cn.Length == 2)
                    {
                        string[] server = cn[0].Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
                        if (server != null && server.Length == 2)
                        {
                            Server = server[1];
                        }
                        string[] catalog = cn[1].Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
                        if (catalog != null && catalog.Length == 2)
                        {
                            Database = catalog[1];
                        }
                    }
                }

                var cnt = item.Items.FirstOrDefault(x => x.Key.Equals(XFConstants.Metrics.Count));
                int i;
                if (cnt != null && Int32.TryParse(cnt.Value.ToString(), out i))
                {
                    Count = i;
                }

                var found = item.Items.FirstOrDefault(x => x.Key.Equals(XFConstants.Metrics.Scope.Command.Text));
                if (found != null)
                {
                    Command     = found.Value.ToString();
                    CommandType = found.Scope;
                }
                DataAccessBegin = item.Items.GetValueAs <DateTime>(XFConstants.Metrics.Scope.Command.Begin);
                DataAccessEnd   = item.Items.GetValueAs <DateTime>(XFConstants.Metrics.Scope.Command.End);
                TimeSpan ts = DataAccessEnd - DataAccessBegin;
                DataAccessElapsed = ts.TotalMilliseconds;// Convert.ToDecimal(ts.TotalMilliseconds);
            }
            else
            {
                var list = item.Items.ToList();
                if (list.ContainsKey(XFConstants.Metrics.Database.Datasource))
                {
                    string datastore = item.Items.GetValueAs <string>(XFConstants.Metrics.Database.Datasource);
                    Database = datastore;
                }
                if (list.ContainsKey(XFConstants.Metrics.Scope.Command.Begin) && list.ContainsKey(XFConstants.Metrics.Scope.Command.End))
                {
                    DataAccessBegin = item.Items.GetValueAs <DateTime>(XFConstants.Metrics.Scope.Command.Begin);
                    DataAccessEnd   = item.Items.GetValueAs <DateTime>(XFConstants.Metrics.Scope.Command.End);
                }
                var found = item.Items.GetValueAs <string>(XFConstants.Metrics.Scope.Command.Text);
                if (found != null)
                {
                    Command = found;
                }

                DataAccessBegin = DataRequestBegin;
                DataAccessEnd   = DataRequestEnd;

                TimeSpan ts = DataAccessEnd - DataAccessBegin;
                DataAccessElapsed = ts.TotalMilliseconds;// Convert.ToDecimal(ts.TotalMilliseconds);
            }

            TimeSpan request = RequestEnd - RequestBegin;

            RequestElapsed = request.TotalMilliseconds;// Convert.ToDecimal(request.TotalMilliseconds);

            TimeSpan resolver = DataAccessBegin - DataRequestBegin;

            ResolveMdgElapsed = resolver.TotalMilliseconds;
            Year      = item.Tds.Year;
            Month     = item.Tds.Month;
            Day       = item.Tds.Day;
            DayOfWeek = item.Tds.DayOfWeek.ToString();
            Hour      = item.Tds.Hour;
            Minute    = item.Tds.Minute;
        }