Beispiel #1
0
        /// <summary>
        /// I return a singleton instance of a Pacemaker that can be accessed throughout the application. Key is host, port, and clientType.
        /// </summary>
        /// <see cref="Pacemaker"/>
        /// <param name="host">Sensu host address</param>
        /// <param name="port">Sensu port</param>
        /// <param name="clientType">Sensu client</param>
        /// <see cref="ClientType"/>
        /// <seealso cref="SensuUdpClient"/>
        /// <seealso cref="SensuTcpClient"/>
        /// <param name="enrichers">An array of ISensuEnricher that enrich all heartbeats sent</param>
        /// <seealso cref="ISensuEnricher"/>
        /// <returns></returns>
        public static Pacemaker Get(string host, int port, ClientType clientType = ClientType.Udp, params ISensuEnricher[] enrichers)
        {
            if (string.IsNullOrEmpty(host))
            {
                throw new ArgumentNullException(nameof(host));
            }

            var key = new Tuple <string, int, ClientType>(host, port, clientType);

            lock (Locker)
            {
                if (!PaceMakers.ContainsKey(key))
                {
                    Func <ISensuClient> udp    = () => new SensuUdpClient(host, port);
                    Func <ISensuClient> tcp    = () => new SensuTcpClient(host, port);
                    ISensuClient        client = clientType == ClientType.Udp ? udp() : tcp();
                    foreach (var sensuEnricher in enrichers)
                    {
                        client.EnrichWith(sensuEnricher);
                    }
                    PaceMakers.Add(key, new Pacemaker(client));
                }
            }
            return(PaceMakers[key]);
        }
Beispiel #2
0
        /// <summary>
        /// Constructor for Pacemaker
        /// </summary>
        /// <param name="client">The Sensu client used to send the hearbeat</param>
        public Pacemaker(ISensuClient client)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            Client       = client;
            _tokenSource = new CancellationTokenSource();
        }
Beispiel #3
0
        private static ISensuClient Client()
        {
            ISensuClient client = null;

            if (_type == ClientType.Udp)
            {
                client = new SensuUdpClient(_host, _port);
            }
            else
            {
                client = new SensuTcpClient(_host, _port);
            }

            client.EnrichWith(new HostInfoEnricher());
            client.EnrichWith(new AssemblyInfoEnricher());
            return(client);
        }
Beispiel #4
0
 /// <summary>
 /// Constructor for SensuMonitor
 /// </summary>
 /// <param name="sensuClient">The client used to send messages to Sensu</param>
 /// <see cref="SensuClientBase"/>
 /// <seealso cref="SensuUdpClient"/>
 /// <seealso cref="SensuTcpClient"/>
 /// <param name="appName">The name of the application being monitored</param>
 public SensuMonitor(ISensuClient sensuClient, string appName)
 {
     _sensuClient = sensuClient;
     _appName     = appName;
     _sensuClient.Connect();
 }