Skip to content

Commit

Permalink
metrics: define metrics to be collected
Browse files Browse the repository at this point in the history
  • Loading branch information
joelrebel committed Jun 28, 2023
1 parent acf1a49 commit 348500d
Showing 1 changed file with 104 additions and 0 deletions.
104 changes: 104 additions & 0 deletions internal/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,117 @@ import (
"net/http"
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
)

const (
MetricsEndpoint = "0.0.0.0:9090"
)

var (
EventsCounter *prometheus.CounterVec

ConditionCounter *prometheus.CounterVec
ConditionRunTimeSummary *prometheus.SummaryVec

ActionCounter *prometheus.CounterVec
ActionRuntimeSummary *prometheus.SummaryVec

ActionHandlerCounter *prometheus.CounterVec
ActionHandlerRunTimeSummary *prometheus.SummaryVec

DownloadBytes *prometheus.CounterVec
DownloadRunTimeSummary *prometheus.SummaryVec
UploadBytes *prometheus.CounterVec
UploadRunTimeSummary *prometheus.SummaryVec

StoreQueryErrorCount *prometheus.CounterVec
)

func init() {
EventsCounter = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "flasher_events_received",
Help: "A counter metric to measure the total count of events received",
},
[]string{"valid", "response"}, // valid is true/false, response is ack/nack
)

ConditionCounter = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "flasher_conditions_received",
Help: "A counter metric to measure the total count of condition requests received, successful and failed",
},
[]string{"condition", "state"},
)

ConditionRunTimeSummary = promauto.NewSummaryVec(
prometheus.SummaryOpts{
Name: "flasher_condition_duration_seconds",
Help: "A summary metric to measure the total time spent in completing each condition",
},
[]string{"condition", "state"},
)

ActionCounter = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "flasher_actions_counter",
Help: "A counter metric to measure the sum of firmware install actions executed",
},
[]string{"vendor", "component", "state"},
)

ActionRuntimeSummary = promauto.NewSummaryVec(
prometheus.SummaryOpts{
Name: "flasher_install_action_runtime_seconds",
Help: "A summary metric to measure the total time spent in each install action",
},
[]string{"vendor", "component", "state"},
)

ActionHandlerCounter = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "flasher_install_action_handler_counter",
Help: "A counter metric to measure the total count of install action handlers executed",
},
[]string{"transition", "vendor", "component", "state"},
)

ActionHandlerRunTimeSummary = promauto.NewSummaryVec(
prometheus.SummaryOpts{
Name: "flasher_install_action_handler_seconds",
Help: "A summary metric to measure the total time spent in each install action handler being executed",
},
[]string{"transition", "vendor", "component", "state"},
)

DownloadBytes = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "flasher_download_bytes",
Help: "A counter metric to measure firmware downloaded in bytes",
},
[]string{"component", "vendor"},
)

UploadBytes = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "flasher_upload_bytes",
Help: "A counter metric to measure firmware uploaded in bytes",
},
[]string{"component", "vendor"},
)

StoreQueryErrorCount = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "store_query_error_count",
Help: "A counter metric to measure the total count of errors querying the asset store.",
},
[]string{"storeKind"},
)
}

// ListenAndServeMetrics exposes prometheus metrics as /metrics
func ListenAndServe() {
go func() {
Expand Down

0 comments on commit 348500d

Please sign in to comment.