Ejemplo n.º 1
0
 public static RedisMemoryAnalysis AnalyzeDatabaseMemory(RedisConnectionInfo connectionInfo, int database)
 {
     using (MiniProfiler.Current.Step("Redis Memory Analysis for " + connectionInfo + " - DB:" + database.ToString()))
     {
         return(Current.LocalCache.GetSet <RedisMemoryAnalysis>(GetMemoryAnalysisKey(connectionInfo, database), (old, ctx) => GetDatabaseMemoryAnalysis(connectionInfo, database), 24 * 60 * 60, 24 * 60 * 60));
     }
 }
Ejemplo n.º 2
0
        private static RedisMemoryAnalysis GetDatabaseMemoryAnalysis(RedisConnectionInfo connectionInfo, int database)
        {
            var config = new ConfigurationOptions
            {
                SyncTimeout = 10 * 60 * 1000,
                AllowAdmin  = true,
                ClientName  = "Status-MemoryAnalyzer",
                Password    = connectionInfo.Password,
                EndPoints   =
                {
                    { connectionInfo.Host, connectionInfo.Port }
                }
            };

            using (var muxer = ConnectionMultiplexer.Connect(config))
            {
                var ma = new RedisMemoryAnalysis(connectionInfo, database);
                if (ma.ErrorMessage.HasValue())
                {
                    return(ma);
                }
                // Prep the match dictionary
                foreach (var km in KeyMatchers[connectionInfo])
                {
                    ma.KeyStats[km] = new KeyStats();
                }

                ma.Analyze(muxer);

                return(ma);
            }
        }
 public static RedisInstance Get(RedisConnectionInfo info)
 {
     foreach (var i in RedisModule.Instances)
     {
         if (i.ConnectionInfo == info)
         {
             return(i);
         }
     }
     return(null);
 }
Ejemplo n.º 4
0
 public RedisInstance GetInstance(RedisConnectionInfo info)
 {
     foreach (var i in Instances)
     {
         if (i.ConnectionInfo == info)
         {
             return(i);
         }
     }
     return(null);
 }
Ejemplo n.º 5
0
        public RedisMemoryAnalysis(RedisConnectionInfo connectionInfo, int database)
        {
            CreationDate = DateTime.UtcNow;
            KeyStats     = new ConcurrentDictionary <KeyMatcher, KeyStats>();

            ConnectionInfo = connectionInfo;
            Database       = database;
            if (!RedisAnalyzer.KeyMatchers.TryGetValue(connectionInfo, out var matchers))
            {
                ErrorMessage = "Could not find regexes defined for " + connectionInfo;
                return;
            }
            KeyMatchers = matchers;
            foreach (var km in matchers)
            {
                KeyStats[km] = new KeyStats();
            }
        }
Ejemplo n.º 6
0
        public RedisMemoryAnalysis(RedisAnalyzer analyzer, RedisConnectionInfo connectionInfo, int database)
        {
            CreationDate = DateTime.UtcNow;
            KeyStats     = new ConcurrentDictionary <KeyMatcher, KeyStats>();

            ConnectionInfo = connectionInfo;
            Database       = database;
            KeyMatchers    = analyzer.KeyMatchers;
            if (KeyMatchers.Count == 0)
            {
                ErrorMessage = "Could not find regexes defined for " + connectionInfo;
                return;
            }
            foreach (var km in KeyMatchers)
            {
                KeyStats[km] = new KeyStats();
            }
        }
Ejemplo n.º 7
0
        private static RedisMemoryAnalysis GetDatabaseMemoryAnalysis(RedisConnectionInfo connectionInfo, int database)
        {
            using (var rc = new RedisConnection(connectionInfo.Host, connectionInfo.Port, syncTimeout: 10 * 60 * 1000, allowAdmin: true))
            {
                var ma = new RedisMemoryAnalysis(connectionInfo, database);
                if (ma.ErrorMessage.HasValue())
                {
                    return(ma);
                }
                // Prep the match dictionary
                foreach (var km in KeyMatchers[connectionInfo])
                {
                    ma.KeyStats[km] = new KeyStats();
                }

                rc.Name = "Status-MemoryAnalyzer";
                rc.Wait(rc.Open());

                ma.Analyze(rc);

                return(ma);
            }
        }
Ejemplo n.º 8
0
 public RedisInstance(RedisConnectionInfo connectionInfo) : base(connectionInfo.Host + ":" + connectionInfo.Port.ToString())
 {
     ConnectionInfo        = connectionInfo;
     ShortHost             = connectionInfo.Host.Split(StringSplits.Period)[0];
     ReplicatesCrossRegion = Current.Settings.Redis.Replication?.CrossRegionNameRegex?.IsMatch(ConnectionInfo.Name) ?? true;
 }
Ejemplo n.º 9
0
 public static void ClearDatabaseMemoryAnalysisCache(RedisConnectionInfo connectionInfo, int database)
 {
     Current.LocalCache.Remove(GetMemoryAnalysisKey(connectionInfo, database));
 }
Ejemplo n.º 10
0
 private static string GetMemoryAnalysisKey(RedisConnectionInfo connectionInfo, int database)
 {
     return($"redis-memory-analysis-{connectionInfo.Host}:{connectionInfo.Port.ToString()}:{database.ToString()}");
 }
Ejemplo n.º 11
0
 public static void AnalyzerInstanceMemory(RedisConnectionInfo connectionInfo)
 {
     //TODO: Get databases, suck in cache for each
 }
Ejemplo n.º 12
0
 public RedisInstance(RedisConnectionInfo connectionInfo) : base(connectionInfo.Host + ":" + connectionInfo.Port.ToString())
 {
     ConnectionInfo = connectionInfo;
     ShortHost      = Host.Split(StringSplits.Period).First();
 }
Ejemplo n.º 13
0
 public RedisInstance(RedisConnectionInfo connectionInfo) : base(connectionInfo.Host + ":" + connectionInfo.Port)
 {
     ConnectionInfo = connectionInfo;
 }
Ejemplo n.º 14
0
 public static RedisInstance GetInstance(RedisConnectionInfo info)
 {
     return AllInstances.FirstOrDefault(ri => ri.ConnectionInfo == info);
 }
Ejemplo n.º 15
0
 public static RedisInstance GetInstance(RedisConnectionInfo info)
 {
     return(AllInstances.FirstOrDefault(ri => ri.ConnectionInfo == info));
 }
Ejemplo n.º 16
0
 private static string GetMemoryAnalysisKey(RedisConnectionInfo connectionInfo, int database)
 {
     return(string.Format("redis-memory-analysis-{0}:{1}:{2}", connectionInfo.Host, connectionInfo.Port, database));
 }