Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remake Prometheus endpoint into a proper endpoint module
- Loading branch information
Showing
6 changed files
with
160 additions
and
32 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
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,40 @@ | ||
# OpenMetrics/Promethus telemetry | ||
|
||
Various server statistics is provided in OpenMetrics format by "openmetrics" | ||
module. | ||
|
||
To enable it, add following line to the server config: | ||
``` | ||
openmetrics tcp://127.0.0.1:9749 { } | ||
``` | ||
|
||
Scrape endpoint would be `http://127.0.0.1:9749/metrics`. | ||
|
||
## Metrics | ||
|
||
``` | ||
# AUTH command failures due to invalid credentials. | ||
maddy_smtp_failed_logins{module} | ||
# Failed SMTP transaction commands (MAIL, RCPT, DATA). | ||
maddy_smtp_failed_commands{module, command, smtp_code, smtp_enchcode} | ||
# Messages rejected with 4xx code due to ratelimiting. | ||
maddy_smtp_ratelimit_deferred{module} | ||
# Amount of started SMTP trasanactions started. | ||
maddy_smtp_started_transactions{module} | ||
# Amount of aborted SMTP trasanactions started. | ||
maddy_smtp_aborted_transactions{module} | ||
# Amount of completed SMTP trasanactions. | ||
maddy_smtp_completed_transactions{module} | ||
# Number of times a check returned 'reject' result (may be more than processed | ||
# messages if check does so on per-recipient basis) | ||
maddy_check_reject{check} | ||
# Number of times a check returned 'quarantine' result (may be more than | ||
# processed messages if check does so on per-recipient basis). | ||
maddy_check_quarantined{check} | ||
# Amount of queued messages | ||
maddy_queue_length{module, location} | ||
# Outbound connections established with specific TLS security level | ||
maddy_remote_conns_tls_level{module, level} | ||
# Outbound connections established with specific MX security level | ||
maddy_remote_conns_mx_level{module, level} | ||
``` |
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,106 @@ | ||
/* | ||
Maddy Mail Server - Composable all-in-one email server. | ||
Copyright © 2019-2020 Max Mazurov <fox.cpp@disroot.org>, Maddy Mail Server contributors | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package openmetrics | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
"net/http" | ||
"sync" | ||
|
||
"github.com/foxcpp/maddy/framework/config" | ||
"github.com/foxcpp/maddy/framework/log" | ||
"github.com/foxcpp/maddy/framework/module" | ||
"github.com/prometheus/client_golang/prometheus/promhttp" | ||
) | ||
|
||
const modName = "openmetrics" | ||
|
||
type Endpoint struct { | ||
addrs []string | ||
logger log.Logger | ||
|
||
listenersWg sync.WaitGroup | ||
serv http.Server | ||
mux *http.ServeMux | ||
} | ||
|
||
func New(_ string, args []string) (module.Module, error) { | ||
return &Endpoint{ | ||
addrs: args, | ||
logger: log.Logger{Name: modName, Debug: log.DefaultLogger.Debug}, | ||
}, nil | ||
} | ||
|
||
func (e *Endpoint) Init(cfg *config.Map) error { | ||
cfg.Bool("debug", false, false, &e.logger.Debug) | ||
if _, err := cfg.Process(); err != nil { | ||
return err | ||
} | ||
|
||
e.mux = http.NewServeMux() | ||
e.mux.Handle("/metrics", promhttp.Handler()) | ||
e.serv.Handler = e.mux | ||
|
||
for _, a := range e.addrs { | ||
a := a | ||
endp, err := config.ParseEndpoint(a) | ||
if err != nil { | ||
return fmt.Errorf("%s: malformed endpoint: %v", modName, err) | ||
} | ||
if endp.IsTLS() { | ||
return fmt.Errorf("%s: TLS is not supported yet", modName) | ||
} | ||
l, err := net.Listen(endp.Network(), endp.Address()) | ||
if err != nil { | ||
return fmt.Errorf("%s: %v", modName, err) | ||
} | ||
|
||
e.listenersWg.Add(1) | ||
go func() { | ||
e.logger.Println("listening on", endp.String()) | ||
err := e.serv.Serve(l) | ||
if err != nil && err != http.ErrServerClosed { | ||
e.logger.Error("serve failed", err, "endpoint", a) | ||
} | ||
}() | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (e *Endpoint) Name() string { | ||
return modName | ||
} | ||
|
||
func (e *Endpoint) InstanceName() string { | ||
return "" | ||
} | ||
|
||
func (e *Endpoint) Close() error { | ||
if err := e.serv.Close(); err != nil { | ||
return err | ||
} | ||
e.listenersWg.Wait() | ||
return nil | ||
} | ||
|
||
func init() { | ||
module.RegisterEndpoint(modName, New) | ||
} |
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