Back to Nightingale

prometheus

integrations/Prometheus/markdown/README.en_US.md

9.1.11.9 KB
Original Source

prometheus

The prometheus plugin scrapes data from /metrics endpoints and reports it to the server. Typically, all kinds of exporters expose data on a /metrics endpoint, and more and more open-source components also embed the prometheus SDK and emit monitoring data in prometheus format — the rabbitmq plugin, for example, describes this in its README.

This plugin was forked from telegraf/prometheus with some trimming and refactoring. It still supports service discovery via consul to manage all target addresses, but the Kubernetes part was removed — that is planned to be implemented in other plugins.

Two configuration options were added: url_label_key and url_label_value. To identify which scrape url the monitoring data was pulled from, a label is attached to the monitoring data to identify that url. The default label KEY is instance; you can change it to something else, though that is not recommended. url_label_value is the label value and supports go template syntax. If it is empty, the whole url is used; you can also use template variables to take only part of it. For example, for http://localhost:9104/metrics, if you only want the IP and port part, you can write:

ini
url_label_value = "{{.Host}}"

If you want both the HTTP scheme part and the /metrics Path part, you can write it like this:

ini
url_label_value = "{{.Scheme}}://{{.Host}}{{.Path}}"

The related variables are generated by this method, for your reference:

go
func (ul *UrlLabel) GenerateLabel(u *url.URL) (string, string, error) {
	if ul.LabelValue == "" {
		return ul.LabelKey, u.String(), nil
	}

	dict := map[string]string{
		"Scheme":   u.Scheme,
		"Host":     u.Host,
		"Hostname": u.Hostname(),
		"Port":     u.Port(),
		"Path":     u.Path,
		"Query":    u.RawQuery,
		"Fragment": u.Fragment,
	}

	var buffer bytes.Buffer
	err := ul.LabelValueTpl.Execute(&buffer, dict)
	if err != nil {
		return "", "", err
	}

	return ul.LabelKey, buffer.String(), nil
}