Exemplo n.º 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);
            }
        }
Exemplo n.º 2
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;
                    }
                }
            }
        }
Exemplo n.º 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 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;
            }
        }