Ejemplo n.º 1
0
 protected virtual void AcceptHeartbeat(MessageEventArgs message)
 {
     try
     {
         HeartbeatResponse response = message.Data.FromJson <HeartbeatResponse>();
         if (response.ResponseStatus == null)
         {
             _heartbeatStatus.AddEvent("null");
         }
         else
         {
             _heartbeatStatus.AddEvent(response.ResponseStatus.Status);
         }
         _acceptHeartbeatLatency.AddValue(DateTimeUtils.CurrentTimeInMilliseconds - _heartbeatAcceptStartTime);
         if (response.ResponseStatus.IsServiceDown())
         {
             _sessionContext.Markdown();
         }
         if (response.ResponseStatus.IsFail())
         {
             _log.Warn("heartbeat failed: " + response.ResponseStatus.Message);
         }
         else if (response.ResponseStatus.isPartialFail())
         {
             _log.Info("heartbeat partial failed: " + response.ResponseStatus.Message);
         }
         Register(response.FailedInstances);
     }
     catch (Exception e)
     {
         _log.Warn("handle heartbeat message failed", e);
     }
 }
Ejemplo n.º 2
0
        protected virtual void SendHeartbeat()
        {
            try
            {
                if (_sessionContext.Value == null)
                {
                    return;
                }

                long   prepareHeartbeatStartTime = DateTimeUtils.CurrentTimeInMilliseconds;
                string message = _instanceRepository.HeartbeatRequest;
                _prepareHeartbeatLatency.AddValue(DateTimeUtils.CurrentTimeInMilliseconds - prepareHeartbeatStartTime);
                if (message == null)
                {
                    _log.Info("heartbeat message is null");
                    _lastHeartbeatTime = DateTimeUtils.CurrentTimeInMilliseconds;
                    return;
                }

                long sendHeartbeatStartTime = DateTimeUtils.CurrentTimeInMilliseconds;
                _sessionContext.Value.Send(message);
                _sendHeartbeatLatency.AddValue(DateTimeUtils.CurrentTimeInMilliseconds - sendHeartbeatStartTime);
                _lastHeartbeatTime        = DateTimeUtils.CurrentTimeInMilliseconds;
                _heartbeatAcceptStartTime = DateTimeUtils.CurrentTimeInMilliseconds;
            }
            catch (Exception e)
            {
                _log.Warn("send heartbeat failed", e);
            }
        }
Ejemplo n.º 3
0
        private void Metric(string filterId, long value)
        {
            if (string.IsNullOrWhiteSpace(filterId))
            {
                return;
            }
            string metricId = "filter-instances." + filterId;

            Dictionary <string, string> metadata = new Dictionary <string, string>();

            metadata["metric_name_distribution"] = _metricNameDistribution;
            metadata["metric_name_audit"]        = _metricNameAudit;
            metadata["filter"] = filterId;

            IAuditMetric metric = _valueMetricManager.GetMetric(metricId, new MetricConfig(metadata));

            metric.AddValue(value);
        }
Ejemplo n.º 4
0
        public void CLogMetricTest()
        {
            string auditMetricName = "Caravan.Metric.Test.CLogMetricTest";
            IAuditMetricManager         manager  = NullAuditMetricManager.Instance;
            Dictionary <string, string> metadata = new Dictionary <string, string>();

            metadata["metric_name_audit"] = auditMetricName.ToLower();
            IAuditMetric auditMetric = manager.GetMetric(auditMetricName.ToLower(), new MetricConfig(metadata));
            bool         isCompleted = false;
            var          task        = Task.Factory.StartNew(() =>
            {
                Random random = new Random();
                while (!isCompleted)
                {
                    auditMetric.AddValue(random.Next(100, 200));
                    Thread.Sleep(10);
                }
            });

            Thread.Sleep(1000 * 60 * 60);
            isCompleted = true;
            task.Wait();
        }