public void OnStart() { // Load metrics to instances and measures to metricobjects, from db var metrics = _repository.GetAllMetrics(); var measuresDictionary = _repository.GetAllMeasures(); foreach (var metric in metrics) { if (!measuresDictionary.TryGetValue(metric.ID, out var measures)) { _monik.LogicWarning($"Measures for metric {metric.ID}:{metric.Name}" + $" InstId:{metric.InstanceID} not found"); continue; } var metObj = _autofac.Resolve <IMetricObject>(); metObj.Load(metric, measures); var instance = _sourceCache.GetInstanceById(metObj.Dto.InstanceID); instance?.Metrics.TryAdd(metObj.Dto.Name, metObj); _metrics.TryAdd(metObj, 0); } foreach (var mo in _metrics.Keys) { mo.OnStart(); } _shedulerPerMin.OnStart(); _shedulerPerSec.OnStart(); _monik.ApplicationVerbose("CacheMetric started"); }
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); } }
public void OnStart() { _cleaner.OnStart(); _statist.OnStart(); _monik.ApplicationVerbose("MessageProcessor started"); }
public void OnStart() { // Create context for ActiveQueues var context = new ActiveQueueContext { OnError = (errorMessage) => { _monik.ApplicationError(errorMessage); Thread.Sleep(DelayOnException); }, OnVerbose = (verboseMessage) => { _monik.ApplicationVerbose(verboseMessage); }, OnMeasure = (metricName, value) => { _monik.Measure(metricName, AggregationType.Gauge, value); _monik.Measure(metricName + "All", AggregationType.Accumulator, value); }, OnReceivedMessage = (msg) => { _msgBuffer.Enqueue(msg); _newMessageEvent.Set(); }, OnReceivedMessages = (messages) => { foreach (var msg in messages) { _msgBuffer.Enqueue(msg); } _newMessageEvent.Set(); } }; if (_queueReaderSettings != null) { foreach (var it in _queueReaderSettings) { try { var queue = CreateActiveQueueByType(it.Type); if (queue != null) { _queues.Add(queue); queue.Start(it, context); } else { _monik.ApplicationWarning( $"MessagePump.OnStart cannot initialize {it.Name}: unknown type {it.Type}"); } } catch (Exception ex) { _monik.ApplicationError($"MessagePump.OnStart failed initialization {it.Name}: {ex.Message}"); } } //configure all event sources } // Start message processing _pumpTask = Task.Run(OnProcessTask); _monik.ApplicationVerbose("MessagePump started"); }
public void OnStart() { // 1. Load all sources in memory var sources = _repository.GetAllSources(); foreach (var src in sources) { if (!_sources.ContainsKey(src.Name)) { _sourceMap.Add(src.ID, src); _sources.Add(src.Name, src); } else { _monik.ApplicationError($"Database contains more than one same source name: {src.Name}"); } } // 2. Load all instances in memory var instances = _repository.GetAllInstances(); foreach (var ins in instances) { if (_sourceMap.ContainsKey(ins.SourceID)) { Source src = _sourceMap[ins.SourceID]; string key = GetSourceInstanceKey(src.Name, ins.Name); if (!_sourceInstanceMap.ContainsKey(key)) { ins.SourceRef(src); _instanceMap.Add(ins.ID, ins); _sourceInstanceMap.Add(key, ins); } else { _monik.ApplicationError( $"Database contains more than one the same instance name '{ins.Name}' for the source '{src.Name}'"); } } else { _monik.ApplicationError($"Database doesnt contains source(id={ins.SourceID}) for the instance '{ins.Name}'"); } } // 3. Load all groups in memory var groups = _repository.GetAllGroupsAndFill(); _defaultInstances = new List <int>(); _groups = new Dictionary <short, Group>(); foreach (var it in groups) { if (it.IsDefault) { foreach (var it2 in it.Instances) { if (!_defaultInstances.Contains(it2)) { _defaultInstances.Add(it2); } } } _groups.Add(it.ID, it); } _monik.ApplicationVerbose("CacheSourceInstance started"); }