Example #1
0
        private static void ProcessInstance(object?o)
        {
            Tuple <HttpContext, string, ConcurrentDictionary <string, ConcurrentBag <string> > > tuple = (Tuple <HttpContext, string, ConcurrentDictionary <string, ConcurrentBag <string> > >)o !;
            HttpContext context          = tuple.Item1;
            string      connectionString = tuple.Item2;
            ConcurrentDictionary <string, ConcurrentBag <string> > dictBags = tuple.Item3;

            var logger = context.RequestServices.GetRequiredService <ILogger <SQLServerHandler> >();

            logger.LogTrace($"Called ProcessInstance(connectionString = {connectionString}, dictBags={dictBags.ToString()}");

            try
            {
                var sqlServerInfo = SQLServerUtils.GetSQLServerInfo(context, connectionString);
                var retString     = new Counters.WorkerThread(context, sqlServerInfo).QueryAndSerializeData();
                dictBags.GetOrAdd("worker_thread", new ConcurrentBag <string>()).Add(retString);

                var pc = new Counters.PerformanceCounters(context, sqlServerInfo).QueryAndSerializeData();
                dictBags.GetOrAdd("performance_counters", new ConcurrentBag <string>()).Add(pc);

                var waitStats = new Counters.WaitStats(context, sqlServerInfo).QueryAndSerializeData();
                dictBags.GetOrAdd("wait_stats", new ConcurrentBag <string>()).Add(waitStats);

                var clerks = new Counters.MemoryClerks(context, sqlServerInfo).QueryAndSerializeData();
                dictBags.GetOrAdd("memory_clerks", new ConcurrentBag <string>()).Add(clerks);

                if (Program.CommandLineOptions != null)
                {
                    foreach (var customCounterConfiguration in Program.CommandLineOptions.CustomCounters)
                    {
                        var l =
                            new Counters.CustomCounter(context, sqlServerInfo, customCounterConfiguration.CustomCounter).QueryAndSerializeData();
                        dictBags.GetOrAdd(customCounterConfiguration.CustomCounter.Name, new ConcurrentBag <string>()).Add(l);
                    }
                }
            }
            catch (Exception e)
            {
                try
                {
                    System.Data.SqlClient.SqlConnectionStringBuilder connBuilder = new System.Data.SqlClient.SqlConnectionStringBuilder(connectionString);
                    logger.LogWarning($"unhandled exception processing \"{connBuilder.DataSource}\": {e.ToString()}");
                }
                catch (Exception einner)
                {
                    logger.LogWarning($"unhandled exception: {einner.ToString()}");
                }
            }
        }
Example #2
0
        private static async Task ProcessInstance(HttpContext context, string connectionString, ConcurrentBag <string> bag)
        {
            var logger = context.RequestServices.GetRequiredService <ILogger <SQLServerHandler> >();

            logger.LogTrace($"Called ProcessInstance(connectionString = {connectionString}, bag={bag.ToString()}");

            var sqlServerInfo = await SQLServerUtils.GetSQLServerInfo(context, connectionString);

            var retString = await new Counters.WorkerThread(context, sqlServerInfo).QueryAndSerializeData();

            bag.Add(retString);

            var pc = await new Counters.PerformanceCounters(context, sqlServerInfo).QueryAndSerializeData();

            bag.Add(pc);

            var waitStats = await new Counters.WaitStats(context, sqlServerInfo).QueryAndSerializeData();

            bag.Add(waitStats);
        }