-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(UserActivityManager) : DAU, MAU계산 및 export
- 로그인시 계정 없음에 대한 에러코드를 정의하였습니다. - 로그인시 하루 기준으로 중복되지 않는 사용자에 대해 카운트하고, metricRegistry를 통해 export 합니다.
- Loading branch information
Showing
5 changed files
with
67 additions
and
2 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
42 changes: 42 additions & 0 deletions
42
wabi/src/main/kotlin/com/wap/wabi/auth/admin/util/UserActivityManager.kt
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,42 @@ | ||
package com.wap.wabi.auth.admin.util | ||
|
||
import com.wap.wabi.auth.admin.entity.Admin | ||
import io.micrometer.core.instrument.Gauge | ||
import io.micrometer.core.instrument.Metrics | ||
import org.slf4j.LoggerFactory | ||
import org.springframework.scheduling.annotation.Scheduled | ||
import org.springframework.stereotype.Component | ||
|
||
|
||
@Component | ||
class UserActivityManager { | ||
private var dauCounter = 0 | ||
private var mauCounter = 0 | ||
|
||
private val activeUsersToday = HashSet<Admin>() | ||
|
||
private val logger = LoggerFactory.getLogger(UserActivityManager::class.java) | ||
|
||
fun updateUserActivity(admin: Admin) { | ||
if (activeUsersToday.add(admin)) { | ||
dauCounter++ | ||
mauCounter++ | ||
} | ||
|
||
Gauge.builder("user_activity_dau") { dauCounter }.register(Metrics.globalRegistry) | ||
Gauge.builder("user_activity_mau") { mauCounter }.register(Metrics.globalRegistry) | ||
} | ||
|
||
@Scheduled(cron = "0 0 0 * * ?") | ||
fun resetDailyActiveUser() { | ||
dauCounter = 0 | ||
activeUsersToday.clear() | ||
logger.info("Reset daily active user") | ||
} | ||
|
||
@Scheduled(cron = "0 0 0 1 * ?") | ||
fun resetMonthlyActiveUser() { | ||
mauCounter = 0 | ||
logger.info("Reset monthly active user") | ||
} | ||
} |
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