prometheus: do not repeat lines accumulated in containers (#86124)
gitea/publik-infra/pipeline/head This commit looks good Details

This commit is contained in:
Frédéric Péters 2024-01-25 17:30:15 +01:00
parent 74711c464f
commit 6b3e0ec208
1 changed files with 5 additions and 4 deletions

View File

@ -87,13 +87,14 @@ if app_name:
write_to_textfile('/var/lib/prometheus/node-exporter/uwsgi.prom', registry)
else:
# host for containers?
content = ''
content_lines = []
for machine_stat in glob.glob('/var/lib/machines/*/var/lib/prometheus/node-exporter/uwsgi.prom'):
with open(machine_stat) as fd:
content += fd.read()
if content:
file_lines = [x for x in fd.readlines() if x not in content_lines]
content_lines.extend(file_lines)
if content_lines:
with open('/var/lib/prometheus/node-exporter/uwsgi.prom.tmp', 'w') as fd:
fd.write(content)
fd.write(''.join(content_lines))
os.rename(
'/var/lib/prometheus/node-exporter/uwsgi.prom.tmp', '/var/lib/prometheus/node-exporter/uwsgi.prom'
)