Esempio n. 1
0
        public ConfigHelper()
        {
            var path = Assembly.GetExecutingAssembly().Location;

            ApplicationPath = Path.GetDirectoryName(path);
            InitializeLoggingConfiguration();

            eventLogFields           = typeof(LogRecordCdoc).GetFields().Select(f => f.Name).ToArray();
            sentinelCostMetricFields = typeof(SentinelCostMetric).GetFields().Select(g => g.Name).ToArray();

            ServiceName = PipelineCostCommon.GetServiceName();
        }
        public async Task <ActionResult <EventDictionaryList> > PostEventDictionaryItem(EventDictionaryList eventDictionaryList)
        {
            string serviceName = PipelineCostCommon.GetServiceName();

            Stopwatch processingStopwatch = Stopwatch.StartNew();

            Stopwatch conversionStopwatch = Stopwatch.StartNew();
            List <LogRecordSentinel> listLogRecordCdocs =
                eventDictionaryList.EventDictionaryListItems.Select(d => new LogRecordSentinel(d.EventDictionary, null, serviceName)).ToList();

            conversionStopwatch.Stop();

            // Update each record with data
            foreach (EventDictionaryItem xmlItem in eventDictionaryList.EventDictionaryListItems)
            {
                eventsProcessed++;
                xmlItem.ProcessingDateTime = DateTime.UtcNow;
                xmlItem.ProcessingServer   = Environment.MachineName;
            }

            PerformanceCounter dictionaryEventsReceived = new PerformanceCounter("WECEvents", "Dictionary Events Received");

            dictionaryEventsReceived.ReadOnly = false;
            dictionaryEventsReceived.IncrementBy(eventsProcessed);

            //_context.EventDictionaryItems.AddRange(eventDictionaryList.EventDictionaryListItems);
            //await _context.SaveChangesAsync();

            processingStopwatch.Stop();

            Stopwatch dataloadStopwatch = Stopwatch.StartNew();

            configHelper.LoadDataToKusto("EventData", listLogRecordCdocs);
            dataloadStopwatch.Stop();

            PerformanceCounter dictionaryParsingEfficiency = new PerformanceCounter("WECEvents", "Dictionary Parsing Efficiency");

            dictionaryParsingEfficiency.ReadOnly = false;
            dictionaryParsingEfficiency.RawValue = conversionStopwatch.Elapsed.Milliseconds;

            // Kusto upload metric in MS
            PerformanceCounter dictionaryUploadEfficiency = new PerformanceCounter("WECEvents", "Dictionary Upload Efficiency");

            dictionaryUploadEfficiency.ReadOnly = false;
            dictionaryUploadEfficiency.RawValue = dataloadStopwatch.Elapsed.Milliseconds;

            // Decrement Event Counter
            dictionaryEventsReceived.IncrementBy(-1 * eventsProcessed);

            // Set return values
            eventDictionaryList.ProcessingDateTime = DateTime.UtcNow;
            eventDictionaryList.ProcessingServer   = Environment.MachineName;

            List <SentinelCostMetric> metricList = new List <SentinelCostMetric>
            {
                new SentinelCostMetric
                {
                    MachineName  = Environment.MachineName,
                    ServiceName  = configHelper.ServiceName,
                    OccurenceUtc = DateTime.UtcNow,
                    PackageGuid  = eventDictionaryList.EventDictionaryListItems[0].PackageGuid,
                    PackageId    = eventDictionaryList.EventDictionaryListItems[0].PackageId,
                    EventType    = Enum.GetName(typeof(EventType), EventType.Receive),
                    MetricData   = new Dictionary <string, object>()
                    {
                        { "SendType", Enum.GetName(typeof(DataType), dataType) },
                        { "ProcessTime", configHelper.GetStopWatchDictionary(processingStopwatch) },
                        { "DataLoadTime", configHelper.GetStopWatchDictionary(dataloadStopwatch) },
                    }
                }
            };

            configHelper.LoadMetricsToKusto("Metrics", metricList);

            return(CreatedAtAction("GetEventDictionaryItem", new EventDictionaryItem {
                PackageId = eventDictionaryList.PackageId
            }, eventDictionaryList));
        }