-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(log,metrics): add log and metrics modules. (#63)
- Loading branch information
Showing
10 changed files
with
209 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
package commands | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
) | ||
|
||
func ExitOnError(err error) { | ||
fmt.Printf("immortal error: %s\n", err.Error()) //nolint | ||
log.Printf("immortal error: %s\n", err.Error()) //nolint | ||
os.Exit(1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package metrics | ||
|
||
import ( | ||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/promauto" | ||
) | ||
|
||
type Metrics struct { | ||
EventsTotal *prometheus.CounterVec | ||
RequestsTotal *prometheus.CounterVec | ||
MessagesTotal prometheus.Counter | ||
Subscriptions prometheus.Gauge | ||
Connections prometheus.Gauge | ||
EventLaency prometheus.Histogram | ||
RequestLatency prometheus.Histogram | ||
} | ||
|
||
func New() *Metrics { | ||
eventsT := promauto.NewCounterVec(prometheus.CounterOpts{ | ||
Name: "events_total", | ||
Help: "number of events sent to the relay.", | ||
}, []string{"status"}) | ||
|
||
reqsT := promauto.NewCounterVec(prometheus.CounterOpts{ | ||
Name: "requests_total", | ||
Help: "number of REQ messages sent to relay.", | ||
}, []string{"status"}) | ||
|
||
msgT := promauto.NewCounter(prometheus.CounterOpts{ | ||
Name: "messages_total", | ||
Help: "number of messages received.", | ||
}) | ||
|
||
subs := promauto.NewGauge(prometheus.GaugeOpts{ | ||
Name: "subscriptions", | ||
Help: "number of open subscription.", | ||
}) | ||
|
||
conns := promauto.NewGauge(prometheus.GaugeOpts{ | ||
Name: "connections", | ||
Help: "number of open websocket connections.", | ||
}) | ||
|
||
eventL := promauto.NewHistogram(prometheus.HistogramOpts{ | ||
Name: "event_latency", | ||
Help: "time needed to request to an EVENT message.", | ||
}) | ||
|
||
reqL := promauto.NewHistogram(prometheus.HistogramOpts{ | ||
Name: "requset_latency", | ||
Help: "time needed to request to a REQ message.", | ||
}) | ||
|
||
return &Metrics{ | ||
EventsTotal: eventsT, | ||
Connections: conns, | ||
MessagesTotal: msgT, | ||
Subscriptions: subs, | ||
RequestsTotal: reqsT, | ||
EventLaency: eventL, | ||
RequestLatency: reqL, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.