Ejemplo n.º 1
0
def main():
    rc = RiemannClient(transport=RiemannUDPTransport)
    rc.send({
        'host': '127.0.0.1',
        'service': 'www',
        'state': 'down',
        'metric_f': 10000
    })
Ejemplo n.º 2
0
def main():
    rc = RiemannClient()
    rc.send({
        'host': '127.0.0.1',
        'service': 'www',
        'state': 'down',
        'metric_f': 10000
    })
    res = rc.query('host')
    print res
    for e in res.events:
        print e.host
Ejemplo n.º 3
0
def main():
    rc = RiemannClient()
    tb = time.time()

    for n in xrange(100):
        rc.send({'host':'127.0.0.1', 'service': 'www%d' % n, 'state': 'down', 'metric_f': 10000})
    
    print time.time() - tb

    res = rc.query('service')
    print res
    if res is not None:
        for e in res.events: print e.host
Ejemplo n.º 4
0
def main():
  parser = argparse.ArgumentParser(description='Send events to Riemann.')
  parser.add_argument('-r', '--riemann', dest='rie_host', action='store',
                      type=str, required=True,
                      help='IP/hostname for Riemann server')
  parser.add_argument('-R', '--riemann-port', dest='rie_port', action='store',
                      type=int, default=5555,
                      help='IP/hostname for Riemann server')

  parser.add_argument('-H', '--host', dest='evt_host', action='store',
                      type=str, default=socket.getfqdn(),
                      help='Hostname for event')
  parser.add_argument('-s', '--service', dest='evt_service', action='store',
                      type=str, help='Service for event')
  parser.add_argument('-S', '--state', dest='evt_state', action='store',
                      type=str, help='Current state for event')
  parser.add_argument('-T', '--time', dest='evt_time', action='store',
                      type=int, default=int(time.time()),
                      help='Timestamp for event')

  parser.add_argument('-a', '--attribute', dest='evt_attrib', action='append',
                      type=str, help='Event attribute (key=value), multiple allowed')
  parser.add_argument('-d', '--description', dest='evt_description',
                      action='store', type=str, help='Event description')
  parser.add_argument('-t', '--tags', dest='evt_tags', action='append',
                      type=str, help='Event tags, multiple allowed')
  parser.add_argument('-m', '--metric', dest='evt_metric', action='store',
                      type=float, help='Event metric')
  parser.add_argument('--ttl', dest='evt_ttl', action='store', type=int,
                      default=60, help='Event TTL')
  args = parser.parse_args()


  event = {}
  for i in ['host', 'service', 'time', 'description', 'tags', 'metric', 'ttl']:
    if getattr(args, 'evt_' + i):
      event[i] = getattr(args, 'evt_' + i)

  if getattr(args, 'evt_attrib', None):
    event['attributes'] = dict(item.split('=') for item in getattr(args, 'evt_attrib'))

  print(repr(event))

  rc = RiemannClient(host=args.rie_host, port=args.rie_port)
  rc.send(event)
Ejemplo n.º 5
0
def main():
    rc = RiemannClient()
    tb = time.time()

    for n in xrange(100):
        rc.send({
            'host': '127.0.0.1',
            'service': 'www%d' % n,
            'state': 'down',
            'metric_f': 10000
        })

    print time.time() - tb

    res = rc.query('service')
    print res
    if res is not None:
        for e in res.events:
            print e.host
Ejemplo n.º 6
0
def main():
    rc = RiemannClient()
    rc.send({'host':'127.0.0.1', 'service': 'www', 'state': 'down', 'metric_f': 10000})
    res = rc.query('host')
    print res
    for e in res.events: print e.host
Ejemplo n.º 7
0
def main():
    rc = RiemannClient(transport = RiemannUDPTransport)
    rc.send({'host':'127.0.0.1', 'service': 'www', 'state': 'down', 'metric_f': 10000})
Ejemplo n.º 8
0
import psutil
import os, popen2, sys
from time import sleep
sys.path.append("..")

from riemann import RiemannClient

#print psutil.disk_io_counters()
#print psutil.network_io_counters(pernic=True)

rc = RiemannClient()


def alert(service, state, metric, description):
    rc.send({
        'service': service,
        'state': state,
        'metric': metric,
        'description': description
    })


def cores():
    return psutil.NUM_CPUS


def cpu_report():
    r, w, e = popen2.popen3('ps -eo pcpu,pid,args | sort -nrb -k1 | head -10')
    return r.readlines()

Ejemplo n.º 9
0
def _s(pars):
    rc = RiemannClient()
    r = rc.send(pars)
Ejemplo n.º 10
0
def _s(pars):
    rc = RiemannClient()
    r = rc.send(pars)