Example #1
0
    def GET(self):
        result = configurator.get_collectd_plugin_names()
        try:
            url_param = [
                i for i in web.ctx['path'].split('/')
                if i not in ['', 'api', 'collectd', 'stats']
            ]
        except:
            error_msg = "URl not Found"
            raise web.notfound(error_msg)
        plugins = []
        if len(url_param) == 0:
            plugins.append(ALL)
        elif url_param[0] in configurator.get_collectd_plugins_mapping().keys(
        ):
            for name in configurator.get_collectd_plugin_names(url_param[0]):
                plugins.append(str(name).replace("_", ''))
        elif url_param[0] in result:
            plugins.append(str(url_param[0]).replace("_", ''))
        else:
            return json.dumps(result)

        if (url_param[0] == "linux"):
            plugins.append("linux")

        user_data = web.input(samples="1", instances="")
        plugin_instances = [ALL]
        if user_data.instances:
            # instance_list = str(user_data.instances[0])
            plugin_instances = user_data.instances.split(",")
        data = collectd_exporter.get_data(num_samples=int(user_data.samples),
                                          plugins=plugins,
                                          plugin_instances=plugin_instances)

        return json.dumps(data)
Example #2
0
    def GET(self):
        try:
            url_param = [
                i for i in web.ctx['path'].split('/')
                if i not in ['', 'api', 'config']
            ]
        except:
            error_msg = "URl not Found"
            raise web.notfound(error_msg)
        result = {}

        if len(url_param) == 0:
            result[METRICS] = configurator.get_collectd_config()
            result[LOGGING] = configurator.get_fluentd_config()
        elif url_param[0] == SUPPORTED_PLUGINS:
            result[METRICS] = configurator.get_supported_metrics_plugins()
            result[LOGGING] = configurator.get_supported_logging_plugins()
        elif url_param[0] == SUPPORTED_TARGETS:
            result = configurator.get_supported_targets()
        elif url_param[0] == "mapping":
            result[METRICS] = configurator.get_collectd_plugins_mapping()
            result[LOGGING] = configurator.get_fluentd_plugins_mapping()
            result[TARGETS] = configurator.get_supported_targets_mapping()
        elif url_param[0] == "params":
            user_data = web.input(metrics_plugins="",
                                  logging_plugins="",
                                  targets="")
            metric_plugin_instances = []
            target_instances = []
            logging_plugin_instances = []
            # print user_data
            if user_data.metrics_plugins:
                metric_plugin_instances = user_data.metrics_plugins.split(",")
                result[METRICS] = configurator.get_metrics_plugins_params(
                    metric_plugin_instances)
            if user_data.targets:
                target_instances = user_data.targets.split(",")
                result[TARGETS] = configurator.get_targets_params(
                    target_instances)
            if user_data.logging_plugins:
                logging_plugin_instances = user_data.logging_plugins.split(",")
                result[LOGGING] = configurator.get_logging_plugins_params(
                    logging_plugin_instances)
            if not (user_data.metrics_plugins or user_data.targets
                    or user_data.logging_plugins):
                result[METRICS] = configurator.get_metrics_plugins_params(
                    metric_plugin_instances)
                result[LOGGING] = configurator.get_logging_plugins_params(
                    logging_plugin_instances)
                result[TARGETS] = configurator.get_targets_params(
                    target_instances)
        else:
            error_msg = "URl not Found"
            raise web.notfound(error_msg)

        return json.dumps(result)
Example #3
0
    def GET(self):
        try:
            url_param = [i for i in web.ctx['path'].split('/') if i not in ['', 'api', 'config']]
        except:
            error_msg = "URl not Found"
            raise web.notfound(error_msg)

        result = {}
        try:
            import platform
            if float(".".join([platform.python_version_tuple()[0], platform.python_version_tuple()[1]])) < 2.6:
                result["distro"] = " ".join(platform.dist())
            else:
                result["distro"] = " ".join(platform.linux_distribution())
        except:
            result["distro"] = None

        if len(url_param) == 0:
            result[METRICS] = configurator.get_collectd_config()
            result[LOGGING] = configurator.get_fluentd_config()
        elif url_param[0] == SUPPORTED_PLUGINS:
            result[METRICS] = configurator.get_supported_metrics_plugins()
            result[LOGGING] = configurator.get_supported_logging_plugins()
        elif url_param[0] == SUPPORTED_TARGETS:
            result = configurator.get_supported_targets()
        elif url_param[0] == "mapping":
            result[METRICS] = configurator.get_collectd_plugins_mapping()
            result[LOGGING] = configurator.get_fluentd_plugins_mapping()
            result[TARGETS] = configurator.get_supported_targets_mapping()
        elif url_param[0] == "params":
            user_data = web.input(metrics_plugins="", logging_plugins="", targets="")
            metric_plugin_instances = []
            target_instances = []
            logging_plugin_instances = []
            # print user_data
            if user_data.metrics_plugins:
                metric_plugin_instances = user_data.metrics_plugins.split(",")
                result[METRICS] = configurator.get_metrics_plugins_params(metric_plugin_instances)
            if user_data.targets:
                target_instances = user_data.targets.split(",")
                result[TARGETS] = configurator.get_targets_params(target_instances)
            if user_data.logging_plugins:
                logging_plugin_instances = user_data.logging_plugins.split(",")
                result[LOGGING] = configurator.get_logging_plugins_params(logging_plugin_instances)
            if not (user_data.metrics_plugins or user_data.targets or user_data.logging_plugins):
                result[METRICS] = configurator.get_metrics_plugins_params(metric_plugin_instances)
                result[LOGGING] = configurator.get_logging_plugins_params(logging_plugin_instances)
                result[TARGETS] = configurator.get_targets_params(target_instances)
        else:
            error_msg = "URl not Found"
            raise web.notfound(error_msg)

        return json.dumps(result)