Skip to content

Commit

Permalink
Introduce metrics & servicemonitors
Browse files Browse the repository at this point in the history
  • Loading branch information
lucemans committed Jan 26, 2025
1 parent b513f94 commit 92813bd
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
- [Containers](./containers/index.md)
- [Kubernetes](./containers/k8s/index.md)
- [RBAC](./containers/k8s/rbac.md)
- [Metrics & Service Monitors](./containers/k8s/metrics.md)
39 changes: 39 additions & 0 deletions src/containers/k8s/metrics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Metrics & Service Monitors

To keep track of the health of your services you can setup a [monitoring.coreos.com/v1.ServiceMonitor](https://prometheus-operator.dev/docs/api-reference/api/#monitoring.coreos.com/v1.ServiceMonitor) resource.

This resource defines a service that will be monitored, and what endpoints, authentication, interval, etc to use.

## Creating your first ServiceMonitor

To create a ServiceMonitor you need to create a `ServiceMonitor` resource.

```yaml
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: my-service-monitor
namespace: my-app
spec:
selector:
matchLabels:
app: my-app
endpoints:
- port: http
interval: 30s
path: /metrics
```
The above service monitor will monitor the `http` port on the `my-app` namespace, and will scrape the `/metrics` endpoint every 30 seconds.

## Service Implementation

On the side of your service you will need to expose an http endpoint (generally `/metrics`) that returns the metrics in a format that Prometheus can scrape.

An example of what this output might look like is:

```yaml
# HELP my_metric_1 A metric
# TYPE my_metric_1 gauge
my_metric_1 1.0
```

0 comments on commit 92813bd

Please sign in to comment.