mirror of
https://blitiri.com.ar/repos/chasquid
synced 2026-01-25 20:25:55 +00:00
Introduce expvar counters
This patch introduces expvar counters to chasquid and the queue packages. For now there's only a handful of counters, but they will be expanded in future patches.
This commit is contained in:
@@ -2,6 +2,7 @@ package courier
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"expvar"
|
||||
"flag"
|
||||
"net"
|
||||
"os"
|
||||
@@ -29,6 +30,11 @@ var (
|
||||
fakeMX = map[string]string{}
|
||||
)
|
||||
|
||||
// Exported variables.
|
||||
var (
|
||||
tlsCount = expvar.NewMap("chasquid/smtpOut/tlsCount")
|
||||
)
|
||||
|
||||
// SMTP delivers remote mail via outgoing SMTP.
|
||||
type SMTP struct {
|
||||
}
|
||||
@@ -91,6 +97,7 @@ retry:
|
||||
// Unfortunately, many servers use self-signed certs, so if we
|
||||
// fail verification we just try again without validating.
|
||||
if insecure {
|
||||
tlsCount.Add("tls:failed", 1)
|
||||
return tr.Errorf("TLS error: %v", err), false
|
||||
}
|
||||
|
||||
@@ -101,10 +108,13 @@ retry:
|
||||
|
||||
if config.InsecureSkipVerify {
|
||||
tr.Debugf("Insecure - using TLS, but cert does not match %s", mx)
|
||||
tlsCount.Add("tls:insecure", 1)
|
||||
} else {
|
||||
tlsCount.Add("tls:secure", 1)
|
||||
tr.Debugf("Secure - using TLS")
|
||||
}
|
||||
} else {
|
||||
tlsCount.Add("plain", 1)
|
||||
tr.Debugf("Insecure - NOT using TLS")
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"encoding/base64"
|
||||
"expvar"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
@@ -51,6 +52,14 @@ var (
|
||||
errQueueFull = fmt.Errorf("Queue size too big, try again later")
|
||||
)
|
||||
|
||||
// Exported variables.
|
||||
var (
|
||||
putCount = expvar.NewInt("chasquid/queue/putCount")
|
||||
itemsWritten = expvar.NewInt("chasquid/queue/itemsWritten")
|
||||
dsnQueued = expvar.NewInt("chasquid/queue/dsnQueued")
|
||||
deliverAttempts = expvar.NewMap("chasquid/queue/deliverAttempts")
|
||||
)
|
||||
|
||||
// Channel used to get random IDs for items in the queue.
|
||||
var newID chan string
|
||||
|
||||
@@ -148,6 +157,7 @@ func (q *Queue) Put(hostname, from string, to []string, data []byte) (string, er
|
||||
if q.Len() >= maxQueueSize {
|
||||
return "", errQueueFull
|
||||
}
|
||||
putCount.Add(1)
|
||||
|
||||
item := &Item{
|
||||
Message: Message{
|
||||
@@ -272,6 +282,7 @@ func ItemFromFile(fname string) (*Item, error) {
|
||||
func (item *Item) WriteTo(dir string) error {
|
||||
item.Lock()
|
||||
defer item.Unlock()
|
||||
itemsWritten.Add(1)
|
||||
|
||||
var err error
|
||||
item.CreatedAtTs, err = ptypes.TimestampProto(item.CreatedAt)
|
||||
@@ -394,12 +405,14 @@ func sendDSN(tr *trace.Trace, q *Queue, item *Item) {
|
||||
}
|
||||
|
||||
tr.Printf("queued DSN: %s", id)
|
||||
dsnQueued.Add(1)
|
||||
}
|
||||
|
||||
// deliver the item to the given recipient, using the couriers from the queue.
|
||||
// Return an error (if any), and whether it is permanent or not.
|
||||
func (item *Item) deliver(q *Queue, rcpt *Recipient) (err error, permanent bool) {
|
||||
if rcpt.Type == Recipient_PIPE {
|
||||
deliverAttempts.Add("pipe", 1)
|
||||
c := strings.Fields(rcpt.Address)
|
||||
if len(c) == 0 {
|
||||
return fmt.Errorf("empty pipe"), true
|
||||
@@ -413,8 +426,10 @@ func (item *Item) deliver(q *Queue, rcpt *Recipient) (err error, permanent bool)
|
||||
|
||||
} else {
|
||||
if envelope.DomainIn(rcpt.Address, q.localDomains) {
|
||||
deliverAttempts.Add("email:local", 1)
|
||||
return q.localC.Deliver(item.From, rcpt.Address, item.Data)
|
||||
} else {
|
||||
deliverAttempts.Add("email:remote", 1)
|
||||
from := item.From
|
||||
if !envelope.DomainIn(item.From, q.localDomains) {
|
||||
// We're sending from a non-local to a non-local. This should
|
||||
|
||||
Reference in New Issue
Block a user