【问题标题】:Is there a C# implementation of Redis-rdb-tools?是否有 Redis-rdb-tools 的 C# 实现?
【发布时间】:2013-02-21 22:52:15
【问题描述】:

看看Redis-RDB-Tools,似乎有一些有用的功能可以监控你的Redis服务器的健康状况。

ServiceStack.Redis 似乎有一套很好的客户端功能(但我使用的是BookSleeve)。

是否有任何 C# 实现可以为我提供一些基本的健康检查 - 消耗的内存、磁盘使用情况等?

-- 更新--

感谢 BookSleeve 的 GetInfo() 命令,返回以下内容...但是我应该更具体:有没有办法将服务器信息作为参数/对象属性或预打包的解析方式输出值?

这是 GetInfo() 的输出:

"# Server\r\nredis_version:2.6.10\r\nredis_git_sha1:00000000\r\nredis_git_dirty:0\r\nredis_mode:standalone\r\nos:Linux 2.6.32-279.19.1.el6.x86_64 x86_64\r\narch_bits:64\r\nmultiplexing_api:epoll\r\ngcc_version:4.4.6\r\nprocess_id:2492\r\nrun_id:62402d583871f4b83f469917966aed8d163d02f3\r\ntcp_port:6379\r\nuptime_in_seconds:502354\r\nuptime_in_days:5\r\nlru_clock:1928056\r\n\r\n# Clients\r\nconnected_clients:7\r\nclient_longest_output_list:0\r\nclient_biggest_input_buf:175\r\nblocked_clients:0\r\n\r\n# Memory\r\nused_memory:1402576\r\nused_memory_human:1.34M\r\nused_memory_rss:9719808\r\nused_memory_peak:1675192\r\nused_memory_peak_human:1.60M\r\nused_memory_lua:31744\r\nmem_fragmentation_ratio:6.93\r\nmem_allocator:jemalloc-3.2.0\r\n\r\n# Persistence\r\nloading:0\r\nrdb_changes_since_last_save:3035\r\nrdb_bgsave_in_progress:0\r\nrdb_last_save_time:1360955487\r\nrdb_last_bgsave_status:ok\r\nrdb_last_bgsave_time_sec:-1\r\nrdb_current_bgsave_time_sec:-1\r\naof_enabled:0\r\naof_rewrite_in_progress:0\r\naof_rewrite_scheduled:0\r\naof_last_rewrite_time_sec:-1\r\naof_current_rewrite_time_sec:-1\r\naof_last_bgrewrite_status:ok\r\n\r\n# Stats\r\ntotal_connections_received:18822\r\ntotal_commands_processed:12547\r\ninstantaneous_ops_per_sec:3\r\nrejected_connections:0\r\nexpired_keys:0\r\nevicted_keys:0\r\nkeyspace_hits:374\r\nkeyspace_misses:39\r\npubsub_channels:1\r\npubsub_patterns:0\r\nlatest_fork_usec:0\r\n\r\n# Replication\r\nrole:master\r\nconnected_slaves:0\r\n\r\n# CPU\r\nused_cpu_sys:57.82\r\nused_cpu_user:208.63\r\nused_cpu_sys_children:0.00\r\nused_cpu_user_children:0.00\r\n\r\n# Keyspace\r\ndb0:keys=6,expires=0\r\n"

【问题讨论】:

  • 展开:在 BookSleeve 中,连接实例上的GetInfo() 命令返回此信息
  • 更新问题:有没有办法读取/处理单个值?

标签: c#-4.0 redis servicestack booksleeve


【解决方案1】:

关于更新后的问题:那里的信息目前没有公开为“已解析”,但这听起来像是一个合理的补充;我怀疑我会隐藏GetInfo() 方法,将其移至.Server.GetInfo(),并以解析的形式公开它。不过,拆分它的代码已经存在 - 但作为私有方法:RedisConnectionBase.ParseInfo:

static Dictionary<string, string> ParseInfo(string result)
{
    string[] lines = result.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
    var data = new Dictionary<string, string>();
    for (int i = 0; i < lines.Length; i++)
    {
        string line = lines[i];
        if (string.IsNullOrEmpty(line) || line[0] == '#') continue; // 2.6+ can have empty lines, and comment lines
        int idx = line.IndexOf(':');
        if (idx > 0) // double check this line looks about right
        {
            data.Add(line.Substring(0, idx), line.Substring(idx + 1));
        }
    }
    return data;
}

【讨论】:

  • 是的,以解析的形式,它更有意义,因为这些值将可用,而不仅仅是用于显示。
  • 避免修改 BookSleeve 代码,我将该方法添加到我的帮助程序类中。效果很好,谢谢。
  • @ElHaix 我的本地副本现在有(在.Server 下):Task&lt;Dictionary&lt;string, string&gt;&gt; GetInfo(string section = null, bool queueJump = false);
【解决方案2】:

调用Redis's INFO command,它会在redis-server 中提供所有不同的服务器信息统计信息。

这里是 2.5.12 版本的 redis-server 上的 a page dump of all the available stats

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-03-18
    • 1970-01-01
    • 2020-07-03
    • 2019-01-20
    • 1970-01-01
    • 2018-03-17
    • 2021-11-22
    • 2017-01-08
    相关资源
    最近更新 更多