mirror of
https://github.com/mariocandela/beelzebub.git
synced 2025-07-01 18:47:26 -04:00
feature: Configured prometheus, improve readme (#31)
This commit is contained in:
@ -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
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user