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)