Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom prometheus metrics documentation #1045

Merged
merged 1 commit into from
Sep 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
- [controller-gen CLI](./reference/controller-gen.md)
- [Artifacts](./reference/artifacts.md)
- [Writing controller tests](./reference/writing-tests.md)
- [Metrics](./reference/metrics.md)

---

Expand Down
45 changes: 45 additions & 0 deletions docs/book/src/reference/metrics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Metrics

By default, controller-runtime builds a global prometheus registry and
publishes a collection of performance metrics for each controller.

## Publishing Additional Metrics

If you wish to publish additional metrics from your controllers, this
can be easily achieved by using the global registry from
`controller-runtime/pkg/metrics`.

One way to achieve this is to declare your collectors as global variables and then register them using `init()`.

For example:

```go
import (
"github.com/prometheus/client_golang/prometheus"
"sigs.k8s.io/controller-runtime/pkg/metrics"
)

var (
goobers = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "goobers_total",
Help: "Number of goobers proccessed",
},
)
gooberFailures = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "goober_failures_total",
Help: "Number of failed goobers",
},
)
)

func init() {
// Register custom metrics with the global prometheus registry
metrics.Registry.MustRegister(goobers, gooberFailures)
}
```

You may then record metrics to those collectors from any part of your
reconcile loop, and those metrics will be available for prometheus or
other openmetrics systems to scrape.
36 changes: 26 additions & 10 deletions docs/book/src/reference/reference.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
# Reference

- [Using Finalizers](./using-finalizers.md): Finalizers are a mechanism to
execute any custom logic related to a resource before it gets deleted from
Kubernetes cluster.
- [Webhooks](./webhook-overview.md): Webhooks are HTTP callbacks, there are 3
types of webhooks in k8s: 1) admission webhook 2) CRD conversion webhook 3)
authorization webhook

- [Admission Webhook](./admission-webhook.md): Admission webhooks are HTTP
callbacks for mutating or validating resources before the API server admit
them.
- [Generating CRDs](generating-crd.md)
- [Using Finalizers](using-finalizers.md)
Finalizers are a mechanism to
execute any custom logic related to a resource before it gets deleted from
Kubernetes cluster.
- [Kind cluster](kind.md)
- [What's a webhook?](webhook-overview.md)
Webhooks are HTTP callbacks, there are 3
types of webhooks in k8s: 1) admission webhook 2) CRD conversion webhook 3)
authorization webhook
- [Admission webhook](admission-webhook.md)
Admission webhooks are HTTP
callbacks for mutating or validating resources before the API server admit
them.
- [Markers for Config/Code Generation](markers.md)

- [CRD Generation](markers/crd.md)
- [CRD Validation](markers/crd-validation.md)
- [Webhook](markers/webhook.md)
- [Object/DeepCopy](markers/object.md)
- [RBAC](markers/rbac.md)

- [controller-gen CLI](controller-gen.md)
- [Artifacts](artifacts.md)
- [Writing controller tests](writing-tests.md)
- [Metrics](metrics.md)