Ejemplo n.º 1
0
        /// <summary>
        /// Heartbeat callback
        /// </summary>
        /// <param name="state"></param>
        private void HeartbeatCallback(object state)
        {
            try
            {
                if (Collector != null)
                {
                    String host    = Environment.MachineName;
                    String procid  = Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture);
                    String appname = Process.GetCurrentProcess().ProcessName;

                    SyslogMessage msg = new SyslogMessage(host, Facility, SyslogSeverity.Debug, null)
                    {
                        ProcessID       = procid,
                        ApplicationName = appname,
                        MessageId       = "HEARTBEAT"
                    };

                    PreProcessMessage(msg);

                    msg.Data.Remove("origin");
                    msg.Data.Remove("timeQuality");

                    if (msg.Data["meta"].ContainsKey("syUpTime"))
                    {
                        msg.Data["meta"].Remove("sysUpTime");
                    }

                    Collector.SubmitMessage(msg);
                }
            }
            catch
            {
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.CancelKeyPress += Console_CancelKeyPress;
            if (args == null || args.Length < 1)
            {
                Console.WriteLine("Usage: NoiseSource ([MESSAGE_RATE]|\"inf\")");
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine("\tMESSAGE_RATE:\t number of messages sent per second");
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine("Example: \tNoiseSource 1500");
                Console.WriteLine("sends 1500 messages per second");
                Console.WriteLine("\tNoiseSource inf");
                Console.WriteLine("sends infinite messages, flooding network socket");
                Environment.Exit(0);
            }
            int rate = 0;

            if (args[0] != "inf" && !int.TryParse(args[0], out rate) || rate == 0)
            {
                Console.WriteLine("Invalid rate");
                Environment.Exit(1);
            }
            long timeout = 10000000 / rate; //100ns timeout

            if (timeout == 0)
            {
                Console.WriteLine("Ready to send infinite messages at infinite rate");
            }
            else
            {
                Console.WriteLine("Ready to send infinite messages at a rate of {0}/s", rate);
            }

            ILogCollector server = CollectorHelper.CreateCollector();
            string        host   = System.Net.Dns.GetHostName();

            while (true)
            {
                SyslogMessage startMsg = new SyslogMessage
                {
                    Timestamp = DateTime.Now,
                    Facility  = SyslogFacility.Printer,
                    Severity  = SyslogSeverity.Debug,
                    Host      = host,
                    MessageId = "NOISE",
                    Text      = "The quick brown fox jumps over the lazy dog"
                };
                server.SubmitMessage(startMsg);

                if (rate > 0)
                {
                    Thread.Sleep(new TimeSpan(timeout));
                }
            }
        }
Ejemplo n.º 3
0
        private static void Run(int timeout)
        {
            _messagesRcvd = new BitArray(_expected, false);
            _received     = 0;
            string pid = Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture);

            ILogCollector  server     = CollectorHelper.CreateCollector();
            string         host       = Dns.GetHostName();
            PropertyFilter hostFilter = new PropertyFilter
            {
                comparison   = ComparisonOperator.eq,
                value        = host,
                propertyName = Property.Host
            };
            FacilityEqualsFilter facFilter = new FacilityEqualsFilter {
                facility = SyslogFacility.Local4
            };
            PropertyFilter pidFilter = new PropertyFilter
            {
                comparison   = ComparisonOperator.eq,
                value        = pid,
                propertyName = Property.ProcessID
            };
            PropertyFilter idFilter = new PropertyFilter
            {
                value        = "BENCH",
                comparison   = ComparisonOperator.eq,
                propertyName = Property.MessageID
            };
            SeverityFilter sevFilter = new SeverityFilter
            {
                comparison = ComparisonOperator.eq,
                severity   = SyslogSeverity.Notice
            };

            using (ILogClient client = ClientHelper.CreateReliableClient(hostFilter & pidFilter & idFilter & sevFilter & facFilter))
            {
                client.MessageReceived += client_MessageReceived;
                client.Start();

                for (int i = 0; i < _expected; i++)
                {
                    if (timeout > 0)
                    {
                        Nanosleep(timeout);
                    }
                    SyslogMessage message = new SyslogMessage
                    {
                        Timestamp = DateTime.Now,
                        Facility  = SyslogFacility.Local4,
                        Severity  = SyslogSeverity.Notice,
                        Host      = host,
                        ProcessID = pid,
                        MessageId = "BENCH",
                        Text      = i.ToString()
                    };

                    server.SubmitMessage(message);
                }
                silenceTimer = new Timer(state => Stop.Set(), null, 40000, Timeout.Infinite);
                Console.WriteLine("Waiting up to 30 seconds after last message received...");
                Stop.WaitOne();
            }

            if (_expected == _received)
            {
                Console.WriteLine("Received all messaged");
            }
            else
            {
                Console.WriteLine("Lost {0} messages", _expected - _received);
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            bool reliable = args != null && args.Length > 0 && args[0] == "--reliable";

            Console.CancelKeyPress += Console_CancelKeyPress;

            Console.WriteLine("This program periodically measures the RTT for log messages sent by here");

            if (!reliable)
            {
                Console.WriteLine("Going in unreliable mode. Messages are subject to loss.");
                Console.WriteLine("Use the --reliable switch to go into reliable mode, where messages don't get lost.");
            }
            else
            {
                Console.WriteLine("Reliable mode activated. No messages will be lost because of the network.");
            }

            PropertyFilter hostFilter = new PropertyFilter
            {
                comparison   = ComparisonOperator.eq,
                value        = Dns.GetHostName(),
                propertyName = Property.Host
            };
            PropertyFilter pidFilter = new PropertyFilter
            {
                comparison = ComparisonOperator.eq,
                value      =
                    Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture),
                propertyName = Property.ProcessID
            };
            PropertyFilter idFilter = new PropertyFilter
            {
                value        = "RTT",
                comparison   = ComparisonOperator.eq,
                propertyName = Property.MessageID
            };

            _target = CollectorHelper.CreateCollector((reliable) ? "tls" : "udp");
            FilterBase filter = hostFilter & pidFilter & idFilter;

            _source = (reliable) ? ClientHelper.CreateReliableClient(filter) : ClientHelper.CreateUnreliableClient(filter);
            _log    = LoggerHelper.GetLogger("Logfile");

            _source.MessageReceived += source_MessageReceived;
            _source.Start();

            while (true)
            {
                _id++;
                DateTime      curTimestamp = DateTime.UtcNow;
                double        millis       = (curTimestamp - DateTime.Today).TotalMilliseconds;
                string        text         = _id.ToString(CultureInfo.InvariantCulture) + "_" + millis.ToString(CultureInfo.InvariantCulture);
                SyslogMessage message      = new SyslogMessage(SyslogFacility.Local3, SyslogSeverity.Notice, text)
                {
                    MessageId = "RTT"
                };

                _target.SubmitMessage(message);

                if (!_ar.WaitOne(10000))
                {
                    Console.WriteLine("RTT sent at {0} lost", curTimestamp);
                    _log.Warning("RTT sent at {0} lost", curTimestamp);
                    continue;
                }
                Thread.Sleep(3000);
            }
        }