pants build system

This commit is contained in:
David Soria Parra 2016-05-25 17:20:22 +02:00
parent f2c4604476
commit f8e52b1d06
5 changed files with 59 additions and 14 deletions

20
mprom/BUILD Normal file
View file

@ -0,0 +1,20 @@
# vim: syntax=python:expandtab:shiftwidth=2:softtabstop=2:tabstop=2
python_binary(
name='mumble-prometheus',
dependencies=[
':murmur',
':ext-deps',
],
source='server.py',
)
python_library(
name='murmur',
sources=['Murmur.py', 'Murmur_ice.py'],
)
python_requirement_library(
name='ext-deps',
requirements=[
python_requirement('prometheus-client>=0.0.13'),
python_requirement('zeroc-ice>=3.6.2.1'),
]
)

View file

@ -5,15 +5,26 @@ import sys
import prometheus_client as node
from contextlib import contextmanager
import argparse, time
import argparse, time, logging
import Ice, Murmur
logger = logging.getLogger('mumble-prometheus')
@contextmanager
def ice_connect(host, port):
def ice_connect(host, port, secret=None):
prxstr = "Meta:tcp -h %s -p %d -t 1000" % (host, port)
ic = Ice.initialize(sys.argv)
props = Ice.createProperties(sys.argv)
props.setProperty("Ice.ImplicitContext", "Shared")
props.setProperty('Ice.Default.EncodingVersion', '1.0')
idata = Ice.InitializationData()
idata.properties = props
ic = Ice.initialize(idata)
if secret:
ic.getImplicitContext().put("secret", secret)
base = ic.stringToProxy(prxstr)
meta = Murmur.MetaPrx.checkedCast(base)
if not meta:
@ -32,6 +43,8 @@ def main():
parser.add_argument('-H', '--host', help='Host of the Ice interface', default='127.0.0.1')
parser.add_argument('-p', '--port', help='Port of the Ice interface', default=6502, type=int)
parser.add_argument('-i', '--interval', help='Interval in seconds', default=60, type=int)
parser.add_argument('--secret', help='The read secret', default=None)
parser.add_argument('-v', '--verbose', help='Verbose', action='store_true')
args = parser.parse_args()
node.start_http_server(args.listen)
@ -43,18 +56,28 @@ def main():
['ice_server', 'server_id']),
}
ice_server = '%s:%d' % (ags.host, args.port)
while True:
t1 = time.time()
with ice_connect(args.host, args.port) as meta:
for server in meta.getBootedServers():
labels = {'server_id': server.id(), 'ice_server': ice_server}
gauges['users'].labels(labels).set(len(server.getUsers()))
gauges['uptime'].labels(labels).set(server.getUptime())
if args.verbose:
logging.basicConfig(level=logging.DEBUG)
else:
logging.basicConfig(level=logging.INFO)
time_to_wait = args.interval - (time.time() - t1)
if time_to_wait > 0:
time.sleep(time_to_wait)
ice_server = '%s:%d' % (args.host, args.port)
with ice_connect(args.host, args.port, args.secret) as meta:
while True:
logger.info('gathering info')
t1 = time.time()
for server in meta.getBootedServers():
g_user = len(server.getUsers())
g_uptime = server.getUptime()
logger.debug('mumble_user_connected: %d' % g_user)
logger.debug('mumble_uptime: %d' % g_uptime)
labels = {'server_id': server.id(), 'ice_server': ice_server}
gauges['users'].labels(labels).set(g_user)
gauges['uptime'].labels(labels).set(g_uptime)
time_to_wait = args.interval - (time.time() - t1)
if time_to_wait > 0:
time.sleep(time_to_wait)
return 0
if __name__ == '__main__':

2
requirements.txt Normal file
View file

@ -0,0 +1,2 @@
prometheus-client==0.0.13
zeroc-ice==3.6.2.1