feature: Configured prometheus, improve readme (#31)

This commit is contained in:
Mario Candela
2023-03-31 20:03:42 +02:00
committed by GitHub
parent 5a70e5c900
commit f50f5185df
12 changed files with 584 additions and 37 deletions

View File

@ -2,29 +2,11 @@ package tracer
import (
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
type Strategy func(event Event)
type Tracer interface {
TraceEvent(event Event)
}
type tracer struct {
strategy Strategy
}
func Init(strategy Strategy) *tracer {
return &tracer{
strategy: strategy,
}
}
func (tracer *tracer) TraceEvent(event Event) {
event.DateTime = time.Now().UTC().Format(time.RFC3339)
tracer.strategy(event)
}
type Event struct {
DateTime string
RemoteAddr string
@ -71,3 +53,63 @@ const (
func (status Status) String() string {
return [...]string{"Start", "End", "Stateless", "Interaction"}[status]
}
type Strategy func(event Event)
type Tracer interface {
TraceEvent(event Event)
}
type tracer struct {
strategy Strategy
}
var (
eventsTotal = promauto.NewCounter(prometheus.CounterOpts{
Namespace: "beelzebub",
Name: "events_total",
Help: "The total number of events",
})
eventsSSHTotal = promauto.NewCounter(prometheus.CounterOpts{
Namespace: "beelzebub",
Name: "ssh_events_total",
Help: "The total number of SSH events",
})
eventsTCPTotal = promauto.NewCounter(prometheus.CounterOpts{
Namespace: "beelzebub",
Name: "tcp_events_total",
Help: "The total number of TCP events",
})
eventsHTTPTotal = promauto.NewCounter(prometheus.CounterOpts{
Namespace: "beelzebub",
Name: "http_events_total",
Help: "The total number of HTTP events",
})
)
func Init(strategy Strategy) *tracer {
return &tracer{
strategy: strategy,
}
}
func (tracer *tracer) TraceEvent(event Event) {
event.DateTime = time.Now().UTC().Format(time.RFC3339)
tracer.strategy(event)
//Openmetrics
eventsTotal.Inc()
switch event.Protocol {
case HTTP.String():
eventsHTTPTotal.Inc()
break
case SSH.String():
eventsSSHTotal.Inc()
break
case TCP.String():
eventsTCPTotal.Inc()
break
}
}