String returns the metric in Prometheus text exposition format. Label values are empty strings and metric values are 0 since only metadata (name, type, help, label names) is used for documentation generation.
()
| 705 | // Label values are empty strings and metric values are 0 since only |
| 706 | // metadata (name, type, help, label names) is used for documentation generation. |
| 707 | func (m Metric) String() string { |
| 708 | var buf strings.Builder |
| 709 | |
| 710 | // Write HELP line. |
| 711 | _, _ = fmt.Fprintf(&buf, "# HELP %s %s\n", m.Name, m.Help) |
| 712 | |
| 713 | // Write TYPE line. |
| 714 | _, _ = fmt.Fprintf(&buf, "# TYPE %s %s\n", m.Name, m.Type) |
| 715 | |
| 716 | // Write a sample metric line with empty label values and zero metric value. |
| 717 | if len(m.Labels) > 0 { |
| 718 | labelPairs := make([]string, len(m.Labels)) |
| 719 | for i, l := range m.Labels { |
| 720 | labelPairs[i] = fmt.Sprintf("%s=\"\"", l) |
| 721 | } |
| 722 | _, _ = fmt.Fprintf(&buf, "%s{%s} 0\n", m.Name, strings.Join(labelPairs, ",")) |
| 723 | } else { |
| 724 | _, _ = fmt.Fprintf(&buf, "%s 0\n", m.Name) |
| 725 | } |
| 726 | |
| 727 | return buf.String() |
| 728 | } |
| 729 | |
| 730 | // writeMetrics writes all metrics in Prometheus text exposition format. |
| 731 | func writeMetrics(metrics []Metric, w io.Writer) { |
no outgoing calls