Example #1
0
        void Snapshot(object isCalledFromTimer)
        {
            if ((bool)isCalledFromTimer && ShutdownCalled) // don't perform timer actions if we're shutting down
            {
                return;
            }

            try
            {
                if (BeforeSerialization != null && BeforeSerialization.GetInvocationList().Length != 0)
                {
                    BeforeSerialization();
                }

                var sw = new Stopwatch();
                sw.Start();
                SerializeMetrics(out var metricsCount, out var bytesWritten);
                sw.Stop();

                var info = new AfterSerializationInfo
                {
                    Count        = metricsCount,
                    BytesWritten = bytesWritten,
                    Duration     = sw.Elapsed,
                };

                AfterSerialization?.Invoke(info);
            }
            catch (Exception ex)
            {
                SendExceptionToHandler(ex);
            }
        }
Example #2
0
        Task SnapshotAsync(bool isCalledFromTimer)
        {
            if (isCalledFromTimer && ShutdownCalled) // don't perform timer actions if we're shutting down
            {
                return(Task.CompletedTask);
            }

            try
            {
                if (BeforeSerialization != null && BeforeSerialization.GetInvocationList().Length != 0)
                {
                    BeforeSerialization();
                }

                IReadOnlyList <MetaData> metadata = Array.Empty <MetaData>();
                if (_hasNewMetadata || DateTime.UtcNow - _lastMetadataFlushTime >= TimeSpan.FromDays(1))
                {
                    metadata = GatherMetaData();
                }

                // prep all metrics for serialization
                var timestamp = DateTime.UtcNow;
                if (_metricsNeedingPreSerialize.Count > 0)
                {
                    Parallel.ForEach(_metricsNeedingPreSerialize, m => m.PreSerializeInternal());
                }

                var sw = new Stopwatch();
                foreach (var endpoint in _endpoints)
                {
                    sw.Restart();
                    SerializeMetrics(endpoint, timestamp, out var metricsCount, out var bytesWritten);
                    // We don't want to send metadata more frequently than the snapshot interval, so serialize it out if we need to
                    if (metadata.Count > 0)
                    {
                        SerializeMetadata(endpoint, metadata);
                    }
                    sw.Stop();

                    AfterSerialization?.Invoke(
                        new AfterSerializationInfo
                    {
                        Endpoint     = endpoint.Name,
                        Count        = metricsCount,
                        BytesWritten = bytesWritten,
                        Duration     = sw.Elapsed,
                    });
                }
            }
            catch (Exception ex)
            {
                SendExceptionToHandler(ex);
            }

            return(Task.CompletedTask);
        }
Example #3
0
        private void Snapshot(object isCalledFromTimer)
        {
            if ((bool)isCalledFromTimer && ShutdownCalled) // don't perform timer actions if we're shutting down
            {
                return;
            }

            if (GetBosunUrl != null)
            {
                BosunUrl = GetBosunUrl();
            }


            try
            {
                if (BeforeSerialization != null && BeforeSerialization.GetInvocationList().Length != 0)
                {
                    BeforeSerialization();
                }

                var sw = new StopwatchStruct();
                sw.Start();
                int metricsCount, bytesWritten;
                SerializeMetrics(out metricsCount, out bytesWritten);
                sw.Stop();

                var info = new AfterSerializationInfo
                {
                    Count                = metricsCount,
                    BytesWritten         = bytesWritten,
                    MillisecondsDuration = sw.GetElapsedMilliseconds(),
                };

                LastSerializationInfo = info;
                AfterSerialization?.Invoke(info);
            }
            catch (Exception ex)
            {
                if (ShouldThrowException(ex))
                {
                    if (HasExceptionHandler)
                    {
                        OnBackgroundException(ex);
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }
Example #4
0
        private void Snapshot(object isCalledFromTimer)
        {
            if ((bool)isCalledFromTimer && ShutdownCalled) // don't perform timer actions if we're shutting down
            {
                return;
            }

            if (GetBosunUrl != null)
            {
                BosunUrl = GetBosunUrl();
            }


            try
            {
                if (BeforeSerialization != null && BeforeSerialization.GetInvocationList().Length != 0)
                {
                    BeforeSerialization();
                }

                var info = new AfterSerializationInfo();
                var sw   = new StopwatchStruct();
                sw.Start();
                var list = GetSerializedMetrics();
                sw.Stop();

                EnqueueMetrics(list);

                info.Count = list.Count;
                info.MillisecondsDuration = sw.GetElapsedMilliseconds();

                LastSerializationInfo = info;
                AfterSerialization?.Invoke(info);
            }
            catch (Exception e)
            {
                if (HasExceptionHandler)
                {
                    OnBackgroundException(e);
                    return;
                }

                throw;
            }
        }
Example #5
0
        private void Snapshot(object isCalledFromTimer)
        {
            if ((bool)isCalledFromTimer && ShutdownCalled) // don't perform timer actions if we're shutting down
            {
                return;
            }

            Debug.WriteLine("BosunReporter: Running metrics snapshot.");
            if (GetBosunUrl != null)
            {
                BosunUrl = GetBosunUrl();
            }

#if DEBUG
            var sw = new Stopwatch();
            sw.Start();
#endif
            try
            {
                if (BeforeSerialization != null && BeforeSerialization.GetInvocationList().Length != 0)
                {
                    BeforeSerialization();
                }

                EnqueueMetrics(GetSerializedMetrics());
            }
            catch (Exception e)
            {
                if (HasExceptionHandler)
                {
                    OnBackgroundException(e);
                    return;
                }

                throw;
            }
#if DEBUG
            sw.Stop();
            Debug.WriteLine("BosunReporter: Metric Snapshot took {0}ms", sw.ElapsedMilliseconds);
#endif
        }