def _after_configure(self, sender: Celery, **kwargs: Any) -> None: """ Hook to avoid circular imports. Providing the schedules and routes functions to the __init__ method and calling them there creates a circular import. This is because the Celery app (self) is not initialized yet when the function reaches the tasks code, which in turn requires the Celery app to decorate the task with `@celery_app.task`. Calling these functions here make it so that the Celery app has already been initialized upfront, yet we call them before the Celery app is actually started. """ if self.__schedules_function: self.conf.beat_schedule = _overall_schedule( *self.__schedules_function()) if self.__routes_function: self.conf.task_routes = self.__routes_function() monitoring_registry = initialize_monitoring() try: start_http_server(port=config.CELERY_PROMETHEUS_PORT, registry=monitoring_registry) except OSError as exception: # More than one Celery is running on the same machine, so it is enough that one of them # starts the monitoring server. if "Address already in use" not in str(exception): raise
def main(): args = parse_args() pool_collector = None urllib3.disable_warnings() nvml.nvmlInit() atexit.register(nvml.nvmlShutdown) REGISTRY.register(NvidiaCollector()) if args['pool'] is not None: pool_collector = pool_collectors()[args['pool'].lower()]( args['pool_api_host'], args['pool_api_miner']) pool_collector.query_pool() REGISTRY.register(pool_collector) if args['miner'] is not None: REGISTRY.register(miner_collectors()[args['miner'].lower()]( args['miner_api_host'], args['miner_api_port'])) print('Starting exporter...') try: start_http_server(args['port']) while True: time.sleep( 60) # 1 query per minute so we don't reach API request limits if pool_collector is not None: pool_collector.query_pool() except KeyboardInterrupt: print('Exiting...') exit(0)
def startup(): """Do startup things. This is the first thing called from within the ioloop context. """ global event_publishers # Ensure we have a mongo connection yield _progressive_backoff( partial(bg_utils.setup_database, config), 'Unable to connect to mongo, is it started?' ) logger.info( 'Starting metrics server on %s:%d' % (config.web.host, config.metrics.port) ) start_http_server(config.metrics.port) logger.info( 'Starting HTTP server on %s:%d' % (config.web.host, config.web.port) ) server.listen(config.web.port, config.web.host) logger.info("Starting event publishers") event_publishers = _setup_event_publishers(client_ssl) logger.info('Starting scheduler') request_scheduler.start() logger.debug("Publishing application startup event") event_publishers.publish_event(Event(name=Events.BREWVIEW_STARTED.name)) brew_view.logger.info("Application is started. Hello!")
def main(configuration): # Start up the server to expose the metrics. start_http_server(port=configuration.metrics_port, addr=configuration.metrics_url) while True: for instance in configuration.instances: try: process_request(**instance) except RequestException as exception: print("Error occurred:") print(exception) time.sleep(settings.polling_time)
def main(): args = parse_args() urllib3.disable_warnings() nvml.nvmlInit() atexit.register(nvml.nvmlShutdown) REGISTRY.register(NvidiaCollector()) print('Starting exporter...') try: start_http_server(args['port']) while True: time.sleep( 60) # 1 query per minute so we don't reach API request limits except KeyboardInterrupt: print('Exiting...') exit(0)
def set_config(self, config: ValueExtractor) -> None: super().set_config(config) registry = get_registry(self.config.get('registry', REGISTRY)) if MULTIPROC_DIR: registry = MultiProcessCollector(registry) self._registry = registry port: int = self.config.get_int('port', default=0) if port: start_http_server(port=port, registry=registry) graphite: Optional[ValueExtractor] = self.config.get('graphite') if graphite: address = graphite.get('address') if isinstance(address, str): addr = address.split(':') address = (addr[0], int(addr[-1])) gb = GraphiteBridge(address, registry=registry) interval: float = graphite.get_duration('interval', 60) prefix: str = graphite.get('prefix', '') gb.start(interval, prefix=prefix)
def startup(): """Do startup things. This is the first thing called from within the ioloop context. """ global event_publishers, anonymous_principal # Ensure we have a mongo connection logger.info("Checking for Mongo connection") yield _progressive_backoff(partial(setup_database, config), "Unable to connect to mongo, is it started?") # Need to wait until after mongo connection established to load anonymous_principal = load_anonymous() logger.info("Starting event publishers") event_publishers = _setup_event_publishers(client_ssl) logger.info("Initializing metrics") initialize_counts() logger.info("Starting metrics server on %s:%d" % (config.web.host, config.metrics.port)) start_http_server(config.metrics.port) logger.info("Starting HTTP server on %s:%d" % (config.web.host, config.web.port)) server.listen(config.web.port, config.web.host) logger.info("Starting scheduler") request_scheduler.start() logger.debug("Publishing application startup event") event_publishers.publish_event(Event(name=Events.BREWVIEW_STARTED.name)) brew_view.logger.info("Application is started. Hello!")
config = Config() except ValueError as e: logger.critical(e) logger.critical("Invalid configuration. Exiting.") sys.exit(1) logger.info("Starting Kibana Prometheus exporter version %s\n" % config.version + config.description()) REGISTRY.register( KibanaCollector( config.kibana_url, kibana_login=config.kibana_login, kibana_password=config.kibana_password, ignore_ssl=config.ignore_ssl, )) try: start_http_server(config.listen_port) except PermissionError as e: logger.critical("Cannot bind to port %s. Permission denied.", config.listen_port) sys.exit(2) loop = asyncio.new_event_loop() try: loop.run_forever() except KeyboardInterrupt: loop.stop() loop.close()
ss = { states[sta]: True if data["status"] == states[sta] else False for sta in states } s = StateSetMetricFamily("solar_state", "The state of the inverter", ss) yield s if __name__ == "__main__": REGISTRY.unregister(PROCESS_COLLECTOR) REGISTRY.unregister(PLATFORM_COLLECTOR) REGISTRY.unregister(GC_COLLECTOR) REGISTRY.register(CustomCollector()) start_http_server(int(get_config("local_port"))) while True: time.sleep(1) # # url_to_scrape = "https://solar.d.sawrc.com/realtime.csv" # auth = httpx.BasicAuth("root", "shimopa55l!nk") # # "Time;Udc1[V];Idc1[A];Pdc1[W];Udc2[V];Idc2[A];Pdc2[W];Uac1[V];Iac1[A];Uac2[V];Iac2[A];Uac3[V];Iac3[A];Pdc[W];Pac[W];Tsys[C]" # # output_data = httpx.get(url_to_scrape, auth=auth) # # data = output_data.content.decode("utf-8").split(";") # # # acCount = 3
def expose_metrics(): REGISTRY.register(VolumeStatsCollector()) start_http_server(9100)