Skip to content

Commit

Permalink
Move metrics to metrics package
Browse files Browse the repository at this point in the history
  • Loading branch information
gagliardetto committed Jul 11, 2024
1 parent a67493c commit 20e5219
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 160 deletions.
11 changes: 6 additions & 5 deletions cmd-rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/allegro/bigcache/v3"
"github.com/fsnotify/fsnotify"
hugecache "github.com/rpcpool/yellowstone-faithful/huge-cache"
"github.com/rpcpool/yellowstone-faithful/metrics"
splitcarfetcher "github.com/rpcpool/yellowstone-faithful/split-car-fetcher"
"github.com/ryanuber/go-glob"
"github.com/urfave/cli/v2"
Expand Down Expand Up @@ -202,13 +203,13 @@ func newCmd_rpc() *cli.Command {
return nil
}()
if err != nil {
metrics_epochsAvailable.WithLabelValues(fmt.Sprintf("%d", epochNum)).Set(0)
metrics.EpochsAvailable.WithLabelValues(fmt.Sprintf("%d", epochNum)).Set(0)
klog.Error(err)
numFailed.Add(1)
// NOTE: DO NOT return the error here, as we want to continue loading other epochs
return nil
}
metrics_epochsAvailable.WithLabelValues(fmt.Sprintf("%d", epochNum)).Set(1)
metrics.EpochsAvailable.WithLabelValues(fmt.Sprintf("%d", epochNum)).Set(1)
numSucceeded.Add(1)
return nil
})
Expand Down Expand Up @@ -275,7 +276,7 @@ func newCmd_rpc() *cli.Command {
return
}
klog.V(2).Infof("Epoch %d added/replaced in %s", epoch.Epoch(), time.Since(startedAt))
metrics_epochsAvailable.WithLabelValues(fmt.Sprintf("%d", epoch.Epoch())).Set(1)
metrics.EpochsAvailable.WithLabelValues(fmt.Sprintf("%d", epoch.Epoch())).Set(1)
}
case fsnotify.Create:
{
Expand All @@ -298,7 +299,7 @@ func newCmd_rpc() *cli.Command {
return
}
klog.V(2).Infof("Epoch %d added in %s", epoch.Epoch(), time.Since(startedAt))
metrics_epochsAvailable.WithLabelValues(fmt.Sprintf("%d", epoch.Epoch())).Set(1)
metrics.EpochsAvailable.WithLabelValues(fmt.Sprintf("%d", epoch.Epoch())).Set(1)
}
case fsnotify.Remove:
{
Expand All @@ -310,7 +311,7 @@ func newCmd_rpc() *cli.Command {
klog.Errorf("error removing epoch for config file %q: %s", event.Name, err.Error())
}
klog.V(2).Infof("Epoch %d removed in %s", epNumber, time.Since(startedAt))
metrics_epochsAvailable.WithLabelValues(fmt.Sprintf("%d", epNumber)).Set(0)
metrics.EpochsAvailable.WithLabelValues(fmt.Sprintf("%d", epNumber)).Set(0)
}
case fsnotify.Rename:
klog.V(3).Infof("File %q was renamed; do nothing", event.Name)
Expand Down
147 changes: 0 additions & 147 deletions metrics.go

This file was deleted.

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

import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)

var RpcRequestByMethod = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "rpc_requests_by_method",
Help: "RPC requests by method",
},
[]string{"method"},
)

var EpochsAvailable = promauto.NewGaugeVec(
prometheus.GaugeOpts{
Name: "epoch_available",
Help: "Epochs available",
},
[]string{"epoch"},
)

var StatusCode = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "status_code",
Help: "Status code",
},
[]string{"code"},
)

var MethodToCode = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "method_to_code",
Help: "Method to code",
},
[]string{"method", "code"},
)

var MethodToSuccessOrFailure = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "method_to_success_or_failure",
Help: "Method to success or failure",
},
[]string{"method", "status"},
)

var MethodToNumProxied = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "method_to_num_proxied",
Help: "Method to num proxied",
},
[]string{"method"},
)

var ResponseTimeHistogram = promauto.NewHistogramVec(
prometheus.HistogramOpts{
Name: "response_time_histogram",
Help: "Response time histogram",
},
[]string{"method"},
)

// - Version information of this binary
var Version = promauto.NewGaugeVec(
prometheus.GaugeOpts{
Name: "version",
Help: "Version information of this binary",
},
[]string{"started_at", "tag", "commit", "compiler", "goarch", "goos", "goamd64", "vcs", "vcs_revision", "vcs_time", "vcs_modified"},
)
Loading

0 comments on commit 20e5219

Please sign in to comment.