-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
190 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
const ( | ||
defaultMetricsPort = 2112 | ||
defaultMetricsHost = "127.0.0.1" | ||
) | ||
|
||
// MetricsConfig defines the server's basic configuration | ||
type MetricsConfig struct { | ||
Enabled bool `long:"enabled" description:"Enable reporting metrics"` | ||
Host string `long:"host" description:"host of the Prometheus server"` | ||
Port int `long:"port" description:"Port of the Prometheus server"` | ||
} | ||
|
||
func (cfg *MetricsConfig) Validate() error { | ||
if cfg.Port < 0 || cfg.Port > 65535 { | ||
return fmt.Errorf("invalid port: %d", cfg.Port) | ||
} | ||
|
||
if cfg.Host == "" { | ||
return fmt.Errorf("host cannot be empty") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (cfg *MetricsConfig) Address() (string, error) { | ||
if err := cfg.Validate(); err != nil { | ||
return "", err | ||
} | ||
return fmt.Sprintf("%s:%d", cfg.Host, cfg.Port), nil | ||
} | ||
|
||
func DefaultMetricsConfig() *MetricsConfig { | ||
return &MetricsConfig{ | ||
Enabled: false, | ||
Port: defaultMetricsPort, | ||
Host: defaultMetricsHost, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package services | ||
|
||
import ( | ||
"github.com/babylonchain/cli-tools/internal/config" | ||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
type PipelineMetrics struct { | ||
SuccessSigningReqs *prometheus.CounterVec | ||
FailedSigningReqs *prometheus.CounterVec | ||
SuccessfulSentTransactions prometheus.Counter | ||
FailureSentTransactions prometheus.Counter | ||
Config *config.MetricsConfig | ||
} | ||
|
||
func NewPipelineMetrics(cfg *config.MetricsConfig) *PipelineMetrics { | ||
return &PipelineMetrics{ | ||
SuccessSigningReqs: prometheus.NewCounterVec( | ||
prometheus.CounterOpts{ | ||
Name: "number_of_successful_signing_requests", | ||
Help: "How many signing requests to given covenant were successful", | ||
}, | ||
[]string{"covenant_pk"}, | ||
), | ||
FailedSigningReqs: prometheus.NewCounterVec( | ||
prometheus.CounterOpts{ | ||
Name: "number_of_failed_signing_requests", | ||
Help: "How many signing requests to given covenant failed", | ||
}, | ||
[]string{"covenant_pk"}, | ||
), | ||
SuccessfulSentTransactions: prometheus.NewCounter( | ||
prometheus.CounterOpts{ | ||
Name: "number_of_successful_unbonding_transactions", | ||
Help: "How many transactions were successfully sent to the network", | ||
}, | ||
), | ||
FailureSentTransactions: prometheus.NewCounter( | ||
prometheus.CounterOpts{ | ||
Name: "number_of_failed_unbonding_transactions", | ||
Help: "How many transactions failed to be sent to the network", | ||
}, | ||
), | ||
Config: cfg, | ||
} | ||
} | ||
|
||
func (pm *PipelineMetrics) RecordSuccessSigningRequest(covenantPk string) { | ||
pm.SuccessSigningReqs.WithLabelValues(covenantPk).Inc() | ||
} | ||
|
||
func (pm *PipelineMetrics) RecordFailedSigningRequest(covenantPk string) { | ||
pm.FailedSigningReqs.WithLabelValues(covenantPk).Inc() | ||
} | ||
|
||
func (pm *PipelineMetrics) RecordSentUnbondingTransaction() { | ||
pm.SuccessfulSentTransactions.Inc() | ||
} | ||
|
||
func (pm *PipelineMetrics) RecordFailedUnbodingTransaction() { | ||
pm.FailureSentTransactions.Inc() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters