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 29, 2023
1 parent 732f847 commit 9802737
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
6 changes: 3 additions & 3 deletions cmd/localstorage-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main
import (
"context"
"flag"
"github.com/caoyingjunz/csi-driver-localstorage/pkg/metrics"
"net"
"net/http"
"os"
Expand All @@ -39,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 @@ -84,7 +84,7 @@ var (
// metrics
metricsPort = flag.Int("metrics-port", 0, "metricsPort is the port of the localhost metrics endpoint (set to 0 to disable)")
metricsPath = flag.String("metrics-path", "/metrics", "metricsPath is the path of the localhost metrics endpoint")
interval = flag.Duration("metrics-interval", 10*time.Second, "metricsInterval is the interval of the metrics collection")
interval = flag.Duration("metrics-interval", 10, "metricsInterval is the interval of the metrics collection, in seconds (default 10s)")
)

func init() {
Expand Down Expand Up @@ -173,7 +173,7 @@ func main() {
if *metricsPort > 0 {
mux := http.NewServeMux()
metrics.InstallHandler(mux, *metricsPath)
if err := metrics.TimingAcquisition(ctx, *interval); err != nil {
if err := metrics.TimingAcquisition(ctx, *interval*time.Second); err != nil {
klog.ErrorS(err, "Init metrics failed")
}
go wait.Until(func() {
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
- --metrics-path=/metrics
- --metrics-interval=10
- --cert-dir=/tmp/cert
- --port=8443
image: harbor.powerlaw.club/pixiuio/localstorage-controller:latest
Expand Down
14 changes: 8 additions & 6 deletions pkg/metrics/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ package metrics

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"
"net/http"
"path/filepath"
"time"

metaV1 "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"

"github.com/caoyingjunz/csi-driver-localstorage/pkg/client/clientset/versioned"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)

var (
Expand Down

0 comments on commit 9802737

Please sign in to comment.