Initial checkin of prometheus example plugins for the blog post

This commit is contained in:
Paul Bellamy
2016-09-29 13:29:51 +01:00
parent 0cc794248b
commit ebdb7c6a51
6 changed files with 491 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
#!/usr/bin/env python
import BaseHTTPServer
import SocketServer
import errno
import os
import signal
import socket
PLUGIN_ID="prometheus"
PLUGIN_UNIX_SOCK = "/var/run/scope/plugins/" + PLUGIN_ID + ".sock"
class Handler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(self):
# The logger requires a client_address, but unix sockets don't have
# one, so we fake it.
self.client_address = "-"
# Send the headers
self.send_response(200)
self.end_headers()
# Send the body
self.wfile.write(b"foo")
def mkdir_p(path):
try:
os.makedirs(path)
except OSError as exc:
if exc.errno == errno.EEXIST and os.path.isdir(path):
pass
else:
raise
def main():
mkdir_p(os.path.dirname(PLUGIN_UNIX_SOCK))
server = SocketServer.UnixStreamServer(PLUGIN_UNIX_SOCK, Handler)
server.serve_forever()
main()