示例#1
0
        public static IList <ResourceManagerMemoryInfo> GetMemoryInfos(int workerId, int pid, IMongoCollection <BsonDocument> collection)
        {
            IList <ResourceManagerMemoryInfo> memoryInfos = new List <ResourceManagerMemoryInfo>();

            string processName = GetProcessName(collection);

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

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

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

            return(memoryInfos);
        }
        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 GenerateMemoryInfoEventHash(ResourceManagerMemoryInfo memoryInfo)
 {
     return(HashHelper.GenerateHashGuid(memoryInfo.Timestamp,
                                        memoryInfo.ProcessName,
                                        memoryInfo.WorkerId,
                                        memoryInfo.ProcessMemoryUtil,
                                        memoryInfo.TotalMemoryUtil,
                                        memoryInfo.Pid));
 }