outposts: add consistent name and type to metrics

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-09-16 10:14:51 +02:00
parent a6a6b3bd06
commit 471f7d9c62
6 changed files with 44 additions and 29 deletions

View File

@ -87,20 +87,20 @@ func NewAPIController(akURL url.URL, token string) *APIController {
instanceUUID: uuid.New(),
Outpost: outpost,
}
ac.logger.Debugf("HA Reload offset: %s", ac.reloadOffset)
ac.logger.WithField("offset", ac.reloadOffset).Debug("HA Reload offset")
ac.initWS(akURL, strfmt.UUID(outpost.Pk))
OutpostInfo.With(prometheus.Labels{
"uuid": ac.instanceUUID.String(),
"name": outpost.Name,
"version": constants.VERSION,
"build": constants.BUILD(),
}).Set(1)
return ac
}
// Start Starts all handlers, non-blocking
func (a *APIController) Start() error {
OutpostInfo.With(prometheus.Labels{
"outpost_name": a.Outpost.Name,
"outpost_type": a.Server.Type(),
"uuid": a.instanceUUID.String(),
"version": constants.VERSION,
"build": constants.BUILD(),
}).Set(1)
err := a.StartBackgorundTasks()
if err != nil {
return err
@ -136,10 +136,11 @@ func (a *APIController) StartBackgorundTasks() error {
return errors.Wrap(err, "failed to run initial refresh")
} else {
LastUpdate.With(prometheus.Labels{
"uuid": a.instanceUUID.String(),
"name": a.Outpost.Name,
"version": constants.VERSION,
"build": constants.BUILD(),
"uuid": a.instanceUUID.String(),
"outpost_name": a.Outpost.Name,
"outpost_type": a.Server.Type(),
"version": constants.VERSION,
"build": constants.BUILD(),
}).SetToCurrentTime()
}
go func() {

View File

@ -76,8 +76,9 @@ func (ac *APIController) startWSHandler() {
err := ac.wsConn.ReadJSON(&wsMsg)
if err != nil {
ConnectionStatus.With(prometheus.Labels{
"uuid": ac.instanceUUID.String(),
"name": ac.Outpost.Name,
"outpost_name": ac.Outpost.Name,
"outpost_type": ac.Server.Type(),
"uuid": ac.instanceUUID.String(),
}).Set(0)
logger.WithError(err).Warning("ws write error, reconnecting")
ac.wsConn.CloseAndReconnect()
@ -85,8 +86,9 @@ func (ac *APIController) startWSHandler() {
continue
}
ConnectionStatus.With(prometheus.Labels{
"uuid": ac.instanceUUID.String(),
"name": ac.Outpost.Name,
"outpost_name": ac.Outpost.Name,
"outpost_type": ac.Server.Type(),
"uuid": ac.instanceUUID.String(),
}).Set(1)
if wsMsg.Instruction == WebsocketInstructionTriggerUpdate {
time.Sleep(ac.reloadOffset)
@ -96,10 +98,11 @@ func (ac *APIController) startWSHandler() {
logger.WithError(err).Debug("Failed to update")
} else {
LastUpdate.With(prometheus.Labels{
"uuid": ac.instanceUUID.String(),
"name": ac.Outpost.Name,
"version": constants.VERSION,
"build": constants.BUILD(),
"outpost_name": ac.Outpost.Name,
"outpost_type": ac.Server.Type(),
"uuid": ac.instanceUUID.String(),
"version": constants.VERSION,
"build": constants.BUILD(),
}).SetToCurrentTime()
}
}
@ -128,8 +131,9 @@ func (ac *APIController) startWSHealth() {
continue
} else {
ConnectionStatus.With(prometheus.Labels{
"uuid": ac.instanceUUID.String(),
"name": ac.Outpost.Name,
"outpost_name": ac.Outpost.Name,
"outpost_type": ac.Server.Type(),
"uuid": ac.instanceUUID.String(),
}).Set(1)
}
}
@ -144,10 +148,11 @@ func (ac *APIController) startIntervalUpdater() {
logger.WithError(err).Debug("Failed to update")
} else {
LastUpdate.With(prometheus.Labels{
"uuid": ac.instanceUUID.String(),
"name": ac.Outpost.Name,
"version": constants.VERSION,
"build": constants.BUILD(),
"outpost_name": ac.Outpost.Name,
"outpost_type": ac.Server.Type(),
"uuid": ac.instanceUUID.String(),
"version": constants.VERSION,
"build": constants.BUILD(),
}).SetToCurrentTime()
}
}

View File

@ -9,13 +9,13 @@ var (
OutpostInfo = promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "authentik_outpost_info",
Help: "Outpost info",
}, []string{"uuid", "name", "version", "build"})
}, []string{"outpost_name", "outpost_type", "uuid", "version", "build"})
LastUpdate = promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "authentik_outpost_last_update",
Help: "Time of last update",
}, []string{"uuid", "name", "version", "build"})
}, []string{"outpost_name", "outpost_type", "uuid", "version", "build"})
ConnectionStatus = promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "authentik_outpost_connection",
Help: "Connection status",
}, []string{"uuid", "name"})
}, []string{"outpost_name", "outpost_type", "uuid"})
)

View File

@ -4,4 +4,5 @@ type Outpost interface {
Start() error
Refresh() error
TimerFlowCacheExpiry()
Type() string
}

View File

@ -86,3 +86,7 @@ func NewServer(ac *ak.APIController) *LDAPServer {
s.CloseFunc("", ls)
return ls
}
func (ls *LDAPServer) Type() string {
return "ldap"
}

View File

@ -79,6 +79,10 @@ func (ps *ProxyServer) HandleHost(host string, rw http.ResponseWriter, r *http.R
return false
}
func (ps *ProxyServer) Type() string {
return "proxy"
}
func (ps *ProxyServer) TimerFlowCacheExpiry() {}
func (ps *ProxyServer) getCertificates(info *tls.ClientHelloInfo) (*tls.Certificate, error) {