mirror of
https://github.com/kubernetes-sigs/prometheus-adapter.git
synced 2026-04-06 01:38:10 +00:00
commit
b3dfbe1b29
7 changed files with 19 additions and 20 deletions
|
|
@ -9,18 +9,18 @@ Per-pod HTTP Requests
|
||||||
|
|
||||||
### Background
|
### Background
|
||||||
|
|
||||||
*The [full walkthrough](/docs/walkthrough.md) sets up a the background for
|
*The [full walkthrough](/docs/walkthrough.md) sets up the background for
|
||||||
something like this*
|
something like this*
|
||||||
|
|
||||||
Suppose we have some frontend webserver, and we're trying to write an
|
Suppose we have some frontend webserver, and we're trying to write a
|
||||||
configuration for the Promtheus adapter so that we can autoscale it based
|
configuration for the Prometheus adapter so that we can autoscale it based
|
||||||
on the HTTP requests per second that it receives.
|
on the HTTP requests per second that it receives.
|
||||||
|
|
||||||
Before starting, we've gone and instrumented our frontend server with
|
Before starting, we've gone and instrumented our frontend server with
|
||||||
a metric, `http_requests_total`. It is exposed with a single label,
|
a metric, `http_requests_total`. It is exposed with a single label,
|
||||||
`method`, breaking down the requests by HTTP verb.
|
`method`, breaking down the requests by HTTP verb.
|
||||||
|
|
||||||
We've configured our Prometheus to collect the metric, and our promethues
|
We've configured our Prometheus to collect the metric, and it
|
||||||
adds the `kubernetes_namespace` and `kubernetes_pod_name` labels,
|
adds the `kubernetes_namespace` and `kubernetes_pod_name` labels,
|
||||||
representing namespace and pod, respectively.
|
representing namespace and pod, respectively.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -179,7 +179,7 @@ template:
|
||||||
group-resource, plus the label for namespace, if the group-resource is
|
group-resource, plus the label for namespace, if the group-resource is
|
||||||
namespaced.
|
namespaced.
|
||||||
- `GroupBy`: a comma-separated list of labels to group by. Currently,
|
- `GroupBy`: a comma-separated list of labels to group by. Currently,
|
||||||
this contains the group-resoure label used in `LabelMarchers`.
|
this contains the group-resource label used in `LabelMatchers`.
|
||||||
|
|
||||||
For instance, suppose we had a series `http_requests_total` (exposed as
|
For instance, suppose we had a series `http_requests_total` (exposed as
|
||||||
`http_requests_per_second` in the API) with labels `service`, `pod`,
|
`http_requests_per_second` in the API) with labels `service`, `pod`,
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ Detailed instructions can be found in the Kubernetes documentation under
|
||||||
[Horizontal Pod
|
[Horizontal Pod
|
||||||
Autoscaling](https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#support-for-custom-metrics).
|
Autoscaling](https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#support-for-custom-metrics).
|
||||||
|
|
||||||
Make sure that you've properly configured metrics-server (as is default in
|
Make sure that you've properly configured metrics-server (as default in
|
||||||
Kubernetes 1.9+), or enabling custom metrics autoscaling support will
|
Kubernetes 1.9+), or enabling custom metrics autoscaling support will
|
||||||
disable CPU autoscaling support.
|
disable CPU autoscaling support.
|
||||||
|
|
||||||
|
|
@ -34,14 +34,13 @@ significantly different.
|
||||||
In order to follow this walkthrough, you'll need container images for
|
In order to follow this walkthrough, you'll need container images for
|
||||||
Prometheus and the custom metrics adapter.
|
Prometheus and the custom metrics adapter.
|
||||||
|
|
||||||
It's easiest to deploy Prometheus with the [Prometheus
|
The [Prometheus Operator](https://coreos.com/operators/prometheus/docs/latest/),
|
||||||
Operator](https://coreos.com/operators/prometheus/docs/latest/), which
|
|
||||||
makes it easy to get up and running with Prometheus. This walkthrough
|
makes it easy to get up and running with Prometheus. This walkthrough
|
||||||
will assume you're planning on doing that -- if you've deployed it by hand
|
will assume you're planning on doing that -- if you've deployed it by hand
|
||||||
instead, you'll need to make a few adjustments to the way you expose
|
instead, you'll need to make a few adjustments to the way you expose
|
||||||
metrics to Prometheus.
|
metrics to Prometheus.
|
||||||
|
|
||||||
The adapter has different images for each arch, and can be found at
|
The adapter has different images for each arch, which can be found at
|
||||||
`directxman12/k8s-prometheus-adapter-${ARCH}`. For instance, if you're on
|
`directxman12/k8s-prometheus-adapter-${ARCH}`. For instance, if you're on
|
||||||
an x86_64 machine, use the `directxman12/k8s-prometheus-adapter-amd64`
|
an x86_64 machine, use the `directxman12/k8s-prometheus-adapter-amd64`
|
||||||
image.
|
image.
|
||||||
|
|
@ -172,7 +171,7 @@ for the Operator to deploy a copy of Prometheus.
|
||||||
|
|
||||||
This walkthrough assumes that Prometheus is deployed in the `prom`
|
This walkthrough assumes that Prometheus is deployed in the `prom`
|
||||||
namespace. Most of the sample commands and files are namespace-agnostic,
|
namespace. Most of the sample commands and files are namespace-agnostic,
|
||||||
but there are a few commands or pieces of configuration that rely on
|
but there are a few commands or pieces of configuration that rely on that
|
||||||
namespace. If you're using a different namespace, simply substitute that
|
namespace. If you're using a different namespace, simply substitute that
|
||||||
in for `prom` when it appears.
|
in for `prom` when it appears.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,14 +22,14 @@ import (
|
||||||
|
|
||||||
// LabelNeq produces a not-equal label selector expression.
|
// LabelNeq produces a not-equal label selector expression.
|
||||||
// Label is passed verbatim, and value is double-quote escaped
|
// Label is passed verbatim, and value is double-quote escaped
|
||||||
// using Go's escaping is used on value (as per the PromQL rules).
|
// using Go's escaping (as per the PromQL rules).
|
||||||
func LabelNeq(label string, value string) string {
|
func LabelNeq(label string, value string) string {
|
||||||
return fmt.Sprintf("%s!=%q", label, value)
|
return fmt.Sprintf("%s!=%q", label, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// LabelEq produces a equal label selector expression.
|
// LabelEq produces a equal label selector expression.
|
||||||
// Label is passed verbatim, and value is double-quote escaped
|
// Label is passed verbatim, and value is double-quote escaped
|
||||||
// using Go's escaping is used on value (as per the PromQL rules).
|
// using Go's escaping (as per the PromQL rules).
|
||||||
func LabelEq(label string, value string) string {
|
func LabelEq(label string, value string) string {
|
||||||
return fmt.Sprintf("%s=%q", label, value)
|
return fmt.Sprintf("%s=%q", label, value)
|
||||||
}
|
}
|
||||||
|
|
@ -52,7 +52,7 @@ func NameMatches(expr string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NameNotMatches produces a label selector expression that checks that the series name doesn't matches the given expression.
|
// NameNotMatches produces a label selector expression that checks that the series name doesn't matches the given expression.
|
||||||
// It's a convinience wrapper around LabelNotMatches.
|
// It's a convenience wrapper around LabelNotMatches.
|
||||||
func NameNotMatches(expr string) string {
|
func NameNotMatches(expr string) string {
|
||||||
return LabelNotMatches("__name__", expr)
|
return LabelNotMatches("__name__", expr)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,13 +7,13 @@ import (
|
||||||
type MetricsDiscoveryConfig struct {
|
type MetricsDiscoveryConfig struct {
|
||||||
// Rules specifies how to discover and map Prometheus metrics to
|
// Rules specifies how to discover and map Prometheus metrics to
|
||||||
// custom metrics API resources. The rules are applied independently,
|
// custom metrics API resources. The rules are applied independently,
|
||||||
// and thus must be mutually exclusive. Rules will the same SeriesQuery
|
// and thus must be mutually exclusive. Rules with the same SeriesQuery
|
||||||
// will make only a single API call.
|
// will make only a single API call.
|
||||||
Rules []DiscoveryRule `yaml:"rules"`
|
Rules []DiscoveryRule `yaml:"rules"`
|
||||||
ResourceRules *ResourceRules `yaml:"resourceRules,omitempty"`
|
ResourceRules *ResourceRules `yaml:"resourceRules,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// DiscoveryRule describes on set of rules for transforming Prometheus metrics to/from
|
// DiscoveryRule describes a set of rules for transforming Prometheus metrics to/from
|
||||||
// custom metrics API resources.
|
// custom metrics API resources.
|
||||||
type DiscoveryRule struct {
|
type DiscoveryRule struct {
|
||||||
// SeriesQuery specifies which metrics this rule should consider via a Prometheus query
|
// SeriesQuery specifies which metrics this rule should consider via a Prometheus query
|
||||||
|
|
|
||||||
|
|
@ -23,11 +23,11 @@ var groupNameSanitizer = strings.NewReplacer(".", "_", "-", "_")
|
||||||
// themselves be normalized.
|
// themselves be normalized.
|
||||||
type MetricNamer interface {
|
type MetricNamer interface {
|
||||||
// Selector produces the appropriate Prometheus series selector to match all
|
// Selector produces the appropriate Prometheus series selector to match all
|
||||||
// series handlable by this namer.
|
// series handable by this namer.
|
||||||
Selector() prom.Selector
|
Selector() prom.Selector
|
||||||
// FilterSeries checks to see which of the given series match any additional
|
// FilterSeries checks to see which of the given series match any additional
|
||||||
// constrains beyond the series query. It's assumed that the series given
|
// constraints beyond the series query. It's assumed that the series given
|
||||||
// already matche the series query.
|
// already match the series query.
|
||||||
FilterSeries(series []prom.Series) []prom.Series
|
FilterSeries(series []prom.Series) []prom.Series
|
||||||
// MetricNameForSeries returns the name (as presented in the API) for a given series.
|
// MetricNameForSeries returns the name (as presented in the API) for a given series.
|
||||||
MetricNameForSeries(series prom.Series) (string, error)
|
MetricNameForSeries(series prom.Series) (string, error)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue