Skip to content

Commit

Permalink
feature: add cri metrics
Browse files Browse the repository at this point in the history
Signed-off-by: Starnop <[email protected]>
  • Loading branch information
starnop committed Oct 11, 2018
1 parent 149b75e commit 4a4983c
Show file tree
Hide file tree
Showing 20 changed files with 1,492 additions and 63 deletions.
72 changes: 11 additions & 61 deletions apis/metrics/metrics.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package metrics

import (
"fmt"
"sync"
"time"

util_metrics "github.com/alibaba/pouch/pkg/utils/metrics"

"github.com/prometheus/client_golang/prometheus"
)
Expand All @@ -14,34 +14,33 @@ func init() {
}

const (
namespace = "engine"
subsystem = "daemon"
subsystemPouch = "daemon"
)

var (
// ImagePullSummary records the summary of pulling image latency.
ImagePullSummary = newLabelSummary("image_pull_latency_microseconds", "Latency in microseconds to pull a image.", "image")
ImagePullSummary = util_metrics.NewLabelSummary(subsystemPouch, "image_pull_latency_microseconds", "Latency in microseconds to pull a image.", "image")

// ContainerActionsCounter records the number of container operations.
ContainerActionsCounter = newLabelCounter("container_actions_counter", "The number of container operations", "action")
ContainerActionsCounter = util_metrics.NewLabelCounter(subsystemPouch, "container_actions_counter", "The number of container operations", "action")

// ContainerSuccessActionsCounter records the number of container success operations.
ContainerSuccessActionsCounter = newLabelCounter("container_success_actions_counter", "The number of container success operations", "action")
ContainerSuccessActionsCounter = util_metrics.NewLabelCounter(subsystemPouch, "container_success_actions_counter", "The number of container success operations", "action")

// ImageActionsCounter records the number of image operations.
ImageActionsCounter = newLabelCounter("image_actions_counter", "The number of image operations", "action")
ImageActionsCounter = util_metrics.NewLabelCounter(subsystemPouch, "image_actions_counter", "The number of image operations", "action")

// ImageSuccessActionsCounter the number of image success operations.
ImageSuccessActionsCounter = newLabelCounter("image_success_actions_counter", "The number of image success operations", "action")
ImageSuccessActionsCounter = util_metrics.NewLabelCounter(subsystemPouch, "image_success_actions_counter", "The number of image success operations", "action")

// ContainerActionsTimer records the time cost of each container action.
ContainerActionsTimer = newLabelTimer("container_actions", "The number of seconds it takes to process each container action", "action")
ContainerActionsTimer = util_metrics.NewLabelTimer(subsystemPouch, "container_actions", "The number of seconds it takes to process each container action", "action")

// ImageActionsTimer records the time cost of each image action.
ImageActionsTimer = newLabelTimer("image_actions", "The number of seconds it takes to process each image action", "action")
ImageActionsTimer = util_metrics.NewLabelTimer(subsystemPouch, "image_actions", "The number of seconds it takes to process each image action", "action")

// EngineVersion records the version and commit information of the engine process.
EngineVersion = newLabelGauge("engine", "The version and commit information of the engine process", "commit")
EngineVersion = util_metrics.NewLabelGauge(subsystemPouch, "engine", "The version and commit information of the engine process", "commit")
)

var registerMetrics sync.Once
Expand All @@ -60,52 +59,3 @@ func Register() {
prometheus.MustRegister(ImageActionsTimer)
})
}

// SinceInMicroseconds gets the time since the specified start in microseconds.
func SinceInMicroseconds(start time.Time) float64 {
return float64(time.Since(start).Nanoseconds() / time.Microsecond.Nanoseconds())
}

func newLabelSummary(name, help string, labels ...string) *prometheus.SummaryVec {
return prometheus.NewSummaryVec(
prometheus.SummaryOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: name,
Help: help,
ConstLabels: nil,
}, labels)
}

func newLabelCounter(name, help string, labels ...string) *prometheus.CounterVec {
return prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: fmt.Sprintf("%s_%s", name, total),
Help: help,
ConstLabels: nil,
}, labels)
}

func newLabelGauge(name, help string, labels ...string) *prometheus.GaugeVec {
return prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: fmt.Sprintf("%s_%s", name, Unit("info")),
Help: help,
ConstLabels: nil,
}, labels)
}

func newLabelTimer(name, help string, labels ...string) *prometheus.HistogramVec {
return prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: fmt.Sprintf("%s_%s", name, seconds),
Help: help,
ConstLabels: nil,
}, labels)
}
3 changes: 2 additions & 1 deletion apis/server/image_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/alibaba/pouch/apis/types"
"github.com/alibaba/pouch/daemon/mgr"
"github.com/alibaba/pouch/pkg/httputils"
util_metrics "github.com/alibaba/pouch/pkg/utils/metrics"

"github.com/gorilla/mux"
"github.com/opencontainers/go-digest"
Expand All @@ -39,7 +40,7 @@ func (s *Server) pullImage(ctx context.Context, rw http.ResponseWriter, req *htt

// record the time spent during image pull procedure.
defer func(start time.Time) {
metrics.ImagePullSummary.WithLabelValues(image).Observe(metrics.SinceInMicroseconds(start))
metrics.ImagePullSummary.WithLabelValues(image).Observe(util_metrics.SinceInMicroseconds(start))
metrics.ImageActionsTimer.WithLabelValues(label).Observe(time.Since(start).Seconds())
}(time.Now())

Expand Down
97 changes: 97 additions & 0 deletions cri/metrics/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package metrics

import (
"sync"

util_metrics "github.com/alibaba/pouch/pkg/utils/metrics"

"github.com/grpc-ecosystem/go-grpc-prometheus"
"github.com/prometheus/client_golang/prometheus"
)

func init() {
// Register prometheus metrics.
Register()
}

const (
subsystemCRI = "cri"
)

var (
// GRPCMetrics create some standard server metrics.
GRPCMetrics = grpc_prometheus.NewServerMetrics()

// PodActionsCounter records the number of pod operations.
PodActionsCounter = util_metrics.NewLabelCounter(subsystemCRI, "pod_actions_counter", "The number of pod operations", "action")

// PodSuccessActionsCounter records the number of pod success operations.
PodSuccessActionsCounter = util_metrics.NewLabelCounter(subsystemCRI, "pod_success_actions_counter", "The number of pod success operations", "action")

// PodActionsTimer records the time cost of each pod action.
PodActionsTimer = util_metrics.NewLabelTimer(subsystemCRI, "pod_actions", "The number of seconds it takes to process each pod action", "action")

// ContainerActionsCounter records the number of container operations.
ContainerActionsCounter = util_metrics.NewLabelCounter(subsystemCRI, "container_actions_counter", "The number of container operations", "action")

// ContainerSuccessActionsCounter records the number of container success operations.
ContainerSuccessActionsCounter = util_metrics.NewLabelCounter(subsystemCRI, "container_success_actions_counter", "The number of container success operations", "action")

// ContainerActionsTimer records the time cost of each container action.
ContainerActionsTimer = util_metrics.NewLabelTimer(subsystemCRI, "container_actions", "The number of seconds it takes to process each container action", "action")

// ImagePullSummary records the summary of pulling image latency.
ImagePullSummary = util_metrics.NewLabelSummary(subsystemCRI, "image_pull_latency_microseconds", "Latency in microseconds to pull a image.", "image")

// ImageActionsCounter records the number of image operations.
ImageActionsCounter = util_metrics.NewLabelCounter(subsystemCRI, "image_actions_counter", "The number of image operations", "action")

// ImageSuccessActionsCounter the number of image success operations.
ImageSuccessActionsCounter = util_metrics.NewLabelCounter(subsystemCRI, "image_success_actions_counter", "The number of image success operations", "action")

// ImageActionsTimer records the time cost of each image action.
ImageActionsTimer = util_metrics.NewLabelTimer(subsystemCRI, "image_actions", "The number of seconds it takes to process each image action", "action")

// VolumeActionsCounter records the number of volume operations.
VolumeActionsCounter = util_metrics.NewLabelCounter(subsystemCRI, "volume_actions_counter", "The number of volume operations", "action")

// VolumeSuccessActionsCounter the number of volume success operations.
VolumeSuccessActionsCounter = util_metrics.NewLabelCounter(subsystemCRI, "volume_success_actions_counter", "The number of volume success operations", "action")

// VolumeActionsTimer records the time cost of each volume action.
VolumeActionsTimer = util_metrics.NewLabelTimer(subsystemCRI, "volume_actions", "The number of seconds it takes to process each volume action", "action")

// RuntimeActionsCounter records the number of runtime operations.
RuntimeActionsCounter = util_metrics.NewLabelCounter(subsystemCRI, "runtime_actions_counter", "The number of runtime operations", "action")

// RuntimeSuccessActionsCounter the number of runtime success operations.
RuntimeSuccessActionsCounter = util_metrics.NewLabelCounter(subsystemCRI, "runtime_success_actions_counter", "The number of runtime success operations", "action")

// RuntimeActionsTimer records the time cost of each runtime action.
RuntimeActionsTimer = util_metrics.NewLabelTimer(subsystemCRI, "runtime_actions", "The number of seconds it takes to process each runtime action", "action")
)

var registerMetrics sync.Once

// Register all metrics.
func Register() {
registerMetrics.Do(func() {
prometheus.MustRegister(GRPCMetrics)
prometheus.MustRegister(PodActionsCounter)
prometheus.MustRegister(PodSuccessActionsCounter)
prometheus.MustRegister(PodActionsTimer)
prometheus.MustRegister(ContainerActionsCounter)
prometheus.MustRegister(ContainerSuccessActionsCounter)
prometheus.MustRegister(ContainerActionsTimer)
prometheus.MustRegister(ImagePullSummary)
prometheus.MustRegister(ImageActionsCounter)
prometheus.MustRegister(ImageSuccessActionsCounter)
prometheus.MustRegister(ImageActionsTimer)
prometheus.MustRegister(VolumeActionsCounter)
prometheus.MustRegister(VolumeSuccessActionsCounter)
prometheus.MustRegister(VolumeActionsTimer)
prometheus.MustRegister(RuntimeActionsCounter)
prometheus.MustRegister(RuntimeSuccessActionsCounter)
prometheus.MustRegister(RuntimeActionsTimer)
})
}
Loading

0 comments on commit 4a4983c

Please sign in to comment.