Add `active_users` metric This change exposes a new metric called `active_users`. This metric indicates the number of active users; a user is considered active when its inactivity period is not greater than the value defined in the `cache."@PLUGIN@.users_cache".maxAge`. The metric uses the `users_cache` of the track-and-disable-inactive-users-1.3.groovy plugin to allow exposure of this value to the various monitoring and observability stacks. Bug: Issue 370937461 Change-Id: Iaa1a78a7435f80508eeeceb6df762f6c789a0bdc
diff --git a/admin/track-and-disable-inactive-users-1.3.groovy b/admin/track-and-disable-inactive-users-1.3.groovy index f1d9b49..a591aef 100644 --- a/admin/track-and-disable-inactive-users-1.3.groovy +++ b/admin/track-and-disable-inactive-users-1.3.groovy
@@ -19,6 +19,7 @@ import com.google.gerrit.extensions.annotations.* import com.google.gerrit.extensions.events.* import com.google.gerrit.extensions.registration.* +import com.google.gerrit.metrics.* import com.google.gerrit.lifecycle.* import com.google.gerrit.server.* import com.google.gerrit.server.account.* @@ -34,6 +35,23 @@ import static java.util.concurrent.TimeUnit.* +@Singleton +class ActiveUsersMetric { + + static final NAME = "active_users" + static final DESCRIPTION = "Number of active users" + + @Inject + public ActiveUsersMetric(MetricMaker metrics, @Named(TrackActiveUsersCache.NAME) Cache<Integer, Long> trackActiveUsersCache){ + metrics.newCallbackMetric( + NAME, + Long.class, + new Description(DESCRIPTION).setGauge().setUnit("users"), + { -> trackActiveUsersCache.size() } + ); + } +} + class TrackActiveUsersCache extends CacheModule { static final NAME = "users_cache" static final DEFAULT_CACHE_TTL = Duration.ofDays(90) @@ -203,6 +221,7 @@ @Override void configure() { install(new TrackActiveUsersCache()) + bind(ActiveUsersMetric.class).asEagerSingleton() listener().to(AutoDisableInactiveUsersListener) DynamicSet.bind(binder(), CacheRemovalListener).to(AutoDisableInactiveUsersEvictionListener)
diff --git a/admin/track-and-disable-inactive-users.md b/admin/track-and-disable-inactive-users.md index c569d0b..e622c41 100644 --- a/admin/track-and-disable-inactive-users.md +++ b/admin/track-and-disable-inactive-users.md
@@ -42,3 +42,11 @@ If a time unit suffix is not specified, `hours` is assumed. Default: 90 days + +Metrics +--------------------- +Currently, the metrics exposed are the following: + +```groovy_track_and_disable_inactive_users_active_users``` +: Indicates the number of active users. + A user is considered active when its inactivity period is not greater than `cache."@PLUGIN@.users_cache".maxAge` . \ No newline at end of file