Skip to content

Commit

Permalink
Add identity num_entities gauge metric (#8816)
Browse files Browse the repository at this point in the history
Signed-off-by: Dustin Decker <dustindecker@protonmail.com>
  • Loading branch information
dustin-decker committed Apr 24, 2020
1 parent bb7e661 commit 3e6df9b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions vault/core.go
Expand Up @@ -2069,6 +2069,7 @@ func stopReplicationImpl(c *Core) error {
func (c *Core) emitMetrics(stopCh chan struct{}) {
emitTimer := time.Tick(time.Second)
writeTimer := time.Tick(c.counters.syncInterval)
identityCountTimer := time.Tick(time.Minute * 10)

for {
select {
Expand All @@ -2094,6 +2095,17 @@ func (c *Core) emitMetrics(stopCh chan struct{}) {
}
}
c.stateLock.RUnlock()
case <-identityCountTimer:
go func() {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
entities, err := c.countActiveEntities(ctx)
if err != nil {
c.logger.Error("error counting identity entities", "err", err)
} else {
metrics.SetGauge([]string{"identity", "num_entities"}, float32(entities.Entities.Total))
}
}()

case <-stopCh:
return
Expand Down

0 comments on commit 3e6df9b

Please sign in to comment.