Python prometheus_client.Gauge() Examples

The following are 30 code examples for showing how to use prometheus_client.Gauge(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module prometheus_client , or try the search function .

Example 1
Project: django-prometheus   Author: korfuri   File: test_testutils.py    License: Apache License 2.0 9 votes vote down vote up
def setUp(self):
        self.registry = prometheus_client.CollectorRegistry()
        self.some_gauge = prometheus_client.Gauge(
            "some_gauge", "Some gauge.", registry=self.registry
        )
        self.some_gauge.set(42)
        self.some_labelled_gauge = prometheus_client.Gauge(
            "some_labelled_gauge",
            "Some labelled gauge.",
            ["labelred", "labelblue"],
            registry=self.registry,
        )
        self.some_labelled_gauge.labels("pink", "indigo").set(1)
        self.some_labelled_gauge.labels("pink", "royal").set(2)
        self.some_labelled_gauge.labels("carmin", "indigo").set(3)
        self.some_labelled_gauge.labels("carmin", "royal").set(4)
        self.test_case = SomeTestCase() 
Example 2
Project: CrawlerMonitor   Author: adrianyoung   File: monitor.py    License: MIT License 7 votes vote down vote up
def create_metric(self):
        # record app conf
        self.conf_info = Info('celery_conf_info','APP_CONF')
        self.conf_info_c = CollectorRegistry()

        # monitor worker info
        self.workers_info = Info('celery_workers_info', 'WORKER_INFO')
        self.workers_info_c = CollectorRegistry()

        # monitor worker info real-time
        self.workers_state = Gauge('celery_workers_state', 'WORKER_STATE', ['worker'])
        self.workers_state_c = CollectorRegistry()
        self.workers_processed = Gauge('celery_processed_tasks_total', 'WORKER_TASKS_PROCESSED', ['worker'])
        self.workers_processed_c = CollectorRegistry()
        self.workers_active = Gauge('celery_active_tasks_total', 'WORKER_TASKS_ACTIVE', ['worker'])
        self.workers_active_c = CollectorRegistry()

        # monitor tasks info
        self.tasks_counter = Counter('celery_tasks_total', 'TASK_COUNT_INFO', ['worker','task','result'])
        self.tasks_counter_c = CollectorRegistry()
        self.tasks_runtime = Summary('celery_tasks_seconds', 'TASK_RUNTIME', ['worker', 'task'])
        self.tasks_runtime_c = CollectorRegistry()
        self.tasks_info = Info('celery_tasks_info', 'TASK_INFO')
        self.tasks_info_c = CollectorRegistry() 
Example 3
Project: ouroboros   Author: pyouroboros   File: dataexporters.py    License: MIT License 6 votes vote down vote up
def __init__(self, data_manager, config):
        self.config = config
        self.data_manager = data_manager
        self.http_server = prometheus_client.start_http_server(
            self.config.prometheus_port,
            addr=self.config.prometheus_addr
        )
        self.updated_containers_counter = prometheus_client.Counter(
            'containers_updated',
            'Count of containers updated',
            ['socket', 'container']
        )
        self.monitored_containers_gauge = prometheus_client.Gauge(
            'containers_being_monitored',
            'Gauge of containers being monitored',
            ['socket']
        )
        self.updated_all_containers_gauge = prometheus_client.Gauge(
            'all_containers_updated',
            'Count of total updated',
            ['socket']
        )
        self.logger = getLogger() 
Example 4
Project: prometheus_flask_exporter   Author: rycus86   File: __init__.py    License: MIT License 6 votes vote down vote up
def gauge(self, name, description, labels=None, **kwargs):
        """
        Use a Gauge to track the number of invocations in progress
        for the method.

        :param name: the name of the metric
        :param description: the description of the metric
        :param labels: a dictionary of `{labelname: callable_or_value}` for labels
        :param kwargs: additional keyword arguments for creating the Gauge
        """

        return self._track(
            Gauge,
            lambda metric, time: metric.dec(),
            kwargs, name, description, labels,
            registry=self.registry,
            before=lambda metric: metric.inc(),
            revert_when_not_tracked=lambda metric: metric.dec()
        ) 
Example 5
Project: InfraBox   Author: SAP   File: server.py    License: Apache License 2.0 6 votes vote down vote up
def __init__(self, name):
        self._gauge = Gauge(name, "A gauge of current ammount of active jobs per cluster",
                              ['state', 'cluster'])
        self._request_per_cluster = """
            SELECT cluster_name,
                count(id) filter(WHERE state = 'running'),
                count(id) filter(WHERE state = 'queued'),
                count(id) filter(WHERE state = 'scheduled')
            FROM job
            WHERE state in ('running', 'queued', 'scheduled')
            GROUP BY cluster_name
        """

        self._request_total = """
            SELECT count(id) filter(WHERE state = 'running'),
                   count(id) filter(WHERE state = 'queued'),
                   count(id) filter(WHERE state = 'scheduled')
            FROM job
            WHERE state in ('running', 'queued', 'scheduled')
        """ 
Example 6
Project: zentral   Author: zentralopensource   File: utils.py    License: Apache License 2.0 6 votes vote down vote up
def get_prometheus_incidents_metrics():
    registry = CollectorRegistry()
    g = Gauge('zentral_incidents_count', 'Zentral incidents',
              ['name', 'id', 'severity', 'status', 'opened'],
              registry=registry)
    query = (
        "select count(*), "
        "i.id, i.name, i.severity, "
        "mi.status, (CASE WHEN mi.status in ('CLOSED', 'RESOLVED') THEN FALSE ELSE TRUE END) as opened "
        "from incidents_incident as i "
        "join incidents_machineincident as mi on (mi.incident_id = i.id) "
        "group by i.name, i.id, i.severity, mi.status, opened "
        "order by i.id, mi.status;"
    )
    cursor = connection.cursor()
    cursor.execute(query)
    columns = [col[0] for col in cursor.description]
    for row in cursor.fetchall():
        d = dict(zip(columns, row))
        d["severity"] = str(SEVERITY_CHOICES_DICT.get(d.pop("severity"), "Unknown"))
        d["status"] = str(STATUS_CHOICES_DICT.get(d.pop("status"), "Unknown"))
        d["opened"] = 'Y' if d["opened"] else 'N'
        count = d.pop('count')
        g.labels(**d).set(count)
    return registry 
Example 7
Project: client_python   Author: prometheus   File: metrics.py    License: Apache License 2.0 6 votes vote down vote up
def __init__(self,
                 name,
                 documentation,
                 labelnames=(),
                 namespace='',
                 subsystem='',
                 unit='',
                 registry=REGISTRY,
                 labelvalues=None,
                 multiprocess_mode='all',
                 ):
        self._multiprocess_mode = multiprocess_mode
        if multiprocess_mode not in self._MULTIPROC_MODES:
            raise ValueError('Invalid multiprocess mode: ' + multiprocess_mode)
        super(Gauge, self).__init__(
            name=name,
            documentation=documentation,
            labelnames=labelnames,
            namespace=namespace,
            subsystem=subsystem,
            unit=unit,
            registry=registry,
            labelvalues=labelvalues,
        )
        self._kwargs['multiprocess_mode'] = self._multiprocess_mode 
Example 8
def gen_subnet_size(self):
        labels = ['cloud', 'network_name']
        net_size = Gauge('neutron_net_size',
                         'Neutron networks size',
                         labels, registry=self.registry)
        for n in self.prodstack['networks']:
            size = 0
            for subnet in n['subnets']:
                for pool in self.subnet_map[subnet]['pool']:
                    if ':' in pool['start']:
                        # Skip IPv6 address pools; they are big enough to
                        # drown the IPv4 numbers we might care about.
                        continue
                    size += IPRange(pool['start'], pool['end']).size
            label_values = [config['cloud'], self.network_map[n['id']]]
            net_size.labels(*label_values).set(size) 
Example 9
def gen_volume_quota_stats(self):
        gbs = Gauge('cinder_quota_volume_disk_gigabytes',
                    'Cinder volume metric (GB)',
                    ['cloud', 'tenant', 'type'], registry=self.registry)
        vol = Gauge('cinder_quota_volume_disks',
                    'Cinder volume metric (number of volumes)',
                    ['cloud', 'tenant', 'type'], registry=self.registry)
        if not self.use_nova_volumes:
            return
        for t, q in self.prodstack['volume_quotas'].items():
            if t in self.tenant_map:
                tenant = self.tenant_map[t]
            else:
                tenant = 'orphaned'
            for tt in ['limit', 'in_use', 'reserved']:
                gbs.labels(config['cloud'], tenant, tt).inc(q['gigabytes'][tt])
                vol.labels(config['cloud'], tenant, tt).inc(q['volumes'][tt]) 
Example 10
Project: faucet   Author: faucetsdn   File: gauge_prom.py    License: Apache License 2.0 6 votes vote down vote up
def __init__(self, reg=None):
        super(GaugePrometheusClient, self).__init__(reg=reg)
        self.table_tags = collections.defaultdict(set)
        self.metrics = {}
        self.dp_status = Gauge( # pylint: disable=unexpected-keyword-arg
            'dp_status',
            'status of datapaths',
            self.REQUIRED_LABELS,
            registry=self._reg)
        for prom_var in PROM_PORT_VARS + PROM_PORT_STATE_VARS:
            exported_prom_var = PROM_PREFIX_DELIM.join(
                (PROM_PORT_PREFIX, prom_var))
            self.metrics[exported_prom_var] = Gauge(  # pylint: disable=unexpected-keyword-arg
                exported_prom_var, '',
                self.REQUIRED_LABELS + ['port', 'port_description'],
                registry=self._reg)
        for prom_var in PROM_METER_VARS:
            exported_prom_var = PROM_PREFIX_DELIM.join(
                (PROM_METER_PREFIX, prom_var))
            self.metrics[exported_prom_var] = Gauge(  # pylint: disable=unexpected-keyword-arg
                exported_prom_var, '',
                self.REQUIRED_LABELS + ['meter_id'],
                registry=self._reg) 
Example 11
Project: prometheus-openstack-exporter   Author: att-comdev   File: nova_services.py    License: Apache License 2.0 6 votes vote down vote up
def get_stats(self):
        registry = CollectorRegistry()
        labels = ['region', 'host', 'service', 'state']
        services_stats_cache = self.get_cache_data()
        for services_stat in services_stats_cache:
            stat_gauge = Gauge(
                self.gauge_name_sanitize(
                    services_stat['stat_name']),
                'Openstack Nova Service statistic',
                labels,
                registry=registry)
            label_values = [self.osclient.region,
                            services_stat.get('host', ''),
                            services_stat.get('service', ''),
                            services_stat.get('state', '')]
            stat_gauge.labels(*label_values).set(services_stat['stat_value'])
        return generate_latest(registry) 
Example 12
Project: prometheus-openstack-exporter   Author: att-comdev   File: cinder_services.py    License: Apache License 2.0 6 votes vote down vote up
def get_stats(self):
        registry = CollectorRegistry()
        labels = ['region', 'host', 'service', 'state']
        cinder_services_stats_cache = self.get_cache_data()
        for cinder_services_stat in cinder_services_stats_cache:
            stat_gauge = Gauge(
                self.gauge_name_sanitize(
                    cinder_services_stat['stat_name']),
                'Openstack Cinder Service statistic',
                labels,
                registry=registry)
            label_values = [self.osclient.region,
                            cinder_services_stat.get('host', ''),
                            cinder_services_stat.get('service', ''),
                            cinder_services_stat.get('state', '')]
            stat_gauge.labels(
                *
                label_values).set(
                cinder_services_stat['stat_value'])
        return generate_latest(registry) 
Example 13
Project: prometheus-openstack-exporter   Author: att-comdev   File: check_os_api.py    License: Apache License 2.0 6 votes vote down vote up
def get_stats(self):
        registry = CollectorRegistry()
        labels = ['region', 'url', 'service']
        check_api_data_cache = self.get_cache_data()
        for check_api_data in check_api_data_cache:
            label_values = [
                check_api_data['region'],
                check_api_data['url'],
                check_api_data['service']]
            gague_name = self.gauge_name_sanitize(
                "check_{}_api".format(check_api_data['service']))
            check_gauge = Gauge(
                gague_name,
                'Openstack API check. fail = 0, ok = 1 and unknown = 2',
                labels,
                registry=registry)
            check_gauge.labels(*label_values).set(check_api_data['status'])
        return generate_latest(registry) 
Example 14
Project: prometheus-openstack-exporter   Author: att-comdev   File: neutron_agents.py    License: Apache License 2.0 6 votes vote down vote up
def get_stats(self):
        registry = CollectorRegistry()
        labels = ['region', 'host', 'service', 'state']
        neutron_agent_stats_cache = self.get_cache_data()
        for neutron_agent_stat in neutron_agent_stats_cache:
            stat_gauge = Gauge(
                self.gauge_name_sanitize(
                    neutron_agent_stat['stat_name']),
                'Openstack Neutron agent statistic',
                labels,
                registry=registry)
            label_values = [self.osclient.region,
                            neutron_agent_stat.get('host', ''),
                            neutron_agent_stat.get('service', ''),
                            neutron_agent_stat.get('state', '')]
            stat_gauge.labels(
                *
                label_values).set(
                neutron_agent_stat['stat_value'])
        return generate_latest(registry) 
Example 15
Project: Carnets   Author: holzschu   File: metrics.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def __init__(self,
        name,
        documentation,
        labelnames=(),
        namespace='',
        subsystem='',
        unit='',
        registry=REGISTRY,
        labelvalues=None,
        multiprocess_mode='all',
    ):
        self._multiprocess_mode = multiprocess_mode
        if multiprocess_mode not in self._MULTIPROC_MODES:
            raise ValueError('Invalid multiprocess mode: ' + multiprocess_mode)
        super(Gauge, self).__init__(
            name=name,
            documentation=documentation,
            labelnames=labelnames,
            namespace=namespace,
            subsystem=subsystem,
            unit=unit,
            registry=registry,
            labelvalues=labelvalues,
        )
        self._kwargs['multiprocess_mode'] = self._multiprocess_mode 
Example 16
Project: anchore-engine   Author: anchore   File: metrics.py    License: Apache License 2.0 6 votes vote down vote up
def gauge_set(name, observation, description="", **kwargs):
    global metrics

    if not enabled:
        return True

    try:
        if name not in metrics:
            metrics[name] = Gauge(name, description, list(kwargs.keys()))

        if kwargs:
            metrics[name].labels(**kwargs).set(observation)
        else:
            metrics[name].set(observation)

    except Exception as err:
        logger.warn("adding metric failed - exception: " + str(err))

    return True 
Example 17
Project: integrations-core   Author: DataDog   File: conftest.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def poll_mock():
    registry = CollectorRegistry()
    g1 = Gauge('metric1', 'processor usage', ['matched_label', 'node', 'flavor'], registry=registry)
    g1.labels(matched_label="foobar", node="host1", flavor="test").set(99.9)
    g2 = Gauge('metric2', 'memory usage', ['matched_label', 'node', 'timestamp'], registry=registry)
    g2.labels(matched_label="foobar", node="host2", timestamp="123").set(12.2)
    c1 = Counter('counter1', 'hits', ['node'], registry=registry)
    c1.labels(node="host2").inc(42)
    g3 = Gauge('metric3', 'memory usage', ['matched_label', 'node', 'timestamp'], registry=registry)
    g3.labels(matched_label="foobar", node="host2", timestamp="456").set(float('inf'))

    poll_mock_patch = mock.patch(
        'requests.get',
        return_value=mock.MagicMock(
            status_code=200,
            iter_lines=lambda **kwargs: ensure_unicode(generate_latest(registry)).split("\n"),
            headers={'Content-Type': "text/plain"},
        ),
    )
    with poll_mock_patch:
        yield 
Example 18
Project: sanic-prometheus   Author: dkruchinin   File: metrics.py    License: MIT License 5 votes vote down vote up
def init(app, latency_buckets=None, multiprocess_mode='all',
         memcollect_enabled=True, metrics_list=None):
    app.metrics['RQS_COUNT'] = Counter(
        'sanic_request_count',
        'Sanic Request Count',
        ['method', 'endpoint', 'http_status']
    )

    hist_kwargs = {}
    if latency_buckets is not None:
        hist_kwargs = {'buckets': latency_buckets}
    app.metrics['RQS_LATENCY'] = Histogram(
        'sanic_request_latency_sec',
        'Sanic Request Latency Histogram',
        ['method', 'endpoint', 'http_status'],
        **hist_kwargs
    )

    if memcollect_enabled:
        app.metrics['PROC_RSS_MEM_BYTES'] = Gauge(
            'sanic_mem_rss_bytes',
            'Resident memory used by process running Sanic',
            multiprocess_mode=multiprocess_mode
        )
        app.metrics['PROC_RSS_MEM_PERC'] = Gauge(
            'sanic_mem_rss_perc',
            'A per cent of total physical memory used by ' +
            'the process running Sanic',
            multiprocess_mode=multiprocess_mode
        )

    if metrics_list:
        for name, pm_metric in metrics_list:
            app.metrics[name] = pm_metric 
Example 19
Project: armada   Author: airshipit   File: metrics.py    License: Apache License 2.0 5 votes vote down vote up
def __init__(self, prefix, description, labels):
        """
        :param prefix: prefix to use for each metric name
        :param description: description of action to use in metric description
        :param labels: label names to define for each metric
        """
        self.full_prefix = '{}_{}'.format(self.__class__._PREFIX, prefix)
        self.progress = prometheus_client.Gauge(
            '{}_attempt_inprogress'.format(self.full_prefix),
            'In progress attempts to {}'.format(description),
            labels,
            registry=REGISTRY,
            multiprocess_mode='livesum')
        self.attempt_total = prometheus_client.Counter(
            '{}_attempt_total'.format(self.full_prefix),
            'Total attempts to {}'.format(description),
            labels,
            registry=REGISTRY)
        self.failure_total = prometheus_client.Counter(
            '{}_failure_total'.format(self.full_prefix),
            'Total failures to {}'.format(description),
            labels,
            registry=REGISTRY)
        self.duration = prometheus_client.Histogram(
            '{}_duration_seconds'.format(self.full_prefix),
            'Seconds to {}'.format(description),
            labels,
            registry=REGISTRY) 
Example 20
Project: platform-resource-manager   Author: intel   File: prometheus.py    License: Apache License 2.0 5 votes vote down vote up
def __init__(self):
        self.gauge_cpu_usage_percentage = Gauge('cma_cpu_usage_percentage',
                                                'CPU usage percentage of a\
                                                container', ['container'])
        self.gauge_llc_misses = Gauge('cma_llc_misses',
                                      'CPU usage percentage of a container',
                                      ['container'])
        self.gauge_unhalted_cycles = Gauge('cma_unhalted_cycles',
                                           'CPU usage percentage of a\
                                           container', ['container'])
        self.gauge_instructions = Gauge('cma_instructions',
                                        'Instructions of a container',
                                        ['container'])
        self.gauge_cycles_per_instruction = Gauge('cma_cycles_per_instruction',
                                                  'Cycles per instruction of a\
                                                  container', ['container'])
        self.gauge_misses_per_instruction = Gauge('cma_misses_per_instruction',
                                                  'Misses per instruction of a\
                                                  container', ['container'])
        self.gauge_stalls_mem_per_instruction = Gauge(
            'cma_stalls_mem_per_instruction',
            'Stalls memory load per instruction of a container', ['container'])
        self.gauge_average_frequency = Gauge('cma_average_frequency',
                                             'Instructions of a container',
                                             ['container'])
        self.gauge_memory_bandwidth = Gauge('cma_memory_bandwidth',
                                            'Instructions of a container',
                                            ['container'])
        self.gauge_llc_occupancy = Gauge('cma_llc_occupancy',
                                         'Instructions of a container',
                                         ['container']) 
Example 21
Project: awslimitchecker   Author: jantman   File: prometheus.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def gauge(path):
    path = path.lower().translate(trantab, '()')
    g = gauges.get(path, None)
    if g is None:
        g = Gauge(path, '', ['region', 'type'])
        gauges[path] = g
    return g 
Example 22
Project: InfraBox   Author: SAP   File: server.py    License: Apache License 2.0 5 votes vote down vote up
def __init__(self, name, conn):
        self._gauge = Gauge(name, "A gauge of allocated ressources of running jobs over time", ['cluster', 'rsc', 'project'])
        self._request_per_cluster = '''
            SELECT foo.cluster_name,
                   (SELECT name FROM project WHERE id= foo.project_id),
                   foo.mem, foo.cpu
            FROM (
                    SELECT cluster_name, project_id, sum((definition#>>'{resources,limits,memory}')::integer) as mem,
                    sum((definition#>>'{resources,limits,cpu}')::decimal) as cpu FROM job
                    WHERE state='running'
                    GROUP BY cluster_name, project_id
                 ) as foo
        '''

        self._request_total = """
            SELECT (SELECT name FROM project WHERE id = foo.project_id), foo.mem, foo.cpu
            FROM (SELECT project_id,
                         sum((definition#>>'{resources,limits,memory}')::integer) as mem,
                         sum((definition#>>'{resources,limits,cpu}')::decimal) as cpu
                  FROM job
                  WHERE state='running'
                  GROUP BY project_id) as foo
        """

        self._request_possible_cluster = "SELECT DISTINCT name FROM cluster ORDER BY name"
        self._request_possible_projects = "SELECT DISTINCT name FROM project ORDER BY name"
        self._possible_combination = None
        self._possible_cluster = None
        self._possible_project = None
        self._count_to_update = 10
        self._create_combination_dict(conn) 
Example 23
Project: InfraBox   Author: SAP   File: server.py    License: Apache License 2.0 5 votes vote down vote up
def __init__(self, name):
        self._gauge = Gauge(name, "A gauge of current ammount of all jobs",
                              ['state', 'node'])

        self._request_possible_states = "SELECT distinct state FROM job"

        self._request_possible_node = "SELECT distinct node_name FROM job"

        self._request_per_node = "SELECT node_name, state, count(*) " \
                                   "FROM job WHERE node_name is not null GROUP BY node_name, state"

        self._possible_combination = dict()
        self._count_to_reset_nodes = 0
        self._possible_nodes = None
        self._possibles_states = None 
Example 24
Project: zentral   Author: zentralopensource   File: utils.py    License: Apache License 2.0 5 votes vote down vote up
def get_prometheus_inventory_metrics():
    registry = CollectorRegistry()
    g = Gauge('zentral_inventory_osx_apps', 'Zentral inventory OSX apps',
              ['name', 'version_str', 'source'],
              registry=registry)
    for r in osx_app_count():
        count = r.pop('count')
        g.labels(**r).set(count)
    g = Gauge('zentral_inventory_os_versions', 'Zentral inventory OS Versions',
              ['name', 'major', 'minor', 'patch', 'build', 'source'],
              registry=registry)
    for r in os_version_count():
        count = r.pop('count')
        g.labels(**r).set(count)
    return registry 
Example 25
Project: BentoML   Author: bentoml   File: instruments.py    License: Apache License 2.0 5 votes vote down vote up
def __init__(self, app, bento_service):
        self.app = app
        self.bento_service = bento_service

        from prometheus_client import Histogram, Counter, Gauge, CollectorRegistry

        service_name = self.bento_service.name
        namespace = config('instrument').get('default_namespace')
        # Use local registry instead of the global one to avoid duplicated metrics
        # register
        self.collector_registry = CollectorRegistry()

        self.metrics_request_duration = Histogram(
            name=service_name + '_request_duration_seconds',
            documentation=service_name + " API HTTP request duration in seconds",
            namespace=namespace,
            labelnames=['endpoint', 'service_version', 'http_response_code'],
            registry=self.collector_registry,
        )
        self.metrics_request_total = Counter(
            name=service_name + "_request_total",
            documentation='Totoal number of HTTP requests',
            namespace=namespace,
            labelnames=['endpoint', 'service_version', 'http_response_code'],
            registry=self.collector_registry,
        )
        self.metrics_request_in_progress = Gauge(
            name=service_name + "_request_in_progress",
            documentation='Totoal number of HTTP requests in progress now',
            namespace=namespace,
            labelnames=['endpoint', 'service_version'],
            registry=self.collector_registry,
        ) 
Example 26
Project: dagster   Author: dagster-io   File: test_resources.py    License: Apache License 2.0 5 votes vote down vote up
def test_prometheus_gauge():
    @solid(required_resource_keys={'prometheus'})
    def prometheus_solid(context):
        g = Gauge(
            'job_last_success_unixtime',
            'Last time a batch job successfully finished',
            registry=context.resources.prometheus.registry,
        )
        g.set_to_current_time()
        recorded = context.resources.prometheus.registry.get_sample_value(
            'job_last_success_unixtime'
        )
        assert abs(time.time() - recorded) < 10.0

    assert execute_solid(prometheus_solid, run_config=ENV, mode_def=MODE).success 
Example 27
Project: iris   Author: linkedin   File: prometheus.py    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
def send_metrics(self, metrics):
        if not self.enable_metrics:
            return
        for metric, value in metrics.items():
            if metric not in self.gauges:
                self.gauges[metric] = Gauge(self.appname + '_' + metric, '')
            self.gauges[metric].set_to_current_time()
            self.gauges[metric].set(value) 
Example 28
Project: quay   Author: quay   File: progress.py    License: Apache License 2.0 5 votes vote down vote up
def __init__(self, prom_pushgateway_addr, prom_job, labels, total_steps_num=None):
        self._total_steps_num = total_steps_num
        self._completed_steps = 0.0

        registry = CollectorRegistry()

        self._migration_completion_percent = Gauge(
            "migration_completion_percent",
            "Estimate of the completion percentage of the job",
            registry=registry,
        )
        self._migration_complete_total = Counter(
            "migration_complete_total",
            "Binary value of whether or not the job is complete",
            registry=registry,
        )
        self._migration_failed_total = Counter(
            "migration_failed_total",
            "Binary value of whether or not the job has failed",
            registry=registry,
        )
        self._migration_items_completed_total = Counter(
            "migration_items_completed_total",
            "Number of items this migration has completed",
            registry=registry,
        )

        self._push = partial(
            push_to_gateway,
            prom_pushgateway_addr,
            job=prom_job,
            registry=registry,
            grouping_key=labels,
        ) 
Example 29
Project: oncall   Author: linkedin   File: prometheus.py    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
def send_metrics(self, metrics):
        if not self.enable_metrics:
            return
        for metric, value in metrics.items():
            if metric not in self.gauges:
                self.gauges[metric] = Gauge(self.appname + '_' + metric, '')
            logger.info('Setting metrics gauge %s to %s', metric, value)
            self.gauges[metric].set_to_current_time()
            self.gauges[metric].set(value) 
Example 30
Project: client_python   Author: prometheus   File: metrics.py    License: Apache License 2.0 5 votes vote down vote up
def set_function(self, f):
        """Call the provided function to return the Gauge value.

        The function must return a float, and may be called from
        multiple threads. All other methods of the Gauge become NOOPs.
        """

        def samples(self):
            return (('', {}, float(f())),)

        self._child_samples = create_bound_method(samples, self)