But the following 3 lines should be appended to a file first, then next 
time override the old content. But how to make the old content be overried 
by previous ones?

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+"))

On Monday, August 8, 2022 at 4:43:00 PM UTC+8 Stuart Clark wrote:

> 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/defc65f8-744c-4428-97e6-a04e07e2c157n%40googlegroups.com.

Reply via email to