Skip to content

Commit

Permalink
Add metric to indicate anycastd is running and its version (#77)
Browse files Browse the repository at this point in the history
Signed-off-by: Igor Shishkin <me@teran.dev>
  • Loading branch information
teran authored Oct 26, 2024
1 parent 587b149 commit b335a30
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ systems to notify operators about any changes in their service.

For now anycastd provides the following metrics:

| Metric name | Labels | Description |
|-------------|---------|------------------------------------------------|
| anycastd_up | version | Application liveness status (must always be 1) |

### Service

Service could provide their metrics in order to aggregate current statuses.
Expand Down
2 changes: 1 addition & 1 deletion cmd/anycastd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func main() {
LocalASN: cfg.Announcer.LocalASN,
})

metrics, err := service.NewMetrics()
metrics, err := service.NewMetrics(appVersion)
if err != nil {
panic(err)
}
Expand Down
23 changes: 17 additions & 6 deletions service/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,21 @@ type Metrics interface {
}

type metrics struct {
appUpGauge *prometheus.GaugeVec
upGauge *prometheus.GaugeVec
checkDurationSeconds *prometheus.GaugeVec
}

func NewMetrics() (Metrics, error) {
func NewMetrics(appVersion string) (Metrics, error) {
appUpGauge := prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: "anycastd",
Name: "up",
Help: "Application liveness status (must always be 1)",
},
[]string{"version"},
)

upGauge := prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: "anycastd",
Expand All @@ -38,15 +48,16 @@ func NewMetrics() (Metrics, error) {
[]string{"service", "check"},
)

if err := prometheus.Register(upGauge); err != nil {
return nil, err
for _, m := range []prometheus.Collector{appUpGauge, upGauge, checkDurationSeconds} {
if err := prometheus.Register(m); err != nil {
return nil, err
}
}

if err := prometheus.Register(checkDurationSeconds); err != nil {
return nil, err
}
appUpGauge.WithLabelValues(appVersion).Set(1)

return &metrics{
appUpGauge: appUpGauge,
upGauge: upGauge,
checkDurationSeconds: checkDurationSeconds,
}, nil
Expand Down

0 comments on commit b335a30

Please sign in to comment.