public static IEnumerable <ResourceManagerCpuSample> GetCpuSamples(string workerId, int pid, IMongoCollection <BsonDocument> collection)
        {
            var cpuSamples = new List <ResourceManagerCpuSample>();

            string processName = GetProcessName(collection);

            var filter = Query.And(FilterMessagesByWorkerAndPid(workerId, pid),
                                   Query.Regex("v", new BsonRegularExpression("^Resource Manager: CPU info:")));

            var cpuSampleDocuments = collection.Find(filter).ToEnumerable();

            foreach (var document in cpuSampleDocuments)
            {
                try
                {
                    ResourceManagerCpuSample cpuSample = new ResourceManagerCpuSample(document, processName);
                    cpuSamples.Add(cpuSample);
                }
                catch (Exception ex)
                {
                    Log.Error("Unable to parse CPU sample from " + document, ex);
                }
            }

            return(cpuSamples);
        }
示例#2
0
        private void AddCpuSampleEvent(NativeJsonLogsBaseEvent baseEvent, string message, LogLine logLine, string processName)
        {
            ResourceManagerCpuSample record = null;

            var currentAndTotalMatch = CurrentAndTotalCpuUtilRegex.Match(message);

            if (currentAndTotalMatch.Success)
            {
                record = ResourceManagerCpuSample.GetEventWithNullCheck(
                    baseEvent,
                    logLine,
                    processName,
                    TryParseIntWithLogging(currentAndTotalMatch, "current_process_util", logLine),
                    TryParseIntWithLogging(currentAndTotalMatch, "total_processes_util", logLine)
                    );

                _cpuSamplesWriter.AddLine(record);
                return;
            }

            var currentMatch = CurrentCpuUtilRegex.Match(message);

            if (currentMatch.Success)
            {
                record = ResourceManagerCpuSample.GetEventWithNullCheck(
                    baseEvent,
                    logLine,
                    processName,
                    TryParseIntWithLogging(currentMatch, "current_process_util", logLine),
                    null
                    );

                _cpuSamplesWriter.AddLine(record);
                return;
            }

            _processingNotificationsCollector.ReportError("Failed to process line as CpuSampleEvent.", logLine, nameof(ResourceManagerPlugin));
        }