当前位置: 首页>>代码示例>>Python>>正文


Python MarathonClient.list_queue方法代码示例

本文整理汇总了Python中marathon.MarathonClient.list_queue方法的典型用法代码示例。如果您正苦于以下问题:Python MarathonClient.list_queue方法的具体用法?Python MarathonClient.list_queue怎么用?Python MarathonClient.list_queue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在marathon.MarathonClient的用法示例。


在下文中一共展示了MarathonClient.list_queue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: MarathonAppCollector

# 需要导入模块: from marathon import MarathonClient [as 别名]
# 或者: from marathon.MarathonClient import list_queue [as 别名]
class MarathonAppCollector(object):
    APP_ATTIBUTES = (
        "instances",
        "cpus",
        "mem",
        "disk",
        "backoffSeconds",
        "backoffFactor",
        "maxLaunchDelaySeconds",
        "container.docker.privileged",
        "container.docker.forcePullImage",
        "healthChecks.gracePeriodSeconds",
        "healthChecks.intervalSeconds",
        "healthChecks.maxConsecutiveFailures",
        "healthChecks.timeoutSeconds",
        "upgradeStrategy.minimumHealthCapacity",
        "upgradeStrategy.maximumOverCapacity",
        "tasksStaged",
        "tasksRunning",
        "tasksHealthy",
        "tasksUnhealthy",
        "taskStats.startedAfterLastScaling.stats.counts.staged",
        "taskStats.startedAfterLastScaling.stats.counts.running",
        "taskStats.startedAfterLastScaling.stats.counts.healthy",
        "taskStats.startedAfterLastScaling.stats.lifeTime.averageSeconds",
        "taskStats.startedAfterLastScaling.stats.lifeTime.medianSeconds",
        "taskStats.withLatestConfig.stats.counts.staged",
        "taskStats.withLatestConfig.stats.counts.running",
        "taskStats.withLatestConfig.stats.counts.healthy",
        "taskStats.withLatestConfig.stats.lifeTime.averageSeconds",
        "taskStats.withLatestConfig.stats.lifeTime.medianSeconds",
        "taskStats.totalSummary.stats.counts.staged",
        "taskStats.totalSummary.stats.counts.running",
        "taskStats.totalSummary.stats.counts.healthy",
        "taskStats.totalSummary.stats.lifeTime.averageSeconds",
        "taskStats.totalSummary.stats.lifeTime.medianSeconds",
    )
    QUEUE_ATTRIBUTES = (
        "count",
        "delay.overdue",
        "delay.timeLeftSeconds",
    )

    def __init__(self, marathon_url=None):
        self.client = MarathonClient(marathon_url)

    def collect(self):
        result_dict = {}
        apps = self.client.list_apps(embed_task_stats=True)
        for app_attribute in self.APP_ATTIBUTES:
            metric_family = GaugeMetricFamily(
                self.get_metric_key(app_attribute, 'apps'),
                documentation='from v2/apps?embed=apps.taskStats value of %s' % app_attribute,
                labels=["id"])
            for app in apps:
                labels = [app.id]
                value = self.get_metric_value(app_attribute, app)
                if value is None:
                    continue
                metric_family.add_metric(labels, value)
            yield metric_family
        queue = self.client.list_queue()
        for queue_attribute in self.QUEUE_ATTRIBUTES:
            metric_family = GaugeMetricFamily(
                self.get_metric_key(queue_attribute, 'queue'),
                documentation='from v2/queue value of %s' % queue_attribute,
                labels=["id"])
            for queue_item in queue:
                labels = [queue_item.app.id]
                value = self.get_metric_value(queue_attribute, queue_item)
                if value is None:
                    continue
                metric_family.add_metric(labels, value)
            yield metric_family

    @classmethod
    def get_metric_value(cls, key, obj):
        if '.' in key:
            key_current, key_rest = key.split('.', 1)
            sub_obj = getattr(obj, to_snake_case(key_current), None)
            if sub_obj is None:
                return None
            return cls.get_metric_value(key_rest, sub_obj)
        return getattr(obj, to_snake_case(key), None)

    @classmethod
    def get_metric_key(cls, key, obj_type):
        return "marathon_%s_%s" % (obj_type, key.replace('.', '_'))

    @classmethod
    def generate_metric(cls, key, obj, obj_type, labels, value):
        return metric_family
开发者ID:bergerx,项目名称:prom_marathon_app_exporter,代码行数:94,代码来源:collector.py


注:本文中的marathon.MarathonClient.list_queue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。