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 }); } }
private void PersistThresholds(int workerId, IMongoCollection <BsonDocument> collection) { IList <BsonDocument> startEvents = MongoQueryHelper.GetSrmStartEventsForWorker(workerId, collection); foreach (var srmStartEvent in startEvents) { ResourceManagerThreshold threshold = MongoQueryHelper.GetThreshold(srmStartEvent, collection); threshold.LogsetHash = logsetHash; resourceManagerPersister.Enqueue(threshold); } }
public static ResourceManagerThreshold GetThreshold(BsonDocument srmStartEvent, IMongoCollection <BsonDocument> collection) { long totalMemoryLimit = GetTotalMemoryLimit(srmStartEvent, collection); long processMemoryLimit = GetPerProcessMemoryLimit(srmStartEvent, collection); int cpuLimit = GetCpuLimit(srmStartEvent, collection); string processName = GetProcessName(collection); ResourceManagerThreshold threshold = new ResourceManagerThreshold(srmStartEvent, processName, cpuLimit, processMemoryLimit, totalMemoryLimit); return(threshold); }
protected static Guid GenerateThresholdEventHash(ResourceManagerThreshold threshold) { return(HashHelper.GenerateHashGuid(threshold.Timestamp, threshold.ProcessName, threshold.ProcessId, threshold.WorkerId, threshold.Pid, threshold.CpuLimit, threshold.PerProcessMemoryLimit, threshold.TotalMemoryLimit)); }
private void AddTotalMemoryLimitEvent(NativeJsonLogsBaseEvent baseEvent, string message, LogLine logLine, string processName) { var match = MemoryLimitRegex.Match(message); if (match.Success) { var record = ResourceManagerThreshold.GetTotalMemoryLimitRecord( baseEvent, logLine, processName, TryParseLongWithLogging(match, "memory_limit", logLine) ); _thresholdsWriters.AddLine(record); return; } _processingNotificationsCollector.ReportError("Failed to process line as TotalMemoryMemoryLimitEvent.", logLine, nameof(ResourceManagerPlugin)); }