Improve WriteToTextfile doc

Signed-off-by: Sevag Hanssian <sevag.hanssian@gmail.com>
This commit is contained in:
Sevag Hanssian 2018-11-02 09:31:30 -07:00
parent 42e6616334
commit 924d5919f3
No known key found for this signature in database
GPG Key ID: 15472D208B254CF4
1 changed files with 6 additions and 3 deletions

View File

@ -537,9 +537,12 @@ func (r *Registry) Gather() ([]*dto.MetricFamily, error) {
return internal.NormalizeMetricFamilies(metricFamiliesByName), errs.MaybeUnwrap() return internal.NormalizeMetricFamilies(metricFamiliesByName), errs.MaybeUnwrap()
} }
// WriteToTextfile formats the metrics of the provided Gatherer interface and // WriteToTextfile calls Gather on the provided Gatherer, encodes the result in the
// emits them in text format to the path. Intended for use with the node_exporter // Prometheus text format, and writes it to a temporary file. Upon success, the
// textfile collector // temporary file is renamed to the provided filename.
//
// This is intended for use with the textfile collector of the node exporter.
// Note that the node exporter expects the filename to be suffixed with ".prom".
func WriteToTextfile(filename string, g Gatherer) error { func WriteToTextfile(filename string, g Gatherer) error {
tmp, err := ioutil.TempFile(filepath.Dir(filename), filepath.Base(filename)) tmp, err := ioutil.TempFile(filepath.Dir(filename), filepath.Base(filename))
if err != nil { if err != nil {