Пример #1
0
def main(): 
    usage = """usage: %prog [options] /path/to/dump.rdb

Example 1 : %prog -k "user.*" -k "friends.*" -f memoryreport.html /var/redis/6379/dump.rdb
Example 2 : %prog /var/redis/6379/dump.rdb"""

    parser = OptionParser(usage=usage)

    parser.add_option("-f", "--file", dest="output",
                  help="Output file", metavar="FILE")
    parser.add_option("-k", "--key", dest="keys", action="append",
                  help="Keys that should be grouped together. Multiple regexes can be provided")
    
    (options, args) = parser.parse_args()
    
    if len(args) == 0:
        parser.error("Redis RDB file not specified")
    dump_file = args[0]
    
    if not options.output:
        output = "redis_memory_report.html"
    else:
        output = options.output

    stats = StatsAggregator()
    callback = MemoryCallback(stats, 64)
    parser = RdbParser(callback)
    parser.parse(dump_file)
    stats_as_json = stats.get_json()
    
    t = open(os.path.join(os.path.dirname(__file__),"report.html.template")).read()
    report_template = Template(t)
    html = report_template.substitute(REPORT_JSON = stats_as_json)
    print(html)
Пример #2
0
def main():
    usage = """usage: %prog [options] /path/to/dump.rdb

Example 1 : %prog -k "user.*" -k "friends.*" -f memoryreport.html /var/redis/6379/dump.rdb
Example 2 : %prog /var/redis/6379/dump.rdb"""

    parser = OptionParser(usage=usage)

    parser.add_option("-f",
                      "--file",
                      dest="output",
                      help="Output file",
                      metavar="FILE")
    parser.add_option(
        "-k",
        "--key",
        dest="keys",
        action="append",
        help=
        "Keys that should be grouped together. Multiple regexes can be provided"
    )

    (options, args) = parser.parse_args()

    if len(args) == 0:
        parser.error("Redis RDB file not specified")
    dump_file = args[0]

    if not options.output:
        output = "redis_memory_report.html"
    else:
        output = options.output

    stats = StatsAggregator()
    callback = MemoryCallback(stats, 64)
    parser = RdbParser(callback)
    parser.parse(dump_file)
    stats_as_json = stats.get_json()

    with open(os.path.join(TEMPLATES_DIR, "report.html.template"), 'r') as t:
        report_template = Template(t.read())

    html = report_template.substitute(REPORT_JSON=stats_as_json)

    with open(output, 'w') as f:
        f.write(html)
class TestStatsAggregator(TestCase):

    def setUp(self):
        self._stats = StatsAggregator()

    def test_add_aggregate(self):
        self._stats.add_aggregate('type_count', 'hash', 1)
        self._stats.add_aggregate('type_count', 'hash', 2)

        self.assertEqual(3, self._stats.aggregates['type_count']['hash'])

    def test_add_histogram(self):
        self._stats.add_histogram('hash_length', 12)
        self.assertEqual(1, self._stats.histograms['hash_length'][12])

        self._stats.add_histogram('hash_length', 12)
        self.assertEqual(2, self._stats.histograms['hash_length'][12])

    def test_add_scatter(self):
        self._stats.add_scatter('set_memory_by_length', 8, 32)
        self.assertEqual([[8, 32]],
                         self._stats.scatters['set_memory_by_length'])
 def setUp(self):
     self._stats = StatsAggregator()