コード例 #1
0
ファイル: statsd.py プロジェクト: zeroc0d3/integrations-core
    def check(self, instance):
        host = instance.get("host", "localhost")
        port = instance.get("port", 8126)
        timeout = float(instance.get('timeout', 10))
        tags = instance.get("tags", [])
        tags = ["host:{0}".format(host), "port:{0}".format(port)] + tags

        # Is it up?
        health = self._send_command(host, port, timeout, "health",
                                    tags).getvalue().strip()
        if health == b"health: up":
            self.service_check(SERVICE_CHECK_NAME_HEALTH, AgentCheck.OK, tags)
        else:
            self.service_check(SERVICE_CHECK_NAME_HEALTH, AgentCheck.CRITICAL,
                               tags)

        # Get general stats
        stats = self._send_command(host, port, timeout, "stats", tags)
        stats.seek(0)
        for l in stats.readlines():
            parts = l.strip().split(b":")
            if len(parts) == 2:
                # Uptime isn't a gauge. Since we have only one exception, this
                # seems fine. If we make more a lookup table might be best.
                if parts[0] == b"bad_lines_seen":
                    self.monotonic_count("statsd.{0}".format(
                        ensure_unicode(parts[0])),
                                         float(parts[1]),
                                         tags=tags)
                else:
                    self.gauge("statsd.{0}".format(ensure_unicode(parts[0])),
                               float(parts[1]),
                               tags=tags)

        counters = len(
            self._send_command(host, port, timeout, "counters",
                               tags).getvalue().splitlines()) - 1
        self.gauge("statsd.counters.count", counters, tags=tags)

        gauges = len(
            self._send_command(host, port, timeout, "gauges",
                               tags).getvalue().splitlines()) - 1
        self.gauge("statsd.gauges.count", gauges, tags=tags)

        timers = len(
            self._send_command(host, port, timeout, "timers",
                               tags).getvalue().splitlines()) - 1
        self.gauge("statsd.timers.count", timers, tags=tags)

        # Send the final service check status
        self.service_check(SERVICE_CHECK_NAME, AgentCheck.OK, tags)
コード例 #2
0
def add_messages(queue_root, queues, in_count):
    for _ in range(10000):
        shuffle(queues)
        rand_queue = sample(queues, 1)[0]
        queue_file = ensure_unicode(binascii.b2a_hex(os.urandom(7)))

        create_file(os.path.join(queue_root, rand_queue, queue_file))

        # keep track of what we put in
        in_count[rand_queue][0] += 1
コード例 #3
0
 def iter_lines(self, **_):
     for elt in self.content.split(b"\n"):
         yield ensure_unicode(elt)
コード例 #4
0
 def iter_lines(self, **_):
     content = self.content.pop(0)
     for elt in content.split("\n"):
         yield ensure_unicode(elt)