GitLab is used only for code review, issue tracking and project management. Canonical locations for source code are still https://gitweb.torproject.org/ https://git.torproject.org/ and git-rw.torproject.org.

Collect Tor's event types.

This patch is a follow-up commit to #10.
parent 0db35d80
......@@ -8,6 +8,8 @@ import (
"math/rand"
"regexp"
"strconv"
"github.com/prometheus/client_golang/prometheus"
)
const (
......@@ -124,6 +126,7 @@ func (t *TorEventState) Feed(line string) {
if OrConnEvent.MatchString(line) {
t.processOrConnLine(line)
} else if NewDescEvent.MatchString(line) {
metrics.Events.With(prometheus.Labels{"type": "newdesc", "status": ""}).Inc()
t.processNewDescLine(line)
} else {
log.Printf("%x: Bug: Received an unexpected event %q.", t.TestId, line)
......@@ -150,6 +153,7 @@ func (t *TorEventState) processOrConnLine(line string) {
// Are we dealing with a new ORCONN for our bridge line? If so, add its ID
// to our map, so we can keep track of it.
if eventType == "LAUNCHED" {
metrics.Events.With(prometheus.Labels{"type": "orconn", "status": "launched"}).Inc()
matchLen := calcMatchLength(target, t.Target)
if target == t.Target[:matchLen] {
log.Printf("%x: Adding ID %d to map.", t.TestId, i)
......@@ -167,6 +171,7 @@ func (t *TorEventState) processOrConnLine(line string) {
// https://gitweb.torproject.org/torspec.git/tree/control-spec.txt#n2448
switch eventType {
case "FAILED":
metrics.Events.With(prometheus.Labels{"type": "orconn", "status": "failed"}).Inc()
// An ORCONN failed. Was it ours?
if _, exists := t.ConnIds[i]; exists {
log.Printf("%x: Setting ORCONN failure.", t.TestId)
......@@ -182,6 +187,7 @@ func (t *TorEventState) processOrConnLine(line string) {
}
t.Reason = desc
case "CONNECTED":
metrics.Events.With(prometheus.Labels{"type": "orconn", "status": "connected"}).Inc()
fingerprint, err := extractFingerprint(line)
if err == nil {
log.Printf("%x: Setting fingerprint to %s.", t.TestId, fingerprint)
......
......@@ -10,11 +10,11 @@ const (
)
type Metrics struct {
OrconnLaunched prometheus.Counter
CacheSize prometheus.Gauge
PendingReqs prometheus.Gauge
FracFunctional prometheus.Gauge
TorTestTime prometheus.Histogram
Events *prometheus.CounterVec
Cache *prometheus.CounterVec
Requests *prometheus.CounterVec
BridgeStatus *prometheus.CounterVec
......@@ -27,12 +27,6 @@ func InitMetrics() {
metrics = &Metrics{}
metrics.OrconnLaunched = promauto.NewCounter(prometheus.CounterOpts{
Namespace: PrometheusNamespace,
Name: "tor_events_orconn_launched",
Help: "The number of ORCONN launch events",
})
metrics.PendingReqs = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: PrometheusNamespace,
Name: "pending_requests",
......@@ -51,6 +45,15 @@ func InitMetrics() {
Help: "The number of cached elements",
})
metrics.Events = promauto.NewCounterVec(
prometheus.CounterOpts{
Namespace: PrometheusNamespace,
Name: "tor_events_total",
Help: "The number of Tor events",
},
[]string{"type", "status"},
)
metrics.Cache = promauto.NewCounterVec(
prometheus.CounterOpts{
Namespace: PrometheusNamespace,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment