Ejemplo n.º 1
0
 private static void SingleSearch()
 {
     try
     {
         var splunk = new SplunkApi(hostName, "admin", "admin");
         int numberOfConnections = 0;
         // Do X number of searches
         for (int i = 0; i < searches; i++)
         {
             try
             {
                 splunk.Connect();
                 numberOfConnections++;
                 if (i % 50 == 0)
                 {
                     Auxilary.WriteLineColor(ConsoleColor.Gray, "{0} {1} connections made so far, {2} remaining", DateTime.Now, numberOfConnections, searches - i);
                 }
             }
             catch (Exception e)
             {
                 ConsoleColor c = Console.ForegroundColor;
                 Console.ForegroundColor = ConsoleColor.Yellow;
                 Console.WriteLine("--- One of the threads caught an exception {0}, {1} searches remaining", e.Message, searches - i);
                 Console.ForegroundColor = c;
             }
         }
     }
     catch (Exception e)
     {
         ConsoleColor c = Console.ForegroundColor;
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine("--- One of the threads caught an exception {0}.Exiting thread", e.Message);
         Console.ForegroundColor = c;
     }
 }
Ejemplo n.º 2
0
        private static void ConnectionTest(object info)
        {
            object[] arguments        = info as object[];
            string   hostName         = (string)arguments[0];
            int      numberOfAttempts = (int)arguments[1];
            int      threadId         = (int)arguments[2];

            try
            {
                var  splunk = new SplunkApi(hostName, "admin", "admin");
                long connectionMade = 0, connectionFailed = 0;

                // Do X number of connections
                for (int i = 0; i < numberOfAttempts; i++)
                {
                    // Batch status update to avoid spinlocks
                    if (i % 50 == 0)
                    {
                        Interlocked.Add(ref _connectionSucceeded, connectionMade);
                        Interlocked.Add(ref _connectionFailed, connectionFailed);
                        connectionMade = connectionFailed = 0;
                    }
                    DateTime tStart = DateTime.Now;
                    try
                    {
                        splunk.Connect();
                        connectionMade++;
                    }
                    catch (Exception)
                    {
                        connectionFailed++;
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine();
                Auxilary.WriteLineColor(ConsoleColor.Red, "{0} [Thread {1:D4}] caught an exception '{2}'. Exiting thread", DateTime.Now, threadId, e.Message);
            }
        }