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 9bdfc9930e
commit 5fe59e1f72
Signed by: xoxys
GPG Key ID: 4E692A2EAECC03C0
3 changed files with 290 additions and 2 deletions

273
boo Normal file
View File

@ -0,0 +1,273 @@
[
{
"targets": [
"goldbug.rknet.org"
],
"labels": {
"__meta_pve_ip": "10.168.65.7",
"__meta_pve_name": "goldbug.rknet.org",
"__meta_pve_type": "qemu",
"__meta_pve_vmid": "104",
"__meta_pve_cpu": "1",
"__meta_pve_cores": "2",
"__meta_pve_memory": "2048",
"__meta_pve_status": "running",
"__meta_pve_groups": "lan,redhat,s_jellyfin,t_jellyfin"
}
},
{
"targets": [
"skyfire.rknet.org"
],
"labels": {
"__meta_pve_ip": "10.168.64.131",
"__meta_pve_name": "skyfire.rknet.org",
"__meta_pve_type": "qemu",
"__meta_pve_vmid": "201",
"__meta_pve_cpu": "1",
"__meta_pve_cores": "1",
"__meta_pve_memory": "512",
"__meta_pve_status": "running",
"__meta_pve_groups": "dmz,redhat,s_ldapproxy,t_openldap"
}
},
{
"targets": [
"ironhide.rknet.org"
],
"labels": {
"__meta_pve_ip": "10.168.64.199",
"__meta_pve_name": "ironhide.rknet.org",
"__meta_pve_type": "qemu",
"__meta_pve_vmid": "304",
"__meta_pve_cpu": "1",
"__meta_pve_cores": "1",
"__meta_pve_memory": "1024",
"__meta_pve_status": "running",
"__meta_pve_groups": "management,redhat,s_prometheus,t_prometheus"
}
},
{
"targets": [
"firestar.rknet.org"
],
"labels": {
"__meta_pve_ip": "10.168.65.6",
"__meta_pve_name": "firestar.rknet.org",
"__meta_pve_type": "qemu",
"__meta_pve_vmid": "103",
"__meta_pve_cpu": "1",
"__meta_pve_cores": "1",
"__meta_pve_memory": "1024",
"__meta_pve_status": "running",
"__meta_pve_groups": "lan,redhat,t_postgres,s_homeassistant"
}
},
{
"targets": [
"metroplex.rknet.org"
],
"labels": {
"__meta_pve_ip": "10.168.64.197",
"__meta_pve_name": "metroplex.rknet.org",
"__meta_pve_type": "qemu",
"__meta_pve_vmid": "302",
"__meta_pve_cpu": "1",
"__meta_pve_cores": "1",
"__meta_pve_memory": "1024",
"__meta_pve_status": "running",
"__meta_pve_groups": "management,redhat,s_pve,s_unifi,s_prometheus,t_webproxy"
}
},
{
"targets": [
"slingshot.rknet.org"
],
"labels": {
"__meta_pve_ip": "10.168.64.195",
"__meta_pve_name": "slingshot.rknet.org",
"__meta_pve_type": "qemu",
"__meta_pve_vmid": "300",
"__meta_pve_cpu": "1",
"__meta_pve_cores": "2",
"__meta_pve_memory": "1024",
"__meta_pve_status": "running",
"__meta_pve_groups": "management,redhat,s_adminstation"
}
},
{
"targets": [
"blaster.rknet.org"
],
"labels": {
"__meta_pve_ip": "blaster.rknet.org",
"__meta_pve_name": "blaster.rknet.org",
"__meta_pve_type": "qemu",
"__meta_pve_vmid": "100",
"__meta_pve_cpu": "1",
"__meta_pve_cores": "2",
"__meta_pve_memory": "2048",
"__meta_pve_status": "running",
"__meta_pve_groups": "debian_ucs,lan,s_scan2mail,s_ucs,t_scan2mail,t_ucs"
}
},
{
"targets": [
"huffer.rknet.org"
],
"labels": {
"__meta_pve_ip": "10.168.65.5",
"__meta_pve_name": "huffer.rknet.org",
"__meta_pve_type": "qemu",
"__meta_pve_vmid": "102",
"__meta_pve_cpu": "1",
"__meta_pve_cores": "1",
"__meta_pve_memory": "512",
"__meta_pve_status": "running",
"__meta_pve_groups": "lan,redhat,s_cups,s_valetudo,t_cups,t_webproxy"
}
},
{
"targets": [
"inferno.rknet.org"
],
"labels": {
"__meta_pve_ip": "10.168.64.198",
"__meta_pve_name": "inferno.rknet.org",
"__meta_pve_type": "qemu",
"__meta_pve_vmid": "303",
"__meta_pve_cpu": "1",
"__meta_pve_cores": "1",
"__meta_pve_memory": "1024",
"__meta_pve_status": "running",
"__meta_pve_groups": "management,redhat,t_postgres"
}
},
{
"targets": [
"slag.rknet.org"
],
"labels": {
"__meta_pve_ip": "10.168.64.133",
"__meta_pve_name": "slag.rknet.org",
"__meta_pve_type": "qemu",
"__meta_pve_vmid": "203",
"__meta_pve_cpu": "1",
"__meta_pve_cores": "1",
"__meta_pve_memory": "1024",
"__meta_pve_status": "running",
"__meta_pve_groups": "dmz,redhat,s_vaultwarden,s_freshrss,s_kanboard,s_authelia,t_postgres"
}
},
{
"targets": [
"tailgate.rknet.org"
],
"labels": {
"__meta_pve_ip": "10.168.64.130",
"__meta_pve_name": "tailgate.rknet.org",
"__meta_pve_type": "qemu",
"__meta_pve_vmid": "200",
"__meta_pve_cpu": "1",
"__meta_pve_cores": "1",
"__meta_pve_memory": "1024",
"__meta_pve_status": "running",
"__meta_pve_groups": "dmz,redhat,s_homeassistant,t_mqtt"
}
},
{
"targets": [
"hook.rknet.org"
],
"labels": {
"__meta_pve_ip": "10.168.64.132",
"__meta_pve_name": "hook.rknet.org",
"__meta_pve_type": "qemu",
"__meta_pve_vmid": "202",
"__meta_pve_cpu": "1",
"__meta_pve_cores": "1",
"__meta_pve_memory": "1024",
"__meta_pve_status": "running",
"__meta_pve_groups": "dmz,redhat,s_vaultwarden,s_freshrss,s_kanboard,s_authelia,t_webproxy,t_authelia"
}
},
{
"targets": [
"lightspeed.rknet.org"
],
"labels": {
"__meta_pve_ip": "10.168.64.134",
"__meta_pve_name": "lightspeed.rknet.org",
"__meta_pve_type": "qemu",
"__meta_pve_vmid": "204",
"__meta_pve_cpu": "1",
"__meta_pve_cores": "1",
"__meta_pve_memory": "1024",
"__meta_pve_status": "running",
"__meta_pve_groups": "dmz,redhat"
}
},
{
"targets": [
"CentOS7Master"
],
"labels": {
"__meta_pve_ip": "CentOS7Master",
"__meta_pve_name": "CentOS7Master",
"__meta_pve_type": "qemu",
"__meta_pve_vmid": "950",
"__meta_pve_cpu": "1",
"__meta_pve_cores": "1",
"__meta_pve_memory": "1024",
"__meta_pve_status": "stopped"
}
},
{
"targets": [
"vortex.rknet.org"
],
"labels": {
"__meta_pve_ip": "10.168.65.4",
"__meta_pve_name": "vortex.rknet.org",
"__meta_pve_type": "qemu",
"__meta_pve_vmid": "101",
"__meta_pve_cpu": "1",
"__meta_pve_cores": "1",
"__meta_pve_memory": "1024",
"__meta_pve_status": "running",
"__meta_pve_groups": "lan,redhat,s_homeassistant,s_jellyfin,t_webproxy"
}
},
{
"targets": [
"cerebros.rknet.org"
],
"labels": {
"__meta_pve_ip": "10.168.64.196",
"__meta_pve_name": "cerebros.rknet.org",
"__meta_pve_type": "qemu",
"__meta_pve_vmid": "301",
"__meta_pve_cpu": "1",
"__meta_pve_cores": "1",
"__meta_pve_memory": "1024",
"__meta_pve_status": "running",
"__meta_pve_groups": "management,redhat,s_unifi,t_unifi"
}
},
{
"targets": [
"alana.rknet.org"
],
"labels": {
"__meta_pve_ip": "10.168.64.135",
"__meta_pve_name": "alana.rknet.org",
"__meta_pve_type": "qemu",
"__meta_pve_vmid": "205",
"__meta_pve_cpu": "1",
"__meta_pve_cores": "2",
"__meta_pve_memory": "4096",
"__meta_pve_status": "running",
"__meta_pve_groups": "dmz,redhat,s_vaultwarden,s_freshrss,s_kanboard,t_vaultwarden,t_dockerengine,t_freshrss,t_kanboard"
}
}
]

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",