<commit_before>import time

from checks import AgentCheck
from util import md5
from util import json

from checks.libs.httplib2 import Http, HttpLib2Error
import socket

class Riak(AgentCheck):

    keys = [
        "vnode_gets",
        "vnode_puts",
        "vnode_index_reads",
        "vnode_index_writes",
        "vnode_index_deletes",
        "node_gets",
        "node_puts",
        "pbc_active",
        "pbc_connects",
        "memory_total",
        "memory_processes",
        "memory_processes_used",
        "memory_atom",
        "memory_atom_used",
        "memory_binary",
        "memory_code",
        "memory_ets",
        "read_repairs",
        "node_put_fsm_rejected_60s",
        "node_put_fsm_active_60s",
        "node_put_fsm_in_rate",
        "node_put_fsm_out_rate",
        "node_get_fsm_rejected_60s",
        "node_get_fsm_active_60s",
        "node_get_fsm_in_rate",
        "node_get_fsm_out_rate"
    ]

    stat_keys = [
        "node_get_fsm_siblings",
        "node_get_fsm_objsize",
        "node_get_fsm_time",
        "node_put_fsm_time"
      ]

    def __init__(self, name, init_config, agentConfig, instances=None):
        AgentCheck.__init__(self, name, init_config, agentConfig, instances)
        for k in ["mean", "median", "95", "99", "100"]:
            [self.keys.append(m + "_" + k) for m in self.stat_keys]

        self.prev_coord_redirs_total = -1


    def check(self, instance):
        url             = instance['url']
        default_timeout = self.init_config.get('default_timeout', 5)
        timeout         = float(instance.get('timeout', default_timeout))

        aggregation_key = md5(url).hexdigest()

        try:
            h = Http(timeout=timeout)
            resp, content = h.request(url, "GET")

        except socket.timeout, e:
            self.timeout_event(url, timeout, aggregation_key)
            return

        except socket.error, e:
            self.timeout_event(url, timeout, aggregation_key)
            return

        except HttpLib2Error, e:
            self.timeout_event(url, timeout, aggregation_key)
            return

        if resp.status != 200:
            self.status_code_event(url, r, aggregation_key)

        stats = json.loads(content)

        [self.gauge("riak." + k, stats[k]) for k in self.keys if k in stats]

        coord_redirs_total = stats["coord_redirs_total"]
        if self.prev_coord_redirs_total > -1:
            count = coord_redirs_total - self.prev_coord_redirs_total
            self.gauge('riak.coord_redirs', count)<commit_msg>Fix bad variable name in risk check<commit_after>import time

from checks import AgentCheck
from util import md5
from util import json

from checks.libs.httplib2 import Http, HttpLib2Error
import socket

class Riak(AgentCheck):

    keys = [
        "vnode_gets",
        "vnode_puts",
        "vnode_index_reads",
        "vnode_index_writes",
        "vnode_index_deletes",
        "node_gets",
        "node_puts",
        "pbc_active",
        "pbc_connects",
        "memory_total",
        "memory_processes",
        "memory_processes_used",
        "memory_atom",
        "memory_atom_used",
        "memory_binary",
        "memory_code",
        "memory_ets",
        "read_repairs",
        "node_put_fsm_rejected_60s",
        "node_put_fsm_active_60s",
        "node_put_fsm_in_rate",
        "node_put_fsm_out_rate",
        "node_get_fsm_rejected_60s",
        "node_get_fsm_active_60s",
        "node_get_fsm_in_rate",
        "node_get_fsm_out_rate"
    ]

    stat_keys = [
        "node_get_fsm_siblings",
        "node_get_fsm_objsize",
        "node_get_fsm_time",
        "node_put_fsm_time"
      ]

    def __init__(self, name, init_config, agentConfig, instances=None):
        AgentCheck.__init__(self, name, init_config, agentConfig, instances)
        for k in ["mean", "median", "95", "99", "100"]:
            [self.keys.append(m + "_" + k) for m in self.stat_keys]

        self.prev_coord_redirs_total = -1


    def check(self, instance):
        url             = instance['url']
        default_timeout = self.init_config.get('default_timeout', 5)
        timeout         = float(instance.get('timeout', default_timeout))

        aggregation_key = md5(url).hexdigest()

        try:
            h = Http(timeout=timeout)
            resp, content = h.request(url, "GET")

        except socket.timeout, e:
            self.timeout_event(url, timeout, aggregation_key)
            return

        except socket.error, e:
            self.timeout_event(url, timeout, aggregation_key)
            return

        except HttpLib2Error, e:
            self.timeout_event(url, timeout, aggregation_key)
            return

        if resp.status != 200:
            self.status_code_event(url, resp, aggregation_key)

        stats = json.loads(content)

        [self.gauge("riak." + k, stats[k]) for k in self.keys if k in stats]

        coord_redirs_total = stats["coord_redirs_total"]
        if self.prev_coord_redirs_total > -1:
            count = coord_redirs_total - self.prev_coord_redirs_total
            self.gauge('riak.coord_redirs', count)
{'fraction_non_alphanumeric': 0.10180687779288906, 'fraction_numerical': 0.010102972605401205, 'mean_word_length': 2.2852584556477344, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4353987', 'n_tokens_mistral': 1723, 'n_tokens_neox': 1645, 'n_words': 309}