Skip to content

Commit

Permalink
Fixes metrics by displaying custom metrics in the default metrics end…
Browse files Browse the repository at this point in the history
…point (#428)

* first

* added documentation

* Added go.* files
  • Loading branch information
WilliamMortlMicrosoft authored Oct 30, 2019
1 parent acc3a61 commit 8bc4feb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
8 changes: 8 additions & 0 deletions docs/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,11 @@
```shell
kubectl logs <podname> -c manager -n azureoperator-system
```

7. In order to view the Prometheus metrics, you can redirect port 8080 to the local machine using the following command:

```shell
kubectl port-forward deployment/controller-manager 8080
```

Then, open a web browser and navigate to the [Metrics Endpoint](http://127.0.0.1:8080/metrics).
2 changes: 2 additions & 0 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@
2019-09-24T12:28:20.331-0600 DEBUG controller-runtime.manager.events Normal {"object": {"kind":"AzureSqlServer","namespace":"default","name":"sqlserver-sample1","uid":"ed3774af-def8-11e9-90c4-025000000001","apiVersion":"azure.microsoft.com/v1alpha1","resourceVersion":"194518"}, "reason": "Provisioned", "message": "sqlserver sqlserver-sample1 provisioned "}
```

8. Once the operator is running locally, in order to view debugging (Prometheus-based) metrics for the Azure operator, open a web browser and navigate to the [Metrics Endpoint](http://127.0.0.1:8080/metrics).

## Developing using VSCode with Remote - Containers

If you're using VSCode with [Remote - Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extensions installed, you can quickly have your environment set up and ready to go, with everything you need to get started.
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ github.com/prometheus/client_golang v0.9.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXP
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829 h1:D+CiwcpGTW6pL6bv6KI3KbyEyCKyS+1JWS2h8PNDnGA=
github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs=
github.com/prometheus/client_golang v1.2.1 h1:JnMpQc6ppsNgw9QPAGF6Dod479itz7lvlsMzzNayLOI=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910 h1:idejC8f05m9MGOsuEi1ATq9shN03HrxNkD/luQvxCv8=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f h1:BVwpUVJDADN2ufcGik7W992pyps0wZ888b/y9GXcLTU=
Expand Down
19 changes: 13 additions & 6 deletions pkg/telemetry/prometheus_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (

log "github.com/go-logr/logr"
"github.com/prometheus/client_golang/prometheus"

ctrlmetrics "sigs.k8s.io/controller-runtime/pkg/metrics"
)

var (
Expand Down Expand Up @@ -76,7 +78,8 @@ func initializeGlobalPrometheusMetricsEtc() {
prometheus.CounterOpts{
Namespace: *namespace,
Subsystem: *subsystem,
Name: "Info",
Name: "Status",
Help: "Status messages",
},
[]string{
"component",
Expand All @@ -85,7 +88,7 @@ func initializeGlobalPrometheusMetricsEtc() {
"message",
},
)
prometheus.MustRegister(statusCounter)
ctrlmetrics.Registry.MustRegister(statusCounter)

executionTime = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Expand All @@ -96,46 +99,50 @@ func initializeGlobalPrometheusMetricsEtc() {
exeuctionTimeStart,
exeuctionTimeWidth,
executionTimeBuckets),
Help: "Time to execute",
},
[]string{
"component",
},
)
prometheus.MustRegister(executionTime)
ctrlmetrics.Registry.MustRegister(executionTime)

activeGuage = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: *namespace,
Subsystem: *subsystem,
Name: "ActiveGuage",
Help: "How many active segments of code",
},
[]string{
"component",
},
)
prometheus.MustRegister(activeGuage)
ctrlmetrics.Registry.MustRegister(activeGuage)

successCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: *namespace,
Subsystem: *subsystem,
Name: "Success",
Help: "Count of Successes",
},
[]string{
"component",
},
)
prometheus.MustRegister(successCounter)
ctrlmetrics.Registry.MustRegister(successCounter)

failureCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: *namespace,
Subsystem: *subsystem,
Name: "Failure",
Help: "Count of Failures",
},
[]string{
"component",
},
)
prometheus.MustRegister(failureCounter)
ctrlmetrics.Registry.MustRegister(failureCounter)
}

0 comments on commit 8bc4feb

Please # to comment.