コード例 #1
0
 def test_send1(self):
     orig_constructor = socket.socket
     socket.socket = functools.partial(fake_socket_constructor,
                                       FakeSocketObject)
     client = TelegrafUnixSocketClient("/foo/bar")
     client.connect(bypass_unix_socket_check=True)
     client.send_measurement("foo", {"field1": 1.23, "field2": 4.56})
     self.assertEquals(client._sock.sended,
                       b'foo field1=1.23,field2=4.56\n')
     client.close()
     socket.socket = orig_constructor
コード例 #2
0
    if x:
        return int(x.stdout)


while True:
    LOGGER.debug("waiting 10s...")
    time.sleep(10)
    client = TelegrafUnixSocketClient(SOCKET_PATH)
    try:
        client.connect()
    except Exception:
        LOGGER.warning("can't connect, wait 10s and try again...")
        continue
    var_in_directories = get_var_in_directories()
    data = {}
    for directory in var_in_directories:
        count = None
        try:
            count = get_file_count(directory)
        except Exception:
            pass
        if count is None:
            continue
        data["file_count"] = count
        msg = client.send_measurement(
            "var_in_files",
            data,
            extra_tags={"directory_name": os.path.basename(directory)})
        LOGGER.debug("sended msg: %s" % msg)
    client.close()
コード例 #3
0
    LOGGER.debug("waiting 10s...")
    time.sleep(10)
    client = TelegrafUnixSocketClient(SOCKET_PATH)
    try:
        client.connect()
    except Exception:
        LOGGER.warning("can't connect to %s, wait 10s and try again...",
                       SOCKET_PATH)
        continue
    stats = psutil.disk_io_counters(perdisk=False)
    new_dt = datetime.now()
    new_read_bytes = stats.read_bytes
    new_write_bytes = stats.write_bytes
    if first:
        first = False
    else:
        delta = (new_dt - old_dt).total_seconds()
        read_bytes_per_second = (new_read_bytes - old_read_bytes) / delta
        write_bytes_per_second = (new_write_bytes - old_write_bytes) / delta
        if read_bytes_per_second >= 0 and write_bytes_per_second >= 0:
            data = {
                "read_bytes_per_second": read_bytes_per_second,
                "write_bytes_per_second": write_bytes_per_second
            }
            msg = client.send_measurement("custom_diskio", data)
            LOGGER.debug("sended msg: %s" % msg)
    old_dt = new_dt
    old_read_bytes = new_read_bytes
    old_write_bytes = new_write_bytes
    client.close()
コード例 #4
0
    if not results:
        LOGGER.warning("can't execute %s: %s" % (CMD, results))
        return None
    lines = results.stdout.splitlines()
    stats = {x: 0 for x in STATES_VALUES}
    for line in lines[1:]:
        tmp = line.strip().split()
        if tmp[0] not in STATES_KEYS:
            stats["tcp_none"] = stats.get("tcp_none") + 1
            continue
        stats[STATES[tmp[0]]] = stats.get(STATES[tmp[0]]) + 1
    stats["tcp_total"] = sum(stats.values())
    return stats


while True:
    LOGGER.debug("waiting 10s...")
    time.sleep(10)
    client = TelegrafUnixSocketClient(SOCKET_PATH)
    try:
        client.connect()
    except Exception:
        LOGGER.warning("can't connect to %s, wait 10s and try again...",
                       SOCKET_PATH)
        continue
    stats = get_stats()
    if stats:
        msg = client.send_measurement("custom_netstat", stats)
        LOGGER.debug("sended msg: %s" % msg)
    client.close()
コード例 #5
0
                stats[plugin][key] = sum([
                    x[key] for x in processes if x['plugin'] == search_plugin
                    and not is_cmdline_monitoring(x['cmdline'])
                ])
            else:
                stats[plugin][key] = sum([
                    x[key] for x in processes if x['plugin'] == search_plugin
                    and is_cmdline_monitoring(x['cmdline'])
                ])
    return stats


while True:
    LOGGER.debug("waiting 10s...")
    time.sleep(10)
    client = TelegrafUnixSocketClient(SOCKET_PATH)
    try:
        client.connect()
    except Exception:
        LOGGER.warning("can't connect to %s, wait 10s and try again...",
                       SOCKET_PATH)
        continue
    stats = get_stats()
    if stats:
        for plugin, fields_dict in stats.items():
            msg = client.send_measurement("metwork_module",
                                          fields_dict,
                                          extra_tags={"plugin": plugin})
            LOGGER.debug("sended msg: %s" % msg)
    client.close()
コード例 #6
0
            dropin_percent = 100.0 * dropin_per_second \
                / packets_recv_per_second
            dropin_percent = min(max(0.0, dropin_percent), 100.0)
            dropout_percent = 100.0 * dropout_per_second \
                / packets_sent_per_second
            dropout_percent = min(max(0.0, dropout_percent), 100.0)
            data = {
                "bytes_sent_per_second": bytes_sent_per_second,
                "bytes_recv_per_second": bytes_recv_per_second,
                "packets_sent_per_second": packets_sent_per_second,
                "packets_recv_per_second": packets_recv_per_second,
                "errin_per_second": errin_per_second,
                "errout_per_second": errout_per_second,
                "dropin_per_second": dropin_per_second,
                "dropout_per_second": dropout_per_second,
                "dropin_percent": dropin_percent,
                "dropout_percent": dropout_percent
            }
            msg = client.send_measurement("custom_netio", data)
            LOGGER.debug("sended msg: %s" % msg)
    old_dt = new_dt
    old_bytes_sent = new_bytes_sent
    old_bytes_recv = new_bytes_recv
    old_packets_sent = new_packets_sent
    old_packets_recv = new_packets_recv
    old_errin = new_errin
    old_errout = new_errout
    old_dropin = new_dropin
    old_dropout = new_dropout
    client.close()
コード例 #7
0
while True:
    LOGGER.debug("waiting 10s...")
    time.sleep(10)
    client = TelegrafUnixSocketClient(SOCKET_PATH)
    try:
        client.connect()
    except Exception:
        LOGGER.warning("can't connect to %s, wait 10s and try again...",
                       SOCKET_PATH)
        continue
    stats = get_stats()
    if stats:
        for plugin, fields_dict in stats.items():
            msg = client.send_measurement("metwork_module",
                                          fields_dict,
                                          extra_tags={"plugin": plugin})
            LOGGER.debug("sended msg: %s" % msg)
    versions = get_versions()
    status = get_status()
    msg = client.send_measurement("metwork_version", {
        "version": versions["mfext_version"],
        "status": "ok",
        "os_name": versions["os_name"]
    },
                                  extra_tags={
                                      "bypassbasicstats": "1",
                                      "modname": "mfext"
                                  })
    LOGGER.debug("sended msg: %s" % msg)
    msg = client.send_measurement("metwork_version", {