Skip to content

Commit

Permalink
prometheus metrics caoyingjunz#231
Browse files Browse the repository at this point in the history
  • Loading branch information
aide-cloud committed Jul 28, 2023
1 parent 1ed35f2 commit a0585ce
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 1 addition & 3 deletions cmd/localstorage-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"flag"
"github.com/caoyingjunz/csi-driver-localstorage/pkg/metrics"
"github.com/prometheus/client_golang/prometheus/promhttp"
"net"
"net/http"
"os"
Expand Down Expand Up @@ -172,8 +171,7 @@ func main() {

if *metricsPort > 0 {
mux := http.NewServeMux()
mux.Handle(*metricsPath, promhttp.Handler())

metrics.InstallHandler(mux, *metricsPath)
go wait.Until(func() {
err := metrics.TimingAcquisition(ctx, *interval)
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions pkg/metrics/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import (
"context"
"github.com/caoyingjunz/csi-driver-localstorage/pkg/client/clientset/versioned"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/homedir"
"k8s.io/klog/v2"
"net/http"
"path/filepath"
"time"
)
Expand All @@ -35,6 +37,11 @@ func init() {
prometheus.MustRegister(VolumesTotalGauge, VolumeSizeGauge)
}

// InstallHandler registers the prometheus handler
func InstallHandler(mux *http.ServeMux, path string) {
mux.Handle(path, promhttp.Handler())
}

// RegisterVolumeSize registers the size of localstorage volumes
func RegisterVolumeSize(volId, volName, volPath string, size float64) {
VolumeSizeGauge.WithLabelValues(volId, volName, volPath).Set(size)
Expand Down

0 comments on commit a0585ce

Please sign in to comment.