Skip to content

Commit

Permalink
fix(examples): update with render calls
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Dec 23, 2019
1 parent 4eb9e92 commit 2e87fca
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion examples/feather-m4-i2c.py
Expand Up @@ -67,7 +67,7 @@ def main():
router = Router([
('GET', '/metrics', lambda headers, body: {
'status': '200 OK',
'content': '\r\n'.join(registry.print()),
'content': '\r\n'.join(registry.render()),
}),
])
server = False
Expand Down
2 changes: 1 addition & 1 deletion examples/feather-m4-random.py
Expand Up @@ -55,7 +55,7 @@ def main():
}),
('GET', '/metrics', lambda headers, body: {
'status': '200 OK',
'content': '\r\n'.join(registry.print()),
'content': '\r\n'.join(registry.render()),
}),
])
server = False
Expand Down
19 changes: 3 additions & 16 deletions examples/pc-python-3.py
Expand Up @@ -5,7 +5,7 @@
from prometheus_express.registry import CollectorRegistry
from prometheus_express.router import Router
from prometheus_express.server import start_http_server
from prometheus_express.utils import check_network
from prometheus_express.utils import check_network, CPythonNetwork

# system
import random
Expand All @@ -18,23 +18,10 @@
BLUE = (0, 0, 255)

rgb = [()]


class MockNetwork():
connected = True

def ifconfig(self):
hostname = socket.gethostname()
ip_addr = socket.gethostbyname(hostname)
return (ip_addr, 0, 0, 0)


eth = MockNetwork()

eth = CPythonNetwork(socket)

def main():
ready = False
bound = False

registry = CollectorRegistry(namespace='prom_express')
metric_t = Counter('si7021_temperature',
Expand All @@ -47,7 +34,7 @@ def main():
def prom_handler(headers, body):
return {
'status': '200 OK',
'content': '\r\n'.join(registry.print()),
'content': '\r\n'.join(registry.render()),
}

router = Router([
Expand Down
12 changes: 12 additions & 0 deletions prometheus_express/utils.py
Expand Up @@ -22,3 +22,15 @@ def scan_i2c_bus(i2c):
])

i2c.unlock()
return True

class CPythonNetwork(object):
connected = True

def __init__(self, socket):
self.socket = socket

def ifconfig(self):
hostname = self.socket.gethostname()
ip_addr = self.socket.gethostbyname(hostname)
return (ip_addr, 0, 0, 0)

0 comments on commit 2e87fca

Please sign in to comment.