Ejemplo n.º 1
0
        private async Task <bool> WriteChunkedOutput(
            IMetricsChunkedOutputFormatter formatter,
            MetricsDataValueSource metricsData,
            CancellationToken cancellationToken = default)
        {
            Logger.Trace("Flushing chunked metrics snapshot");

            var chunks = await formatter.WriteAsync(
                metricsData,
                _options.SocketSettings.MaxUdpDatagramSize,
                cancellationToken);

            var success = true;

            foreach (var chunk in chunks)
            {
                var result = await _socketClient.WriteAsync(chunk, cancellationToken);

                if (!result.Success)
                {
                    Logger.Error(result.ErrorMessage);
                    success = false;
                }
            }

            Logger.Trace(success
                ? "Successfully flushed chunked metrics snapshot"
                : "Flushed chunked metrics snapshot with error(s)");
            return(success);
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        public async Task <bool> FlushAsync(MetricsDataValueSource metricsData, CancellationToken cancellationToken = default(CancellationToken))
        {
            Logger.Trace("Flushing metrics snapshot");

            using (var stream = new MemoryStream())
            {
                await Formatter.WriteAsync(stream, metricsData, cancellationToken);

                var output = Encoding.UTF8.GetString(stream.ToArray());

                var result = await _socketClient.WriteAsync(output, cancellationToken);

                if (result.Success)
                {
                    Logger.Trace("Successfully flushed metrics snapshot");
                    return(true);
                }

                Logger.Error(result.ErrorMessage);

                return(false);
            }
        }