コード例 #1
0
ファイル: __init__.py プロジェクト: marclop/prometheus-demo
class incrementCounter(object):
    """docstring for incrementCounter"""

    def __init__(self, counter):
        super(incrementCounter, self).__init__()
        self.counterName = counter
        self.pushgatewayUrl = 'http://pushgateway:9091'
        self.c = Counter(self.counterName, 'description for counter')
        self.p = Pusher('pushgateway', self.pushgatewayUrl)
        self.registry = Registry()
        self.registry.register(self.c)

    def inc(self):
        self.counterValue = None
        #c = counter
        if self.counterName is not None:
            if self.counterValue == None:
                self.c.inc({'type': 'hit'})
            else:
                self.c.add({'type': 'hit'}, self.counterValue)
        else:
            return False

        self.p.add(self.registry)
        return True
コード例 #2
0
    def test_push_job_ping(self):
        job_name = "my-job"
        p = Pusher(job_name, TEST_URL)
        registry = Registry()
        c = Counter("total_requests", "Total requests.", {})
        registry.register(c)

        c.inc({
            'url': "/p/user",
        })

        # Push to the pushgateway
        p.replace(registry)

        # Check the objects that setted the server thread
        self.assertEqual(Pusher.PATH.format(job_name), self.request['path'])
コード例 #3
0
ファイル: __init__.py プロジェクト: marclop/prometheus-demo
 def __init__(self, counter):
     super(incrementCounter, self).__init__()
     self.counterName = counter
     self.pushgatewayUrl = 'http://pushgateway:9091'
     self.c = Counter(self.counterName, 'description for counter')
     self.p = Pusher('pushgateway', self.pushgatewayUrl)
     self.registry = Registry()
     self.registry.register(self.c)
コード例 #4
0
    def test_push_delete(self):
        job_name = "my-job"
        p = Pusher(job_name, TEST_URL)
        registry = Registry()
        counter = Counter("counter_test", "A counter.", {'type': "counter"})
        registry.register(counter)

        counter_data = (({'c_sample': '1', 'c_subsample': 'b'}, 400), )

        [counter.set(c[0], c[1]) for c in counter_data]
        valid_result = b'[\n\x0ccounter_test\x12\nA counter.\x18\x00"=\n\r\n\x08c_sample\x12\x011\n\x10\n\x0bc_subsample\x12\x01b\n\x0f\n\x04type\x12\x07counter\x1a\t\t\x00\x00\x00\x00\x00\x00y@'

        # Push to the pushgateway
        p.delete(registry)

        # Check the object that setted the server thread
        self.assertEqual("DELETE", self.request['method'])
        self.assertEqual(valid_result, self.request['body'])
コード例 #5
0
ファイル: __init__.py プロジェクト: marclop/prometheus-demo
    def inc(self, arg=None):
        self.gaugeValue = arg
        if self.gaugeName is not None:

            p = Pusher('pushgateway', self.pushgatewayUrl)
            registry = Registry()
            c = Gauge(self.gaugeName, 'description for gauge', {})
            registry.register(c)

            if self.gaugeValue == None:
                c.inc({'type': 'hit'})
            else:
                c.add({'type': 'hit'}, self.gaugeValue)
        else:
            return False

        p.add(registry)
        return True
コード例 #6
0
import os
import sys
sys.path.append(
    os.path.dirname(
        os.path.dirname(
            os.path.abspath(inspect.getfile(inspect.currentframe())))))

from prometheus.pusher import Pusher
from prometheus.registry import Registry
from prometheus.collectors import Gauge

PUSHGATEWAY_URL = "http://127.0.0.1:9091"

if __name__ == "__main__":
    job_name = "example"
    p = Pusher(job_name, PUSHGATEWAY_URL)
    registry = Registry()
    g = Gauge("up_and_down", "Up and down counter.", {})
    registry.register(g)

    user = input("Hi! enter your username: "******"Enter a positive or negative number: "))

            g.add({
                'user': user,
            }, n)
            # Push to the pushgateway
            p.add(registry)