예제 #1
0
def run():
    if not is_enabled():
        return

    if not _is_installed():
        logger.warn(
            "DataDog agent isn"
            "t installed yet but DD_API_KEY is set. " +
            "Please push or restage your app to complete DataDog installation."
        )
        return

    e = dict(os.environ)
    e["DD_HOSTNAME"] = buildpackutil.get_hostname()
    e["DD_API_KEY"] = get_api_key()
    e["LD_LIBRARY_PATH"] = os.path.abspath(".local/datadog/lib/")
    subprocess.Popen(
        (".local/datadog/datadog-agent", "-c", ".local/datadog", "start"),
        env=e,
    )
    # after datadog agent 6.3 is released, a separate process agent might
    # not be necessary any more: https://github.com/DataDog/datadog-process-agent/pull/124
    subprocess.Popen(
        (
            ".local/datadog/process-agent",
            "-logtostderr",
            "-config",
            ".local/datadog/datadog.yaml",
        ),
        env=e,
    )
예제 #2
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
    logger.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": buildpackutil.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_runtime_agent(m2ee)
예제 #3
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
    logger.debug('creating telegraf config')
    _create_config_file({
        'interval': '10s',
        'round_interval': True,
        'metric_batch_size': 1000,
        'metric_buffer_limit': 10000,
        'collection_jitter': '0s',
        'flush_jitter': '10s',
        'precision': '',
        'debug': False,
        'logfile': '',
        'hostname': buildpackutil.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_runtime_agent(m2ee)
예제 #4
0
def run():
    if not is_enabled():
        return

    if not _is_installed():
        logger.warn('DataDog agent isn''t installed yet but DD_API_KEY is set. ' +
                    'Please push or restage your app to complete DataDog installation.')
        return

    e = dict(os.environ)
    e['DD_HOSTNAME'] = buildpackutil.get_hostname()
    e['DD_API_KEY'] = get_api_key()
    e['LD_LIBRARY_PATH'] = os.path.abspath('.local/datadog/lib/')
    subprocess.Popen((
        '.local/datadog/datadog-agent', '-c', '.local/datadog', 'start',
    ), env=e)
    # after datadog agent 6.3 is released, a separate process agent might
    # not be necessary any more: https://github.com/DataDog/datadog-process-agent/pull/124
    subprocess.Popen((
        '.local/datadog/process-agent', '-logtostderr',
        '-config', '.local/datadog/datadog.yaml',
    ), env=e)
예제 #5
0
def update_config(m2ee, app_name):
    if not is_enabled() or not _is_installed():
        return

    tags = buildpackutil.get_tags()
    if buildpackutil.is_appmetrics_enabled():
        statsd_port = 8126
    else:
        statsd_port = 8125
    m2ee.config._conf["m2ee"]["javaopts"].extend(
        [
            "-Dcom.sun.management.jmxremote",
            "-Dcom.sun.management.jmxremote.port=7845",
            "-Dcom.sun.management.jmxremote.local.only=true",
            "-Dcom.sun.management.jmxremote.authenticate=false",
            "-Dcom.sun.management.jmxremote.ssl=false",
            "-Djava.rmi.server.hostname=127.0.0.1",
        ]
    )
    if m2ee.config.get_runtime_version() >= 7.15:
        m2ee.config._conf["logging"].append(
            {
                "type": "tcpjsonlines",
                "name": "DataDogSubscriber",
                "autosubscribe": "INFO",
                "host": "localhost",
                # For MX8 integer is supported again, this change needs to be
                # made when MX8 is GA
                "port": "9032",
            }
        )
    enable_runtime_agent(m2ee)
    subprocess.check_call(("mkdir", "-p", ".local/datadog"))
    with open(".local/datadog/datadog.yaml", "w") as fh:
        config = {
            "dd_url": "https://app.datadoghq.com",
            "api_key": None,  # set via DD_API_KEY instead
            "confd_path": ".local/datadog/conf.d",
            "logs_enabled": True,
            "log_file": "/dev/null",  # will be printed via stdout/stderr
            "hostname": buildpackutil.get_hostname(),
            "tags": tags,
            "process_config": {
                "enabled": "true",  # has to be string
                "log_file": "/dev/null",
            },
            "apm_config": {"enabled": True, "max_traces_per_second": 10},
            "logs_config": {"run_path": ".local/datadog/run"},
            "use_dogstatsd": True,
            "dogstatsd_port": statsd_port,
        }
        fh.write(yaml.safe_dump(config))
    subprocess.check_call(("mkdir", "-p", ".local/datadog/conf.d/mendix.d"))
    subprocess.check_call(("mkdir", "-p", ".local/datadog/run"))
    with open(".local/datadog/conf.d/mendix.d/conf.yaml", "w") as fh:
        config = {
            "logs": [
                {
                    "type": "tcp",
                    "port": "9032",
                    "service": _get_service(),
                    "source": "mendix",
                    "tags": tags,
                }
            ]
        }
        fh.write(yaml.safe_dump(config))
    subprocess.check_call(("mkdir", "-p", ".local/datadog/conf.d/jmx.d"))
    with open(".local/datadog/conf.d/jmx.d/conf.yaml", "w") as fh:
        # jmx beans and values can be inspected with jmxterm
        # download the jmxterm jar into the container
        # and run app/.local/bin/java -jar ~/jmxterm.jar
        #
        # the extra attributes are only available from Mendix 7.15.0+
        config = {
            "init_config": {"collect_default_metrics": True, "is_jmx": True},
            "instances": [
                {
                    "host": "localhost",
                    "port": 7845,
                    "java_bin_path": ".local/bin/java",
                    "java_options": "-Xmx50m -Xms5m",
                    "reporter": "statsd:localhost:{}".format(statsd_port),
                    # 'refresh_beans': 10, # runtime takes time to initialize the beans
                    "conf": [
                        {
                            "include": {
                                "bean": "com.mendix:type=SessionInformation",
                                # NamedUsers = 1;
                                # NamedUserSessions = 0;
                                # AnonymousSessions = 0;
                                "attribute": {
                                    "NamedUsers": {"metrics_type": "gauge"},
                                    "NamedUserSessions": {
                                        "metrics_type": "gauge"
                                    },
                                    "AnonymousSessions": {
                                        "metrics_type": "gauge"
                                    },
                                },
                            }
                        },
                        {
                            "include": {
                                "bean": "com.mendix:type=Statistics,name=DataStorage",
                                # Selects = 1153;
                                # Inserts = 1;
                                # Updates = 24;
                                # Deletes = 0;
                                # Transactions = 25;
                                "attribute": {
                                    "Selects": {"metrics_type": "counter"},
                                    "Updates": {"metrics_type": "counter"},
                                    "Inserts": {"metrics_type": "counter"},
                                    "Deletes": {"metrics_type": "counter"},
                                    "Transactions": {
                                        "metrics_type": "counter"
                                    },
                                },
                            }
                        },
                        {
                            "include": {
                                "bean": "com.mendix:type=General",
                                # Languages = en_US;
                                # Entities = 24;
                                "attribute": {
                                    "Entities": {"metrics_type": "gauge"}
                                },
                            }
                        },
                        {
                            "include": {
                                "bean": "com.mendix:type=JettyThreadPool",
                                # Threads = 8
                                # IdleThreads = 3;
                                # IdleTimeout = 60000;
                                # MaxThreads = 254;
                                # StopTimeout = 30000;
                                # MinThreads = 8;
                                # ThreadsPriority = 5;
                                # QueueSize = 0;
                                "attribute": {
                                    "Threads": {"metrics_type": "gauge"},
                                    "MaxThreads": {"metrics_type": "gauge"},
                                    "IdleThreads": {"metrics_type": "gauge"},
                                    "QueueSize": {"metrics_type": "gauge"},
                                },
                            }
                        },
                    ],
                    #  }, {
                    #    'include': {
                    #        'bean': 'com.mendix:type=Jetty',
                    #        # ConnectedEndPoints = 0;
                    #        # IdleTimeout = 30000;
                    #        # RequestsActiveMax = 0;
                    #        'attribute': {
                    #        }
                    #    },
                }
            ],
        }
        fh.write(yaml.safe_dump(config))

    _set_up_postgres()
예제 #6
0
def _get_service():
    dd_service = os.environ.get("DD_SERVICE")
    if dd_service is None:
        dd_service = buildpackutil.get_hostname()
    return dd_service
예제 #7
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
    logger.debug("creating telegraf config")
    _create_config_file(
        {
            "interval": "10s",
            "round_interval": True,
            "metric_batch_size": 1000,
            "metric_buffer_limit": 10000,
            "collection_jitter": "0s",
            "flush_jitter": "10s",
            "precision": "",
            "debug": False,
            "logfile": "",
            "hostname": buildpackutil.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()})

    # Expose metrics to Azure Application Insights when enabled
    if _get_appmetrics_aai() is not None:
        _write_aai_output_config()
    
    # Collect statistics from Mendix admin port
    _write_mendix_admin_http_input_config("runtime_statistics", "mendix_runtime_memory", "feedback.memory", ["used_heap", "committed_heap", "init_heap", "max_heap", "used_nonheap", "committed_nonheap", "init_nonheap", "max_nonheap"])
    _write_mendix_admin_http_input_config("runtime_statistics", "mendix_runtime_connectionbus", "feedback.connectionbus", ["select", "insert", "update", "delete", "transaction"])
    _write_mendix_admin_http_input_config("runtime_statistics", "mendix_runtime_sessions", "feedback.sessions", ["named_users", "anonymous_sessions", "named_user_sessions"])
    _write_mendix_admin_http_input_config("server_statistics", "mendix_runtime_threads", "feedback.threadpool", ["threads"])
    _write_mendix_admin_http_input_config("server_statistics", "mendix_runtime_connections", "feedback.jetty", ["current_connections"])
    _write_mendix_admin_http_input_config("get_logged_in_user_names", "mendix_runtime_loggedinusers", "feedback", ["count"])
    _write_mendix_admin_http_named_input_config("runtime_statistics", "mendix_runtime_requests_", "name", "feedback.requests", ["value"])

    _write_cpu_input_config()

    # # Write http_oputs (one or array)
    if _get_appmetrics_target() is not None:
        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_runtime_agent(m2ee)
예제 #8
0
def update_config(m2ee, app_name):
    if not is_enabled() or not _is_installed():
        return

    tags = buildpackutil.get_tags()
    m2ee.config._conf['m2ee']['javaopts'].extend([
        '-Dcom.sun.management.jmxremote',
        '-Dcom.sun.management.jmxremote.port=7845',
        '-Dcom.sun.management.jmxremote.local.only=true',
        '-Dcom.sun.management.jmxremote.authenticate=false',
        '-Dcom.sun.management.jmxremote.ssl=false',
        '-Djava.rmi.server.hostname=127.0.0.1',
    ])
    if m2ee.config.get_runtime_version() >= 7.15:
        m2ee.config._conf['logging'].append({
            'type': 'tcpjsonlines',
            'name': 'DataDogSubscriber',
            'autosubscribe': 'INFO',
            'host': 'localhost',
            'port': 9032,
        })
    enable_runtime_agent(m2ee)
    subprocess.check_call(('mkdir', '-p', '.local/datadog'))
    with open('.local/datadog/datadog.yaml', 'w') as fh:
        config = {
            'dd_url': 'https://app.datadoghq.com',
            'api_key': None,  # set via DD_API_KEY instead
            'confd_path': '.local/datadog/conf.d',
            'logs_enabled': True,
            'log_file': '/dev/null',  # will be printed via stdout/stderr
            'hostname': buildpackutil.get_hostname(),
            'tags': tags,
            'process_config': {
                'enabled': 'true',  # has to be string
                'log_file': '/dev/null',
            },
            'apm_config': {
                'enabled': True,
                'max_traces_per_second': 10,
            },
            'logs_config': {
                'run_path': '.local/datadog/run',
            },
            'use_dogstatsd': not buildpackutil.is_appmetrics_enabled()
        }
        fh.write(yaml.safe_dump(config))
    subprocess.check_call(('mkdir', '-p', '.local/datadog/conf.d/mendix.d'))
    subprocess.check_call(('mkdir', '-p', '.local/datadog/run'))
    with open('.local/datadog/conf.d/mendix.d/conf.yaml', 'w') as fh:
        config = {
            'logs': [{
                'type': 'tcp',
                'port': '9032',
                'service': _get_service(),
                'source': 'mendix',
                'tags': tags,
            }],
        }
        fh.write(yaml.safe_dump(config))
    subprocess.check_call(('mkdir', '-p', '.local/datadog/conf.d/jmx.d'))
    with open('.local/datadog/conf.d/jmx.d/conf.yaml', 'w') as fh:
        # jmx beans and values can be inspected with jmxterm
        # download the jmxterm jar into the container
        # and run app/.local/bin/java -jar ~/jmxterm.jar
        #
        # the extra attributes are only available from Mendix 7.15.0+
        config = {
            'init_config': {
                'collect_default_metrics': True,
                'is_jmx': True,
            },
            'instances': [{
                'host': 'localhost',
                'port': 7845,
                'java_bin_path': '.local/bin/java',
                'java_options': '-Xmx50m -Xms5m',
                # 'refresh_beans': 10, # runtime takes time to initialize the beans
                'conf': [{
                    'include': {
                        'bean': 'com.mendix:type=SessionInformation',
                        # NamedUsers = 1;
                        # NamedUserSessions = 0;
                        # AnonymousSessions = 0;

                        'attribute': {
                            'NamedUsers': {'metrics_type': 'gauge'},
                            'NamedUserSessions': {'metrics_type': 'gauge'},
                            'AnonymousSessions': {'metrics_type': 'gauge'},
                        },
                    },
                }, {
                    'include': {
                        'bean': 'com.mendix:type=Statistics,name=DataStorage',
                        # Selects = 1153;
                        # Inserts = 1;
                        # Updates = 24;
                        # Deletes = 0;
                        # Transactions = 25;

                        'attribute': {
                            'Selects': {'metrics_type': 'counter'},
                            'Updates': {'metrics_type': 'counter'},
                            'Inserts': {'metrics_type': 'counter'},
                            'Deletes': {'metrics_type': 'counter'},
                            'Transactions': {'metrics_type': 'counter'},
                        },
                    },
                }, {
                    'include': {
                        'bean': 'com.mendix:type=General',
                        # Languages = en_US;
                        # Entities = 24;

                        'attribute': {
                            'Entities': {'metrics_type': 'gauge'},
                        },
                    },
                }, {
                    'include': {
                        'bean': 'com.mendix:type=JettyThreadPool',
                        # Threads = 8
                        # IdleThreads = 3;
                        # IdleTimeout = 60000;
                        # MaxThreads = 254;
                        # StopTimeout = 30000;
                        # MinThreads = 8;
                        # ThreadsPriority = 5;
                        # QueueSize = 0;

                        'attribute': {
                            'Threads': {'metrics_type': 'gauge'},
                            'MaxThreads': {'metrics_type': 'gauge'},
                            'IdleThreads': {'metrics_type': 'gauge'},
                            'QueueSize': {'metrics_type': 'gauge'},
                        },
                    },
                }],
                #  }, {
                #    'include': {
                #        'bean': 'com.mendix:type=Jetty',
                #        # ConnectedEndPoints = 0;
                #        # IdleTimeout = 30000;
                #        # RequestsActiveMax = 0;

                #        'attribute': {
                #        }
                #    },
            }],
        }
        fh.write(yaml.safe_dump(config))

    _set_up_postgres()