Thank you I have resolved the issue.
I also tried to use the interfaces to create and record the metrics. I have tested with following codes and found that the value of the metrcis will be overrided by the last value of the metrics.
For example:
real situation is:
service1 -> ldap_query_success{...} 0
service2 -> ldap_query_success{...} 0
service3 -> ldap_query_success{...} 1
but with the following codes:
service1 -> ldap_query_success{...} 1
service2 -> ldap_query_success{...} 1
service3 -> ldap_query_success{...} 1
from prometheus_client import Gauge, write_to_textfile, CollectorRegistry
for service in services:
g1 = Gauge('ldap_query_success', 'LDAP query command', ['ldap_uri', 'ldap_search_base'], registry=registry)
g1.labels(service,ldap_search_base,ldap_default_bind_dn).set(query_check)
write_to_textfile("/var/log node_exporter/filecollector/ldap_query.prom", registry)