feat: add option service to run sd in a loop (default: true)

This commit is contained in:
Robert Kaussow 2021-06-09 21:38:06 +02:00
parent c40eac65f4
commit fdc41dcdef
2 changed files with 17 additions and 2 deletions

View File

@ -48,6 +48,12 @@ class PrometheusSD:
action="store", action="store",
help="delay between discovery runs" help="delay between discovery runs"
) )
parser.add_argument(
"--no-service",
dest="service",
action="store_false",
help="run discovery as a service"
)
parser.add_argument( parser.add_argument(
"-v", dest="logging.level", action="append_const", const=-1, help="increase log level" "-v", dest="logging.level", action="append_const", const=-1, help="increase log level"
) )
@ -90,12 +96,15 @@ class PrometheusSD:
output_file = self.config.config["output_file"] output_file = self.config.config["output_file"]
self.logger.info("Writes targets to {}".format(output_file)) self.logger.info("Writes targets to {}".format(output_file))
self.logger.debug("Propagate from PVE")
while True: while True:
self.logger.debug("Propagate from PVE")
self._write(self.discovery.propagate()) self._write(self.discovery.propagate())
self.logger.info("Waiting {} seconds for next loop".format(loop_delay)) if not self.config.config["service"]:
break
self.logger.info("Waiting {} seconds for next discovery loop".format(loop_delay))
sleep(self.config.config["loop_delay"]) sleep(self.config.config["loop_delay"])
def _write(self, host_list: HostList): def _write(self, host_list: HostList):

View File

@ -61,6 +61,12 @@ class Config():
"file": True, "file": True,
"type": environs.Env().int "type": environs.Env().int
}, },
"service": {
"default": True,
"env": "SERVICE",
"file": True,
"type": environs.Env().bool
},
"exclude_state": { "exclude_state": {
"default": [], "default": [],
"env": "EXCLUDE_STATE", "env": "EXCLUDE_STATE",