Beispiel #1
0
        public async Task Upload(object metricsBody, string eventType)
        {
            try
            {
                var payload = new MetricsMessage
                {
                    Application   = _config.Application,
                    Body          = metricsBody,
                    CorrelationId = _correlationId,
                    Environment   = _config.Environment,
                    EventType     = eventType,
                };

                var serializedPayload = JsonConvert.SerializeObject(payload, _jsonSerializerSettings);

                var response = await Retry.DoWithRetries <FlurlHttpException, HttpResponseMessage>(nameof(MetricUploader), _logger, async() =>
                                                                                                   await _config.EndpointUrl
                                                                                                   .WithTimeout(_config.UploadTimeout)
                                                                                                   .PostAsync(new StringContent(serializedPayload, Encoding.UTF8, "application/json")));

                if (!response.IsSuccessStatusCode)
                {
                    _logger.LogWarning("Successful status code not returned from telemetry upload.");
                }
            }
            catch (Exception ex)
            {
                _logger.LogWarning(ex, "Exception occurred during telemetry upload.");
            }
        }
Beispiel #2
0
 public void Handle(MetricsMessage message)
 {
     database.Measurements.AddRange(message.Measurements);
 }
Beispiel #3
0
 public void Handle(MetricsMessage message)
 {
     lastHearbeat = message.Timestamp;
 }