Exemplo n.º 1
0
        public static IList <ResourceManagerAction> GetActions(int workerId, int pid, IMongoCollection <BsonDocument> collection)
        {
            IList <ResourceManagerAction> actions = new List <ResourceManagerAction>();

            string processName = GetProcessName(collection);

            var filter = Query.And(
                FilterMessagesByWorkerAndPid(workerId, pid),
                Query.Or(
                    Query.Regex("v", new BsonRegularExpression(ResourceManagerAction.CpuUsageExceededRegex)),
                    Query.Regex("v", new BsonRegularExpression(ResourceManagerAction.ProcessMemoryUsageExceededRegex)),
                    Query.Regex("v", new BsonRegularExpression(ResourceManagerAction.TotalMemoryUsageExceededRegex))
                    )
                );

            var memoryInfoDocuments = collection.Find(filter).ToList();

            foreach (var document in memoryInfoDocuments)
            {
                try
                {
                    ResourceManagerAction memoryInfo = new ResourceManagerAction(document, processName);
                    actions.Add(memoryInfo);
                }
                catch (Exception ex)
                {
                    Log.Error("Unable to parse memoryInfo from " + document, ex);
                }
            }

            return(actions);
        }
        public static InsertionResult PersistResourceManagerInfo(IPluginRequest pluginRequest, IDbConnection dbConnection, ResourceManagerEvent resourceManagerInfo)
        {
            try
            {
                if (resourceManagerInfo is ResourceManagerCpuInfo)
                {
                    ResourceManagerCpuInfo cpuInfo = resourceManagerInfo as ResourceManagerCpuInfo;
                    cpuInfo.EventHash = GenerateCpuInfoEventHash(cpuInfo);
                    dbConnection.Insert(cpuInfo);
                }
                else if (resourceManagerInfo is ResourceManagerMemoryInfo)
                {
                    ResourceManagerMemoryInfo memoryInfo = resourceManagerInfo as ResourceManagerMemoryInfo;
                    memoryInfo.EventHash = GenerateMemoryInfoEventHash(memoryInfo);
                    dbConnection.Insert(memoryInfo);
                }
                else if (resourceManagerInfo is ResourceManagerAction)
                {
                    ResourceManagerAction actionEvent = resourceManagerInfo as ResourceManagerAction;
                    actionEvent.EventHash = GenerateActionEventHash(actionEvent);
                    dbConnection.Insert(actionEvent);
                }
                else if (resourceManagerInfo is ResourceManagerThreshold)
                {
                    ResourceManagerThreshold threshold = resourceManagerInfo as ResourceManagerThreshold;
                    threshold.EventHash = GenerateThresholdEventHash(threshold);
                    dbConnection.Insert(threshold);
                }

                return(new InsertionResult
                {
                    SuccessfulInserts = 1,
                    FailedInserts = 0
                });
            }
            catch (PostgresException ex)
            {
                // Log an error only if this isn't a duplicate key exception.
                if (!ex.SqlState.Equals(PluginLibConstants.POSTGRES_ERROR_CODE_UNIQUE_VIOLATION))
                {
                    Log.ErrorFormat("Failed to persist ResourceManagerInfo event '{0}': {1}", resourceManagerInfo.EventHash, ex.Message);
                }

                return(new InsertionResult
                {
                    SuccessfulInserts = 0,
                    FailedInserts = 1
                });
            }
            catch (NpgsqlException ex)
            {
                Log.ErrorFormat("Failed to persist ResourceManagerInfo event '{0}': {1}", resourceManagerInfo.EventHash, ex.Message);

                return(new InsertionResult
                {
                    SuccessfulInserts = 0,
                    FailedInserts = 1
                });
            }
        }
 protected static Guid GenerateActionEventHash(ResourceManagerAction actionEvent)
 {
     return(HashHelper.GenerateHashGuid(actionEvent.Timestamp,
                                        actionEvent.ProcessName,
                                        actionEvent.WorkerId,
                                        actionEvent.CpuUtil,
                                        actionEvent.ProcessMemoryUtil,
                                        actionEvent.TotalMemoryUtil,
                                        actionEvent.Pid,
                                        actionEvent.CpuUtilTermination,
                                        actionEvent.ProcessMemoryUtilTermination,
                                        actionEvent.TotalMemoryUtilTermination));
 }
Exemplo n.º 4
0
        private void AddActionEvent(NativeJsonLogsBaseEvent baseEvent, string message, LogLine logLine, string processName)
        {
            ResourceManagerAction record = null;

            var cpuUsageMatch = CpuUsageExceededRegex.Match(message);

            if (cpuUsageMatch.Success)
            {
                record = ResourceManagerAction.GetCpuTerminationEvent(
                    baseEvent,
                    logLine,
                    processName,
                    TryParseIntWithLogging(cpuUsageMatch, "process_cpu_util", logLine)
                    );
            }

            var processMemoryUsageMatch = ProcessMemoryUsageExceededRegex.Match(message);

            if (processMemoryUsageMatch.Success)
            {
                record = ResourceManagerAction.GetProcessMemoryTerminationEvent(
                    baseEvent,
                    logLine,
                    processName,
                    TryParseLongWithLogging(processMemoryUsageMatch, "process_usage", logLine)
                    );
            }

            var totalMemoryUsageMatch = TotalMemoryUsageExceededRegex.Match(message);

            if (totalMemoryUsageMatch.Success)
            {
                record = ResourceManagerAction.GetTotalMemoryTerminationEvent(
                    baseEvent,
                    logLine,
                    processName,
                    TryParseLongWithLogging(totalMemoryUsageMatch, "process_usage", logLine, true),
                    TryParseLongWithLogging(totalMemoryUsageMatch, "tableau_usage", logLine, true),
                    TryParseLongWithLogging(totalMemoryUsageMatch, "total_usage", logLine)
                    );
            }

            if (record != null)
            {
                _actionsWriter.AddLine(record);
                return;
            }

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