public SqlPoller(Settings settings, ILog log = null)
 {
     _settings = settings;
     _syncRoot = new object();
     _log = log ?? LogManager.GetLogger(Constants.SqlMonitorLogger);
     _metricCollector = new MetricCollector(settings, _log);
 }
        internal static Settings FromConfigurationSection(NewRelicConfigurationSection section, ILog log)
        {
            var sqlEndpoints = section.SqlServers
                                      .Select(s =>
                                              {
                                                  var includedDatabaseNames = s.IncludedDatabases.Select(d => d.ToDatabase()).ToArray();
                                                  var excludedDatabaseNames = s.ExcludedDatabases.Select(d => d.Name).ToArray();
                                                  return
                                                      (ISqlEndpoint) new SqlServerEndpoint(s.Name, s.ConnectionString, s.IncludeSystemDatabases, includedDatabaseNames, excludedDatabaseNames);
                                              })
                                      .Union(section.AzureSqlDatabases.Select(s => (ISqlEndpoint) new AzureSqlEndpoint(s.Name, s.ConnectionString)));

            var service = section.Service;
            var settings = new Settings(sqlEndpoints.ToArray())
                           {
                               LicenseKey = service.LicenseKey,
                               PollIntervalSeconds = service.PollIntervalSeconds,
                           };

            if (!string.IsNullOrEmpty(service.ServiceName) && Regex.IsMatch(service.ServiceName, "^[a-zA-Z_0-9-]{6,32}$"))
            {
                settings.ServiceName = service.ServiceName;
            }

            return settings;
        }
 public SqlMonitorService(Settings settings)
 {
     _settings = settings;
     ServiceName = settings.ServiceName;
 }
        /// <summary>
        ///     Runs from the command shell, printing to the Console.
        /// </summary>
        /// <param name="settings"></param>
        private static void RunInteractive(Settings settings)
        {
            Console.Out.WriteLine("Starting Server");

            // Start our services
            var poller = new SqlPoller(settings);
            poller.Start();

            // Capture Ctrl+C
            Console.TreatControlCAsInput = true;

            char key;
            do
            {
                Console.Out.WriteLine("Press Q to quit...");
                var consoleKeyInfo = Console.ReadKey(true);
                Console.WriteLine();
                key = consoleKeyInfo.KeyChar;
            } while (key != 'q' && key != 'Q');

            Console.Out.WriteLine("Stopping...");

            // Stop our services
            poller.Stop();

            #if DEBUG
            if (Debugger.IsAttached)
            {
                Console.Out.WriteLine("Press any key to stop debugging...");
                Console.ReadKey();
            }
            #endif
        }
 public MetricCollector(Settings settings, ILog log)
 {
     _settings = settings;
     _log = log;
     _agentData = new AgentData {Host = Environment.MachineName, Pid = Process.GetCurrentProcess().Id, Version = _settings.Version,};
 }