apiary/honeypot/ssh/store/metrics.go

46 lines
1.2 KiB
Go
Raw Normal View History

2021-10-28 14:35:57 +00:00
package store
import (
"github.com/prometheus/client_golang/prometheus"
"github.uio.no/torjus/apiary/models"
)
type MetricsCollectingStore struct {
store LoginAttemptStore
attemptsCounter *prometheus.CounterVec
}
func NewMetricsCollectingStore(store LoginAttemptStore) *MetricsCollectingStore {
mcs := &MetricsCollectingStore{store: store}
mcs.attemptsCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "apiary_ssh_attempt_counter",
Help: "Total count of login attempts toward SSH",
ConstLabels: prometheus.Labels{"service": "honeypot_ssh"},
},
[]string{"CountryCode"},
)
prometheus.MustRegister(mcs.attemptsCounter)
return mcs
}
func (s *MetricsCollectingStore) AddAttempt(l *models.LoginAttempt) error {
err := s.store.AddAttempt(l)
s.attemptsCounter.WithLabelValues(l.Country).Inc()
return err
}
func (s *MetricsCollectingStore) All() ([]models.LoginAttempt, error) {
return s.store.All()
}
func (s *MetricsCollectingStore) Stats(statType LoginStats, limit int) ([]StatsResult, error) {
return s.store.Stats(statType, limit)
}
func (s *MetricsCollectingStore) Query(query AttemptQuery) ([]models.LoginAttempt, error) {
return s.store.Query(query)
}