public SqlPoller(Settings settings, ILog log = null) { _settings = settings; _syncRoot = new object(); _log = log ?? LogManager.GetLogger(Constants.SqlMonitorLogger); _metricCollector = new MetricCollector(settings, _log); }
public void QueryChildren(MetricCollector collector) { using (var context = _fixture.CreateContext()) { context.Customers.ToList(); collector.StartCollection(); var orders = context.Orders.ToList(); collector.StopCollection(); Assert.Equal(100, context.ChangeTracker.Entries <Customer>().Count()); Assert.Equal(100, context.ChangeTracker.Entries <Order>().Count()); Assert.All(orders, o => Assert.NotNull(o.Customer)); } }
public void OrderBy(MetricCollector collector, bool tracking, bool caching) { using (var context = _fixture.CreateContext()) { var query = context.Products .ApplyCaching(caching) .ApplyTracking(tracking) .OrderBy(p => p.Retail); collector.StartCollection(); var result = query.ToList(); collector.StopCollection(); Assert.Equal(1000, result.Count); } }
public void AttachCollection(MetricCollector collector, bool autoDetectChanges) { using (var context = _fixture.CreateContext()) { context.ChangeTracker.AutoDetectChangesEnabled = autoDetectChanges; var customers = GetAllCustomersFromDatabase(); Assert.Equal(1000, customers.Length); using (collector.StartCollection()) { context.Customers.AttachRange(customers); } } }
public void RemoveCollection(MetricCollector collector, bool autoDetectChanges) { using (var context = _fixture.CreateContext()) { context.ChangeTracker.AutoDetectChangesEnabled = autoDetectChanges; var customers = context.Customers.ToArray(); Assert.Equal(1000, customers.Length); using (collector.StartCollection()) { context.Customers.RemoveRange(customers); } } }
public void QueryParents(MetricCollector collector) { using (var context = _fixture.CreateContext()) { context.Orders.ToList(); collector.StartCollection(); var customers = context.Customers.ToList(); collector.StopCollection(); Assert.Equal(100, context.ChangeTracker.Entries <Customer>().Count()); Assert.Equal(100, context.ChangeTracker.Entries <Order>().Count()); Assert.All(customers, c => Assert.Equal(1, c.Orders.Count)); } }
public void SkipTake(MetricCollector collector, bool tracking) { using (var context = _fixture.CreateContext()) { var query = context.Products .ApplyTracking(tracking) .OrderBy(p => p.ProductId) .Skip(500).Take(500); collector.StartCollection(); var result = query.ToList(); collector.StopCollection(); Assert.Equal(500, result.Count); } }
public void Include(MetricCollector collector, bool tracking) { using (var context = _fixture.CreateContext()) { var query = context.Customers .ApplyTracking(tracking) .Include(c => c.Orders); collector.StartCollection(); var result = query.ToList(); collector.StopCollection(); Assert.Equal(1000, result.Count); Assert.Equal(2000, result.SelectMany(c => c.Orders).Count()); } }
public void Attach(MetricCollector collector) { using (var context = _fixture.CreateContext()) { var customers = GetAllCustomersFromDatabase(); Assert.Equal(1000, customers.Length); using (collector.StartCollection()) { foreach (var customer in customers) { context.Customers.Attach(customer); } } } }
public void ValueFromObject(MetricCollector collector) { using (var context = _fixture.CreateContext()) { using (collector.StartCollection()) { var valueHolder = new ValueHolder(); for (var i = 0; i < _funcletizationIterationCount; i++) { var result = context.Products.Where(p => p.ProductId < valueHolder.SecondLevelProperty).ToList(); Assert.Equal(10, result.Count); } } } }
public void NewQueryInstance(MetricCollector collector) { using (var context = _fixture.CreateContext()) { using (collector.StartCollection()) { var val = 11; for (var i = 0; i < _funcletizationIterationCount; i++) { var result = context.Products.Where(p => p.ProductId < val).ToList(); Assert.Equal(10, result.Count); } } } }
public void ProjectionAcrossNavigation(MetricCollector collector) { using (var context = _fixture.CreateContext()) { collector.StartCollection(); var result = context.Orders.Select(o => new { CustomerName = o.Customer.Name, OrderDate = o.Date }) .ToList(); collector.StopCollection(); Assert.Equal(2000, result.Count); } }
public void Remove(MetricCollector collector) { using (var context = _fixture.CreateContext()) { var customers = context.Customers.ToArray(); Assert.Equal(1000, customers.Length); using (collector.StartCollection()) { foreach (var customer in customers) { context.Customers.Remove(customer); } } } }
public void Remove(MetricCollector collector, bool autoDetectChanges) { using (var context = _fixture.CreateContext()) { var customers = context.Customers.ToArray(); Assert.Equal(1000, customers.Length); context.Configuration.AutoDetectChangesEnabled = autoDetectChanges; using (collector.StartCollection()) { foreach (var customer in customers) { context.Customers.Remove(customer); } } } }
public void ProjectionAcrossNavigation(MetricCollector collector, bool caching) { using (var context = _fixture.CreateContext(queryCachingEnabled: caching)) { // TODO Use navigation for projection when supported (#325) var query = context.Orders.Join( context.Customers, o => o.CustomerId, c => c.CustomerId, (o, c) => new { CustomerName = c.Name, OrderDate = o.Date }); collector.StartCollection(); var result = query.ToList(); collector.StopCollection(); Assert.Equal(2000, result.Count); } }
public void Attach(MetricCollector collector, bool autoDetectChanges) { using (var context = _fixture.CreateContext()) { var customers = GetAllCustomersFromDatabase(); Assert.Equal(1000, customers.Length); context.Configuration.AutoDetectChangesEnabled = autoDetectChanges; using (collector.StartCollection()) { foreach (var customer in customers) { context.Customers.Attach(customer); } } } }
public void BuildModel_AdventureWorks(MetricCollector collector) { collector.StartCollection(); var conventions = new SqlServerConventionSetBuilder() .AddConventions(new CoreConventionSetBuilder().CreateConventionSet()); var builder = new ModelBuilder(conventions); AdventureWorksContext.ConfigureModel(builder); var model = builder.Model; collector.StopCollection(); Assert.Equal(67, model.EntityTypes.Count()); }
public void AddCollection(MetricCollector collector) { using (var context = _fixture.CreateContext()) { var customers = new Customer[1000]; for (var i = 0; i < customers.Length; i++) { customers[i] = new Customer { Name = "Customer " + i }; } using (collector.StartCollection()) { context.Customers.AddRange(customers); } } }
public void Update(MetricCollector collector, bool autoDetectChanges) { using (var context = _fixture.CreateContext()) { context.Configuration.AutoDetectChangesEnabled = autoDetectChanges; var customers = GetAllCustomersFromDatabase(); Assert.Equal(1000, customers.Length); using (collector.StartCollection()) { foreach (var customer in customers) { context.Entry(customer).State = EntityState.Modified; } } } }
public void Update(MetricCollector collector, bool disableBatching) { using (var context = _fixture.CreateContext(disableBatching)) { using (context.Database.BeginTransaction()) { foreach (var customer in context.Customers) { customer.Name += " Modified"; } collector.StartCollection(); var records = context.SaveChanges(); collector.StopCollection(); Assert.Equal(1000, records); } } }
public void GroupBy(MetricCollector collector, bool caching) { using (var context = _fixture.CreateContext(queryCachingEnabled: caching)) { var query = context.Products .GroupBy(p => p.Retail) .Select(g => new { Retail = g.Key, Products = g }); collector.StartCollection(); var result = query.ToList(); collector.StopCollection(); Assert.Equal(10, result.Count); Assert.All(result, g => Assert.Equal(100, g.Products.Count())); } }
public void Delete(MetricCollector collector) { using (var context = _fixture.CreateContext()) { using (context.Database.BeginTransaction()) { foreach (var customer in context.Customers) { context.Customers.Remove(customer); } collector.StartCollection(); var records = context.SaveChanges(); collector.StopCollection(); Assert.Equal(1000, records); } } }
public bool Start(HostControl hostControl) { log.Info("starting up"); var statsify = configuration.Statsify; var @namespace = statsify.Namespace; if (!string.IsNullOrWhiteSpace(@namespace)) { @namespace += "."; } @namespace += Environment.MachineName.ToLowerInvariant(); var uri = statsify.Uri; if (uri != null && !string.IsNullOrWhiteSpace(uri.OriginalString)) { log.Trace("configuring StatsifyClient with uri: {0}, namespace: '{1}', collection interval: '{2}' ", statsify.Uri, @namespace, configuration.Metrics.CollectionInterval); var statsifyChannelFactory = new StatsifyChannelFactory(); var statsifyChannel = statsifyChannelFactory.CreateChannel(uri); statsifyClient = new StatsifyClient(@namespace, statsifyChannel); } // if else { log.Trace("configuring StatsifyClient with host: {0}, port: {1}, namespace: '{2}', collection interval: '{3}' ", configuration.Statsify.Host, configuration.Statsify.Port, @namespace, configuration.Metrics.CollectionInterval); statsifyClient = new UdpStatsifyClient(statsify.Host, statsify.Port, @namespace); } // else metricCollector = new MetricCollector(configuration.Metrics); metricPublisher = new MetricPublisher(metricCollector, statsifyClient, configuration.Metrics.CollectionInterval); metricPublisher.Start(); return(true); }
public void AddCollection(MetricCollector collector, bool autoDetectChanges) { using (var context = _fixture.CreateContext()) { context.Configuration.AutoDetectChangesEnabled = autoDetectChanges; var customers = new Customer[1000]; for (var i = 0; i < customers.Length; i++) { customers[i] = new Customer { Name = "Customer " + i }; } using (collector.StartCollection()) { context.Customers.AddRange(customers); } } }
private static MetricCollector GetCollector(int count, object obj) { var id = string.Join("~", obj.GetType().Name, count); return(_dataCollectors.GetOrAdd(id, x => { var display = (DisplayAttribute)obj.GetType() .GetCustomAttributes(typeof(DisplayAttribute), true) .FirstOrDefault(); var collector = new MetricCollector(id) { DisplayName = display?.Name ?? obj.GetType().Name, DisplayOrder = display?.Order ?? 99999 }; collector.AdditionalProperties["ObjectCount"] = count; return collector; })); }
public void Insert(MetricCollector collector) { using (var context = _fixture.CreateContext()) { using (context.Database.BeginTransaction()) { for (var i = 0; i < 1000; i++) { context.Customers.Add(new Customer { Name = "New Customer " + i }); } collector.StartCollection(); var records = context.SaveChanges(); collector.StopCollection(); Assert.Equal(1000, records); } } }
public void AddChildren(MetricCollector collector) { using (var context = _fixture.CreateContext()) { var customers = context.Customers.ToList(); Assert.Equal(100, customers.Count); foreach (var customer in customers) { var order = new Order { CustomerId = customer.CustomerId }; using (collector.StartCollection()) { context.Orders.Add(order); } Assert.Same(order, order.Customer.Orders.Single()); } } }
public void InitializeAndQuery_AdventureWorks(MetricCollector collector, bool cold, int count) { RunColdStartEnabledTest(cold, c => c.InitializeAndQuery_AdventureWorks(collector, count)); }
public void CreateAndDisposeUnusedContext(MetricCollector collector, bool cold, int count) { RunColdStartEnabledTest(cold, c => c.CreateAndDisposeUnusedContext(collector, count)); }
public void InitializeAndSaveChanges_AdventureWorks(MetricCollector collector, bool cold, int count) { RunColdStartEnabledTest(cold, t => t.InitializeAndSaveChanges_AdventureWorks(collector, count)); }