-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom_exporter.py
More file actions
55 lines (41 loc) · 1.62 KB
/
Copy pathcustom_exporter.py
File metadata and controls
55 lines (41 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os
import sys
import syslog
import time
from sessions import sso_session
from prometheus_client import start_http_server, Info
from prometheus_client.core import REGISTRY
from gathers.rds_metrics_gather import RDSMetricsCollector
from gathers.health_metrics_gather import HealthMetricsCollector
from gathers.ec2_metrics_gather import EC2MetricsCollector
#from gathers.elb_metrics_gather import ELBMetricsCollector
# Establecemos el path del proyecto
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
# Registrar el colector personalizado
try:
## Colector eventos AWS Health
REGISTRY.register(HealthMetricsCollector())
## Colector EC2
REGISTRY.register(EC2MetricsCollector())
## Colector RDS
REGISTRY.register(RDSMetricsCollector())
## Colector IAM
REGISTRY.register(IAMMetricsCollector())
## Colector ELB
# REGISTRY.register(ELBMetricsCollector())
except Exception as e:
syslog.syslog(syslog.LOG_ERR, f'Error al registrar colectores: {str(e)}')
print(f'Error al registrar colectores: {str(e)}') # Imprime el error en la consola para depuración
sys.exit(1) # Termina el programa si no se pueden registrar los colectores
# Inicia el servidor Prometheus en el puerto especificado
print("Iniciando el servidor Prometheus en el puerto", sso_session.port)
start_http_server(sso_session.port)
# Definimos la versión del exporter
i = Info('custom_exporter_version', 'Info')
i.info({'version': '1.0.0', 'Author': 'Jesus Frontelo'})
# Mantén el script en ejecución
try:
while True:
time.sleep(60)
except KeyboardInterrupt:
print("Interrumpido por el usuario")