Search in sources :

Example 1 with RegistryStatusValueDto

use of org.bf2.srs.fleetmanager.rest.service.model.RegistryStatusValueDto in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.

the class UsageMetrics method init.

public synchronized void init() {
    expirationPeriod = Duration.ofSeconds(expirationPeriodSeconds);
    int stagger = 0;
    // Only stagger if the expiration period is at least 1 minute (testing support).
    if (expirationPeriod.compareTo(Duration.ofMinutes(1)) >= 0) {
        stagger = new Random().nextInt(expirationPeriodSeconds) + 1;
        log.debug("Staggering usage metrics cache expiration by {} seconds", stagger);
    }
    nextExpiration = Instant.now().plus(Duration.ofSeconds(stagger));
    for (RegistryStatusValueDto status : RegistryStatusValueDto.values()) {
        Gauge.builder(USAGE_STATISTICS_REGISTRIES_STATUS, () -> {
            Arc.initialize();
            var ctx = Arc.container().requestContext();
            ctx.activate();
            try {
                return getUsageStatisticsCached().getRegistryCountPerStatus().get(status);
            } finally {
                ctx.deactivate();
            }
        }).tags(Tags.of(TAG_USAGE_STATISTICS_STATUS, status.value())).register(metrics);
    }
    for (RegistryInstanceTypeValueDto type : RegistryInstanceTypeValueDto.values()) {
        Gauge.builder(USAGE_STATISTICS_REGISTRIES_TYPE, () -> {
            Arc.initialize();
            var ctx = Arc.container().requestContext();
            ctx.activate();
            try {
                return getUsageStatisticsCached().getRegistryCountPerType().get(type);
            } finally {
                ctx.deactivate();
            }
        }).tags(Tags.of(TAG_USAGE_STATISTICS_TYPE, type.value())).register(metrics);
    }
    Gauge.builder(USAGE_STATISTICS_ACTIVE_USERS, () -> {
        Arc.initialize();
        var ctx = Arc.container().requestContext();
        ctx.activate();
        try {
            return getUsageStatisticsCached().getActiveUserCount();
        } finally {
            ctx.deactivate();
        }
    }).register(metrics);
    Gauge.builder(USAGE_STATISTICS_ACTIVE_ORGANISATIONS, () -> {
        Arc.initialize();
        var ctx = Arc.container().requestContext();
        ctx.activate();
        try {
            return getUsageStatisticsCached().getActiveOrganisationCount();
        } finally {
            ctx.deactivate();
        }
    }).register(metrics);
}
Also used : RegistryStatusValueDto(org.bf2.srs.fleetmanager.rest.service.model.RegistryStatusValueDto) Random(java.util.Random) RegistryInstanceTypeValueDto(org.bf2.srs.fleetmanager.rest.service.model.RegistryInstanceTypeValueDto)

Aggregations

Random (java.util.Random)1 RegistryInstanceTypeValueDto (org.bf2.srs.fleetmanager.rest.service.model.RegistryInstanceTypeValueDto)1 RegistryStatusValueDto (org.bf2.srs.fleetmanager.rest.service.model.RegistryStatusValueDto)1