示例#1
0
def update_config(m2ee, app_name):
    if not is_enabled() or not _is_installed():
        return

    # Telegraf config, taking over defaults from telegraf.conf from the distro
    logging.debug("creating telegraf config")
    _create_config_file(
        {
            "interval": "10s",
            "round_interval": True,
            "metric_batch_size": 1000,
            "metric_buffer_limit": 10000,
            "collection_jitter": "0s",
            "flush_interval": "10s",
            "flush_jitter": "5s",
            "precision": "",
            "debug": False,
            "logfile": "",
            "hostname": util.get_hostname(),
            "omit_hostname": False,
        }
    )

    _write_config("[global_tags]", _get_tags())
    _write_config(
        "[[inputs.statsd]]",
        {
            "protocol": "udp",
            "max_tcp_connections": 250,
            "tcp_keep_alive": False,
            "service_address": ":8125",
            "delete_gauges": True,
            "delete_counters": True,
            "delete_sets": True,
            "delete_timings": True,
            "percentiles": [90],
            "metric_separator": ".",
            "parse_data_dog_tags": True,
            "allowed_pending_messages": 10000,
            "percentile_limit": 1000,
        },
    )

    # Forward metrics also to DataDog when enabled
    if datadog.is_enabled():
        _write_config("[[outputs.datadog]]", {"apikey": datadog.get_api_key()})

    # # Write http_oputs (one or array)
    http_configs = json.loads(_get_appmetrics_target())
    if type(http_configs) is list:
        for http_config in http_configs:
            _write_http_output_config(http_config)
    else:
        _write_http_output_config(http_configs)

    # Enable Java Agent on MxRuntime to
    datadog.enable_mx_java_agent(m2ee)
def update_config(m2ee, app_name):
    if not is_enabled() or not _is_installed():
        return

    # Populate Telegraf config template
    statsd_port = None
    if mx_java_agent.meets_version_requirements(
            m2ee.config.get_runtime_version()):
        statsd_port = get_statsd_port()

    template_path = os.path.join(CONFIG_FILE_DIR, TEMPLATE_FILENAME)

    tags = util.get_tags()
    if datadog.is_enabled() and "service" not in tags:
        # app and / or service tag not set
        tags["service"] = datadog.get_service()

    with open(template_path, "r") as file_:
        template = Template(file_.read(), trim_blocks=True, lstrip_blocks=True)
    rendered = template.render(
        interval=10,  # in seconds
        tags=tags,
        hostname=util.get_hostname(),
        statsd_port=statsd_port,
        db_config=_get_db_config(),
        database_diskstorage_metric_enabled=datadog.
        is_database_diskstorage_metric_enabled(),
        database_rate_count_metrics_enabled=datadog.
        is_database_rate_count_metrics_enabled(),
        datadog_api_key=datadog.get_api_key(),
        datadog_url="{}series/".format(datadog.get_api_url()),
        http_outputs=_get_http_outputs(),
    )

    logging.debug("Writing Telegraf configuration file...")
    with open(CONFIG_FILE_PATH, "w") as file_:
        file_.write(rendered)
    logging.debug("Telegraf configuration file written")
def is_enabled(runtime_version):
    return meets_version_requirements(runtime_version) and (
        telegraf.is_enabled() or datadog.is_enabled())
示例#4
0
def update_config(m2ee, app_name):
    if not is_enabled() or not _is_installed():
        return

    # Telegraf config, taking over defaults from telegraf.conf from the distro
    logging.debug("creating telegraf config")
    _create_config_file(
        {
            "interval": "10s",
            "round_interval": True,
            "metric_batch_size": 1000,
            "metric_buffer_limit": 10000,
            "collection_jitter": "0s",
            "flush_interval": "10s",
            "flush_jitter": "5s",
            "precision": "",
            "debug": False,
            "logfile": "",
            "hostname": util.get_hostname(),
            "omit_hostname": False,
        }
    )

    _write_config("[global_tags]", _get_tags())
    _write_config(
        "[[inputs.statsd]]",
        {
            "protocol": "udp",
            "max_tcp_connections": 250,
            "tcp_keep_alive": False,
            "service_address": ":8125",
            "delete_gauges": True,
            "delete_counters": True,
            "delete_sets": True,
            "delete_timings": True,
            "percentiles": [90],
            "metric_separator": ".",
            "parse_data_dog_tags": True,
            "allowed_pending_messages": 10000,
            "percentile_limit": 1000,
        },
    )

    # Configure postgreSQL input plugin
    if include_db_metrics():
        db_config = database.get_config()
        if db_config:
            _write_config(
                "[[inputs.postgresql]]",
                {
                    "address": "postgres://{}:{}@{}/{}".format(
                        db_config["DatabaseUserName"],
                        db_config["DatabasePassword"],
                        db_config["DatabaseHost"],
                        db_config["DatabaseName"],
                    )
                },
            )

    # Forward metrics also to DataDog when enabled
    if datadog.is_enabled():
        _write_config("[[outputs.datadog]]", {"apikey": datadog.get_api_key()})

    # Write http_outputs (one or array)
    try:
        http_configs = json.loads(_get_appmetrics_target())
    except ValueError:
        logging.error(
            "Invalid APPMETRICS_TARGET set. Please check if it contains valid JSON."
        )
        return
    if type(http_configs) is list:
        for http_config in http_configs:
            _write_http_output_config(http_config)
    else:
        _write_http_output_config(http_configs)
def is_enabled():
    return _get_appmetrics_target() is not None or datadog.is_enabled()
def is_enabled():
    return datadog.is_enabled() or telegraf.is_enabled()