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

prometheus metrics #231 #244

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ This driver allows Kubernetes to access LocalStorage on Linux node.
test-pvc Bound pvc-2b2c809f-33b5-437f-a4b8-61906c10a3e1 1Mi RWX pixiu-localstorage 5s
```

## Metrics
- [metrics](./docs/metrics.md)

## Feature
- Schedule with volume status
- Volume metrics
Expand Down
27 changes: 22 additions & 5 deletions cmd/localstorage-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/caoyingjunz/csi-driver-localstorage/pkg/client/clientset/versioned"
"github.com/caoyingjunz/csi-driver-localstorage/pkg/client/informers/externalversions"
"github.com/caoyingjunz/csi-driver-localstorage/pkg/controller/storage"
"github.com/caoyingjunz/csi-driver-localstorage/pkg/metrics"
"github.com/caoyingjunz/csi-driver-localstorage/pkg/runtime"
"github.com/caoyingjunz/csi-driver-localstorage/pkg/signals"
"github.com/caoyingjunz/csi-driver-localstorage/pkg/util"
Expand Down Expand Up @@ -79,6 +80,10 @@ var (
resourceNamespace = flag.String("leader-elect-resource-namespace", ResourceNamespace, "The namespace of resource object that is used for locking during leader election.")
leaseDuration = flag.Int("leader-elect-lease-duration", LeaseDuration, "The duration that non-leader candidates will wait")
renewDeadline = flag.Int("leader-elect-renew-deadline", RenewDeadline, "The interval between attempts by the acting master to renew a leadership slot before it stops leading.")

// metrics
metricsPort = flag.Int("metrics-port", 0, "metricsPort is the port of the localhost metrics endpoint (set to 0 to disable)")
interval = flag.Duration("metrics-interval", 10, "metricsInterval is the interval of the metrics collection, in seconds (default 10s)")
)

func init() {
Expand Down Expand Up @@ -127,12 +132,13 @@ func main() {
if err != nil {
klog.Fatalf("Failed to build kube clientSet: %v", err)
}
run := func(ctx context.Context) {
lsClientSet, err := versioned.NewForConfig(kubeConfig)
if err != nil {
klog.Fatalf("Failed to new localstorage clientSet: %v", err)
}

lsClientSet, err := versioned.NewForConfig(kubeConfig)
if err != nil {
klog.Fatalf("Failed to new localstorage clientSet: %v", err)
}

run := func(ctx context.Context) {
sharedInformer := externalversions.NewSharedInformerFactory(lsClientSet, 300*time.Second)
sc, err := storage.NewStorageController(ctx,
sharedInformer.Storage().V1().LocalStorages(),
Expand Down Expand Up @@ -164,6 +170,17 @@ func main() {
}, 5*time.Second, wait.NeverStop)
}

if *metricsPort > 0 {
mux := http.NewServeMux()
metrics.InstallHandler(mux, "/metrics")
metrics.TimingAcquisition(ctx, lsClientSet, *interval*time.Second)
go func() {
if err = http.ListenAndServe(net.JoinHostPort("", strconv.Itoa(*metricsPort)), mux); err != nil {
klog.ErrorS(err, "Failed to start metrics server")
}
}()
}

if !*leaderElect {
run(ctx)
klog.Fatalf("unreachable")
Expand Down
3 changes: 3 additions & 0 deletions deploy/latest/ls-controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ spec:
- -v=2
# port's value equals 0 means health check func disabled
- --healthz-port=10258
- --metrics-port=10259
# default metrics interval is 10s
- --metrics-interval=10
- --cert-dir=/tmp/cert
- --port=8443
image: harbor.powerlaw.club/pixiuio/localstorage-controller:latest
Expand Down
Binary file added docs/images/localstorage_controller.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading