Exemple #1
0
        protected override void Write(LogEventInfo logEvent)
        {
            var message = Layout.Render(logEvent);

            if (logEvent.Level == LogLevel.Debug)
            {
                monikClient.ApplicationVerbose(message);
            }
            else if (logEvent.Level == LogLevel.Error)
            {
                monikClient.LogicError(message);
            }
            else if (logEvent.Level == LogLevel.Fatal)
            {
                monikClient.LogicFatal(message);
            }
            else if (logEvent.Level == LogLevel.Info)
            {
                monikClient.LogicInfo(message);
            }
            else if (logEvent.Level == LogLevel.Trace)
            {
                monikClient.LogicVerbose(message);
            }
            else if (logEvent.Level == LogLevel.Warn)
            {
                monikClient.LogicWarning(message);
            }
        }
Exemple #2
0
        public AppModel(IShell shell, IMapper mp, IMonik m)
        {
            this.shell = shell;
            m.LogicVerbose("AppModel.ctor");

            BoxesCache.Connect()
            .Bind(out _boxes)
            .Subscribe();
        }
Exemple #3
0
        public void Connect(ISaveRepository repo)
        {
            ///////////////////
            // Boards AutoSaver
            ///////////////////
            var boardsChanges = Boards.Connect().Publish();

            SubscribeChanged(boardsChanges,
                             bvm =>
            {
                mon.LogicVerbose($"Box.Boards.ItemChanged {bvm.Id}::{bvm.Name}::{bvm.Modified}");
                var bi = mapper.Map <BoardViewModel, Board>(bvm);
                repo.CreateOrUpdateBoard(bi).Wait();
            });

            SubscribeAdded(boardsChanges,
                           bvm =>
            {
                mon.LogicVerbose($"Box.Boards.Add {bvm.Id}::{bvm.Name}");

                var bi = mapper.Map <BoardViewModel, Board>(bvm);
                bi     = repo.CreateOrUpdateBoard(bi).Result;

                bvm.Id = bi.Id;
            });

            SubscribeRemoved(boardsChanges,
                             bvm =>
            {
                mon.LogicVerbose($"Box.Boards.Remove {bvm.Id}::{bvm.Name}");

                repo.DeleteBoard(bvm.Id).Wait();
            });

            boardsChanges.Connect();

            ////////////////////
            // Columns AutoSaver
            ////////////////////
            var columnsChanges = Columns.Connect().Publish();

            SubscribeChanged(columnsChanges,
                             cvm =>
            {
                mon.LogicVerbose($"Box.Columns.ItemChanged {cvm.Id}::{cvm.Name}::{cvm.Order}");
                var ci = mapper.Map <ColumnViewModel, Column>(cvm);
                repo.CreateOrUpdateColumn(ci).Wait();
            });

            SubscribeAdded(columnsChanges,
                           cvm =>
            {
                mon.LogicVerbose($"Box.Columns.Add {cvm.Id}::{cvm.Name}::{cvm.Order}");

                var ci = mapper.Map <ColumnViewModel, Column>(cvm);
                ci     = repo.CreateOrUpdateColumn(ci).Result;

                cvm.Id = ci.Id;
            });

            SubscribeRemoved(columnsChanges,
                             cvm =>
            {
                mon.LogicVerbose($"Box.Columns.Remove {cvm.Id}::{cvm.Name}::{cvm.Order}");

                repo.DeleteColumn(cvm.Id).Wait();
            });


            columnsChanges.Connect();

            /////////////////
            // Rows AutoSaver
            /////////////////
            var rowsChanges = Rows.Connect().Publish();

            SubscribeChanged(rowsChanges,
                             rvm =>
            {
                mon.LogicVerbose($"Box.Rows.ItemChanged {rvm.Id}::{rvm.Name}::{rvm.Order}");
                var row = mapper.Map <RowViewModel, Row>(rvm);
                repo.CreateOrUpdateRow(row).Wait();
            });

            SubscribeAdded(rowsChanges,
                           rvm =>
            {
                mon.LogicVerbose($"Box.Rows.Add {rvm.Id}::{rvm.Name}::{rvm.Order}");

                var ri = mapper.Map <RowViewModel, Row>(rvm);
                ri     = repo.CreateOrUpdateRow(ri).Result;

                rvm.Id = ri.Id;
            });

            SubscribeRemoved(rowsChanges,
                             rvm =>
            {
                mon.LogicVerbose($"Box.Rows.Remove {rvm.Id}::{rvm.Name}::{rvm.Order}");

                repo.DeleteRow(rvm.Id).Wait();
            });

            rowsChanges.Connect();

            //////////////////
            // Cards AutoSaver
            //////////////////
            var cardsChanges = Cards.Connect().Publish();

            SubscribeChanged(cardsChanges,
                             cvm =>
            {
                mon.LogicVerbose($"Box.Cards.ItemChanged {cvm.Id}::{cvm.Header}");
                var iss = mapper.Map <CardViewModel, Card>(cvm);
                repo.CreateOrUpdateCard(iss).Wait();
            });

            SubscribeAdded(cardsChanges,
                           cvm =>
            {
                mon.LogicVerbose($"Box.Cards.Add {cvm.Id}::{cvm.Header}");
                var ci = mapper.Map <CardViewModel, Card>(cvm);
                ci     = repo.CreateOrUpdateCard(ci).Result;

                cvm.Id = ci.Id;
            });

            SubscribeRemoved(cardsChanges,
                             cvm =>
            {
                mon.LogicVerbose($"Box.Cards.Remove {cvm.Id}::{cvm.Header}");

                repo.DeleteCard(cvm.Id).Wait();
            });

            cardsChanges.Connect();
        }
Exemple #4
0
        public void OnNewMeasure(Event metric)
        {
            var metTime = DateTimeOffset.FromUnixTimeMilliseconds(metric.Created).UtcDateTime;

            lock (this)
            {
                var actualIntervalStart = _dto.ActualInterval.AddMinutes(-5);
                var actualIntervalEnd   = _dto.ActualInterval;

                // interval with epsilon
                var intervalStart = actualIntervalStart.AddMilliseconds(-IntervalEpsilon);
                var intervalEnd   = actualIntervalEnd.AddMilliseconds(IntervalEpsilon);
                if ((metTime < intervalStart || metTime > intervalEnd) && (metric.Mc.Name.ToLower() != "outtimemeasure"))
                {
                    // skip event
                    // increase skip metric
                    _monik.Measure("OutTimeMeasure", AggregationType.Accumulator, 1);

                    var ev = NewMeasureEvent(metric.Source, metric.Instance, "OutTimeMeasure", 1, AggregationType.Accumulator);
                    _pump.OnEmbeddedEvents(new Event[1] {
                        ev
                    });

                    var serverTime   = DateTime.UtcNow;
                    var diffInterval = metTime < intervalStart
                        ? (metTime - actualIntervalStart).TotalMilliseconds
                        : (metTime - actualIntervalEnd).TotalMilliseconds;
                    var diffServer = (serverTime - metTime).TotalMilliseconds;
                    _monik.LogicVerbose($@"[OutTime] {metric.Source}.{metric.Instance}::{metric.Mc.Name}, lag:{diffServer}, lagInterval:{diffInterval}, {metric.Created} not in [{new DateTimeOffset(actualIntervalStart).ToUnixTimeMilliseconds()},{new DateTimeOffset(actualIntervalEnd).ToUnixTimeMilliseconds()}), now:{new DateTimeOffset(serverTime).ToUnixTimeMilliseconds()}");
                    return;
                }

                var actualMeasure = GetMeasure(_dto.ActualID);

                switch (metric.Mc.Aggregation)
                {
                case AggregationType.Accumulator:
                    if (actualMeasure.HasValue)
                    {
                        actualMeasure.Value += metric.Mc.Value;
                    }
                    else
                    {
                        actualMeasure.Value    = metric.Mc.Value;
                        actualMeasure.HasValue = true;
                    }

                    AccumWindowCalculator accWin = window as AccumWindowCalculator;
                    if (accWin == null)
                    {
                        window = new AccumWindowCalculator();
                    }

                    window.OnNewValue(metric.Mc.Value);
                    break;

                case AggregationType.Gauge:
                    if (actualMeasure.HasValue)
                    {
                        actualMeasure.Value = (actualMeasure.Value + metric.Mc.Value) / 2;
                    }
                    else
                    {
                        actualMeasure.Value    = metric.Mc.Value;
                        actualMeasure.HasValue = true;
                    }

                    GaugeWindowCalculator gauWin = window as GaugeWindowCalculator;
                    if (gauWin == null)
                    {
                        window = new GaugeWindowCalculator();
                    }

                    window.OnNewValue(metric.Mc.Value);
                    break;

                default:
                    // skip event
                    // increase skip metric
                    break;
                }
            }//lock
        }