On 2022-08-08 09:14, nina guo wrote:
Hi,

I used the following way to output the metrics and values to a file,
and let node exporter to scrape it.

I have a question here, how to let the next metrics value overide the
previous'?

I checked .prom file, there are some metrics with same labels and same
values of labels but different value of the metrics. It is not
correct. The next value of the metrics should override the previous
old value. But how to implement this?

print (" # HELP ldap_query_success LDAP query command",
file=open("/var/log/node_exporter/filecollector/ldap_query.prom",
"a+"))
 print (" # TYPE ldap_query_success gauge",
file=open("/var/log/node_exporter/filecollector/ldap_query.prom",
"a+"))
print
('ldap_query_success'+'{'+'ldap_uri'+'='+service+','+'ldap_search_base'+'='+ldap_search_base+','+'}
'+str(query_check),
file=open("/var/log/node_exporter/filecollector/ldap_query.prom",
"a+"))


You shouldn't be appending to an existing file, but instead replacing the file contents each time you do an update.

Depending on the tooling used it is often better to create a new file with a random non *.prom filename and then rename it into the correct name - renames are generally atomic whereas file updates often aren't, meaning if you modify the file directly you could end up reading part finished data.

--
Stuart Clark

--
You received this message because you are subscribed to the Google Groups 
"Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to prometheus-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/prometheus-users/661c81dacfd90b1b59ed060aed4101f2%40Jahingo.com.

Reply via email to