예제 #1
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'])
예제 #2
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'])
예제 #3
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)