Esempio n. 1
0
def main():
    init_logging("metric_collector.log")
    options = get_options()

    spectator = SpectatorClient(options)
    try:
        stackdriver = StackdriverClient.make_client(options)
    except IOError as ioerror:
        logging.error("Could not create stackdriver client -- Stackdriver will be unavailable\n%s", ioerror)
        stackdriver = None

    if options.command:
        process_command(options.command, spectator, stackdriver, options)
        return

    path_handlers = {
        "/": handlers.BaseHandler(options),
        "/clear": handlers.ClearCustomDescriptorsHandler(options, stackdriver),
        "/dump": handlers.DumpMetricsHandler(options, spectator),
        "/list": handlers.ListCustomDescriptorsHandler(options, stackdriver),
        "/explore": handlers.ExploreCustomDescriptorsHandler(options, spectator),
        "/show": handlers.ShowCurrentMetricsHandler(options, spectator),
    }

    logging.info("Starting HTTP server on port %d", options.port)
    httpd = HttpServer(options.port, path_handlers)
    httpd.serve_forever()
Esempio n. 2
0
def main():
    init_logging('metric_collector.log')
    options = get_options()

    spectator = SpectatorClient(options)
    try:
        stackdriver = StackdriverClient.make_client(options)
    except IOError as ioerror:
        logging.error(
            'Could not create stackdriver client -- Stackdriver will be unavailable\n%s',
            ioerror)
        stackdriver = None

    if options.command:
        process_command(options.command, spectator, stackdriver, options)
        return

    path_handlers = {
        '/': handlers.BaseHandler(options),
        '/clear': handlers.ClearCustomDescriptorsHandler(options, stackdriver),
        '/dump': handlers.DumpMetricsHandler(options, spectator),
        '/list': handlers.ListCustomDescriptorsHandler(options, stackdriver),
        '/explore':
        handlers.ExploreCustomDescriptorsHandler(options, spectator),
        '/show': handlers.ShowCurrentMetricsHandler(options, spectator)
    }

    logging.info('Starting HTTP server on port %d', options.port)
    httpd = HttpServer(options.port, path_handlers)
    httpd.serve_forever()
Esempio n. 3
0
def main():
    init_logging('metric_collector.log')
    options = vars(get_options())

    spectator = spectator_client.SpectatorClient(options)
    try:
        stackdriver = StackdriverMetricsService.make_service(options)

    except IOError as ioerror:
        logging.error(
            'Could not create stackdriver client'
            ' -- Stackdriver will be unavailable\n%s', ioerror)
        stackdriver = None

    registry = []
    registry.extend([
        CommandDefinition(handlers.BaseHandler(options, registry), '/', 'Home',
                          CommandRequest(options=options),
                          'Home page for Spinnaker metric administration.'),
        CommandDefinition(
            stackdriver_handlers.ClearCustomDescriptorsHandler(
                options,
                stackdriver), '/stackdriver/clear_descriptors', 'clear',
            CommandRequest(options=options),
            'Clear all the Stackdriver Custom Metrics'),
        CommandDefinition(
            stackdriver_handlers.ListCustomDescriptorsHandler(
                options, stackdriver), '/stackdriver/list_descriptors', 'list',
            CommandRequest(content_type='application/json', options=options),
            'Get the JSON of all the Stackdriver Custom Metric Descriptors.'),
        CommandDefinition(
            stackdriver_handlers.UpsertCustomDescriptorsHandler(
                options, stackdriver), None, 'upsert_descriptors',
            CommandRequest(options=options),
            'Given a file of Stackdriver Custom Metric Desciptors,'
            ' update the existing ones and add the new ones.'
            ' WARNING: Historic time-series data may be lost on update.'),
        CommandDefinition(
            handlers.DumpMetricsHandler(options, spectator), '/dump', 'dump',
            CommandRequest(options=options),
            'Show current raw metric JSON from all the servers.'),
        CommandDefinition(
            handlers.ExploreCustomDescriptorsHandler(options, spectator),
            '/explore',
            'explore',
            CommandRequest(options=options),
            'Explore metric type usage across Spinnaker microservices.',
        ),
        CommandDefinition(
            handlers.ShowCurrentMetricsHandler(options,
                                               spectator), '/show', 'show',
            CommandRequest(options=options),
            'Show current metric JSON for all Spinnaker.'),
    ])

    if options.get('command', None):
        command_processor.process_command(options['command'], registry)
        return

    if options.get('monitor', None):
        logging.info('Starting Monitor every %d s', options['period'])

        metric_service = stackdriver

        monitor = Monitor(spectator, metric_service, options)
        threading.Thread(target=monitor, name='monitor').start()

    logging.info('Starting HTTP server on port %d', options['port'])
    url_path_to_handler = {entry.url_path: entry.handler for entry in registry}
    httpd = HttpServer(options['port'], url_path_to_handler)
    httpd.serve_forever()
    sys.exit(-1)
Esempio n. 4
0
def main():
    init_logging('metric_collector.log')
    options = get_options()

    spectator = spectator_client.SpectatorClient(options)
    try:
        stackdriver = stackdriver_client.StackdriverClient.make_client(options)
    except IOError as ioerror:
        logging.error(
            'Could not create stackdriver client'
            ' -- Stackdriver will be unavailable\n%s', ioerror)
        stackdriver = None

    registry = []
    registry.extend([
        CommandDefinition(handlers.BaseHandler(options, registry), '/', 'Home',
                          CommandRequest(options=options),
                          'Home page for Spinnaker metric administration.'),
        CommandDefinition(
            stackdriver_handlers.ClearCustomDescriptorsHandler(
                options,
                stackdriver), '/stackdriver/clear_descriptors', 'clear',
            CommandRequest(options=options),
            'Clear all the Stackdriver Custom Metrics'),
        CommandDefinition(
            stackdriver_handlers.ListCustomDescriptorsHandler(
                options, stackdriver), '/stackdriver/list_descriptors', 'list',
            CommandRequest(content_type='application/json', options=options),
            'Get the JSON of all the Stackdriver Custom Metric Descriptors.'),
        CommandDefinition(
            handlers.DumpMetricsHandler(options, spectator), '/dump', 'dump',
            CommandRequest(options=options),
            'Show current raw metric JSON from all the servers.'),
        CommandDefinition(
            handlers.ExploreCustomDescriptorsHandler(options, spectator),
            '/explore',
            'explore',
            CommandRequest(options=options),
            'Explore metric type usage across Spinnaker microservices.',
        ),
        CommandDefinition(
            handlers.ShowCurrentMetricsHandler(options,
                                               spectator), '/show', 'show',
            CommandRequest(options=options),
            'Show current metric JSON for all Spinnaker.'),
    ])

    if options.command:
        command_processor.process_command(options.command, registry)
        return

    if options.monitor:
        logging.info('Starting Monitor every %d s', options.period)

        # TODO: Replace this with a real service.
        metric_service = DummyMetricService()

        monitor = Monitor(spectator, metric_service, options)
        threading.Thread(target=monitor, name='monitor').start()

    logging.info('Starting HTTP server on port %d', options.port)
    url_path_to_handler = {entry.url_path: entry.handler for entry in registry}
    httpd = HttpServer(options.port, url_path_to_handler)
    httpd.serve_forever()
    sys.exit(-1)
Esempio n. 5
0
def main():
  init_logging('metric_collector.log')
  options = get_options()

  spectator = spectator_client.SpectatorClient(options)
  try:
    stackdriver = stackdriver_client.StackdriverClient.make_client(options)
  except IOError as ioerror:
    logging.error('Could not create stackdriver client'
                  ' -- Stackdriver will be unavailable\n%s',
                  ioerror)
    stackdriver = None

  registry = []
  registry.extend([
      CommandDefinition(
          handlers.BaseHandler(options, registry),
          '/',
          'Home',
          CommandRequest(options=options),
          'Home page for Spinnaker metric administration.'),
      CommandDefinition(
          stackdriver_handlers.ClearCustomDescriptorsHandler(
              options, stackdriver),
          '/stackdriver/clear_descriptors',
          'clear',
          CommandRequest(options=options),
          'Clear all the Stackdriver Custom Metrics'),
      CommandDefinition(
          stackdriver_handlers.ListCustomDescriptorsHandler(
              options, stackdriver),
          '/stackdriver/list_descriptors',
          'list',
          CommandRequest(content_type='application/json', options=options),
          'Get the JSON of all the Stackdriver Custom Metric Descriptors.'
          ),

      CommandDefinition(
          handlers.DumpMetricsHandler(options, spectator),
          '/dump',
          'dump',
          CommandRequest(options=options),
          'Show current raw metric JSON from all the servers.'),
      CommandDefinition(
          handlers.ExploreCustomDescriptorsHandler(options, spectator),
          '/explore',
          'explore',
          CommandRequest(options=options),
          'Explore metric type usage across Spinnaker microservices.',
          ),
      CommandDefinition(
          handlers.ShowCurrentMetricsHandler(options, spectator),
          '/show',
          'show',
          CommandRequest(options=options),
          'Show current metric JSON for all Spinnaker.'
          ),
      ])

  if options.command:
    command_processor.process_command(options.command, registry)
    return

  if options.monitor:
    logging.info('Starting Monitor every %d s', options.period)

    # TODO: Replace this with a real service.
    metric_service = DummyMetricService()

    monitor = Monitor(spectator, metric_service, options)
    threading.Thread(target=monitor, name='monitor').start()

  logging.info('Starting HTTP server on port %d', options.port)
  url_path_to_handler = {entry.url_path: entry.handler for entry in registry}
  httpd = HttpServer(options.port, url_path_to_handler)
  httpd.serve_forever()
  sys.exit(-1)