This repository has been archived by the owner on Feb 17, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add metrics for piping messages
- Loading branch information
1 parent
550cf91
commit b0559d4
Showing
2 changed files
with
69 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package pipe | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
// Piped contains metrics to meter the number of piped messages. | ||
type Piped struct { | ||
PipedMessages prometheus.Counter | ||
FailedMessages prometheus.Counter | ||
} | ||
|
||
func NewPiped(name string) Piped { | ||
piped := prometheus.NewCounter(prometheus.CounterOpts{ | ||
Namespace: "sjr", | ||
Name: "piped_total", | ||
Help: "total number of piped messages", | ||
Subsystem: "pipe", | ||
ConstLabels: prometheus.Labels{ | ||
"topic": name, | ||
}, | ||
}) | ||
|
||
if err := prometheus.Register(piped); err != nil { | ||
var are prometheus.AlreadyRegisteredError | ||
if ok := errors.As(err, &are); ok { | ||
piped, ok = are.ExistingCollector.(prometheus.Counter) | ||
if !ok { | ||
panic("piped must be a counter") | ||
} | ||
} else { | ||
panic(err) | ||
} | ||
} | ||
|
||
failed := prometheus.NewCounter(prometheus.CounterOpts{ | ||
Namespace: "sjr", | ||
Name: "piped_total", | ||
Help: "total number of failed messages", | ||
Subsystem: "pipe", | ||
ConstLabels: prometheus.Labels{ | ||
"topic": name, | ||
}, | ||
}) | ||
|
||
if err := prometheus.Register(failed); err != nil { | ||
var are prometheus.AlreadyRegisteredError | ||
if ok := errors.As(err, &are); ok { | ||
piped, ok = are.ExistingCollector.(prometheus.Counter) | ||
if !ok { | ||
panic("failed must be a counter") | ||
} | ||
} else { | ||
panic(err) | ||
} | ||
} | ||
|
||
return Piped{ | ||
PipedMessages: piped, | ||
FailedMessages: failed, | ||
} | ||
} |
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