<commit_before>import redis
import sys
import time
import socket

import boundary_plugin

params = boundary_plugin.parse_params()
redis_server = params.get('redis_hostname', 'localhost')
redis_port = int(params.get('redis_port', 6379))
redis_password = params.get('redis_password', None)

if not redis_password:
    redis_password = None
r = redis.Redis(redis_server, redis_port, password=redis_password)

_accum = dict()

def accum(stat_name, new_value):
    global _accum

    try:
        old_value = _accum[stat_name]
    except KeyError:
        _accum[stat_name] = new_value
        return new_value

    diff = new_value - old_value
    _accum[stat_name] = new_value
    return diff

values_to_report = (
    'connected_clients',
    'keyspace_hits',
    'keyspace_misses',
    'expired_keys',
    'evicted_keys',
    'total_commands_processed',
    'total_connections_received',
    'used_memory_rss',
)

while True:
    info = r.info()

    for v in values_to_report:
        boundary_plugin.boundary_report_metric('REDIS_' + v.upper(), accum(v, info[v]))
<commit_msg>* Fixed bug with param.json parsing. * Fixed aggregation issue with some parameters.<commit_after>import redis
import sys
import time
import socket

import boundary_plugin

params = boundary_plugin.parse_params()
redis_server = params.get('redis_hostname', None) or 'localhost'
redis_port = int(params.get('redis_port', None) or 6379)
redis_password = params.get('redis_password', None) or None

if not redis_password:
    redis_password = None
r = redis.Redis(redis_server, redis_port, password=<PASSWORD>)

_accum = dict()

def accum(stat_name, new_value):
    global _accum

    try:
        old_value = _accum[stat_name]
    except KeyError:
        old_value = new_value

    diff = new_value - old_value
    _accum[stat_name] = new_value
    return diff

# List of values returned from Redis' info call to report to Boundary.
# Each value has a boolean specifying whether to aggregate data (i.e. report
# only delta from the previous value) or report the metric as-is.
values_to_report = (
    ('connected_clients', False),
    ('keyspace_hits', True),
    ('keyspace_misses', True),
    ('expired_keys', True),
    ('evicted_keys', True),
    ('total_commands_processed', True),
    ('total_connections_received', True),
    ('used_memory_rss', False),
)

while True:
    info = r.info()

    for v,aggregate in values_to_report:
        val = accum(v, info[v]) if aggregate else info[v]
        boundary_plugin.boundary_report_metric('REDIS_' + v.upper(), val)

{'fraction_non_alphanumeric': 0.10290652003142184, 'fraction_numerical': 0.003142183817753339, 'mean_word_length': 4.114457831325301, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7257840', 'n_tokens_mistral': 864, 'n_tokens_neox': 829, 'n_words': 212}