diff --git a/api/admin.go b/api/admin.go
index 300796bad7..4e4d21b0b1 100644
--- a/api/admin.go
+++ b/api/admin.go
@@ -25,6 +25,11 @@ import (
"github.com/mssola/user_agent"
)
+const (
+ DAY_MILLISECONDS = 24 * 60 * 60 * 1000
+ MONTH_MILLISECONDS = 31 * DAY_MILLISECONDS
+)
+
func InitAdmin() {
l4g.Debug(utils.T("api.admin.init.debug"))
@@ -382,7 +387,7 @@ func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) {
}
if name == "standard" {
- var rows model.AnalyticsRows = make([]*model.AnalyticsRow, 8)
+ var rows model.AnalyticsRows = make([]*model.AnalyticsRow, 10)
rows[0] = &model.AnalyticsRow{"channel_open_count", 0}
rows[1] = &model.AnalyticsRow{"channel_private_count", 0}
rows[2] = &model.AnalyticsRow{"post_count", 0}
@@ -391,6 +396,8 @@ func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) {
rows[5] = &model.AnalyticsRow{"total_websocket_connections", 0}
rows[6] = &model.AnalyticsRow{"total_master_db_connections", 0}
rows[7] = &model.AnalyticsRow{"total_read_db_connections", 0}
+ rows[8] = &model.AnalyticsRow{"daily_active_users", 0}
+ rows[9] = &model.AnalyticsRow{"monthly_active_users", 0}
openChan := app.Srv.Store.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_OPEN)
privateChan := app.Srv.Store.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_PRIVATE)
@@ -406,6 +413,9 @@ func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) {
postChan = app.Srv.Store.Post().AnalyticsPostCount(teamId, false, false)
}
+ dailyActiveChan := app.Srv.Store.User().AnalyticsActiveCount(DAY_MILLISECONDS)
+ monthlyActiveChan := app.Srv.Store.User().AnalyticsActiveCount(MONTH_MILLISECONDS)
+
if r := <-openChan; r.Err != nil {
c.Err = r.Err
return
@@ -477,6 +487,20 @@ func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) {
rows[7].Value = float64(app.Srv.Store.TotalReadDbConnections())
}
+ if r := <-dailyActiveChan; r.Err != nil {
+ c.Err = r.Err
+ return
+ } else {
+ rows[8].Value = float64(r.Data.(int64))
+ }
+
+ if r := <-monthlyActiveChan; r.Err != nil {
+ c.Err = r.Err
+ return
+ } else {
+ rows[9].Value = float64(r.Data.(int64))
+ }
+
w.Write([]byte(rows.ToJson()))
} else if name == "post_counts_day" {
if skipIntensiveQueries {
diff --git a/store/sql_user_store.go b/store/sql_user_store.go
index 533757479a..09742a4f44 100644
--- a/store/sql_user_store.go
+++ b/store/sql_user_store.go
@@ -1129,6 +1129,31 @@ func (us SqlUserStore) AnalyticsUniqueUserCount(teamId string) StoreChannel {
return storeChannel
}
+func (us SqlUserStore) AnalyticsActiveCount(timePeriod int64) StoreChannel {
+
+ storeChannel := make(StoreChannel, 1)
+
+ go func() {
+ result := StoreResult{}
+
+ time := model.GetMillis() - timePeriod
+
+ query := "SELECT COUNT(*) FROM Status WHERE LastActivityAt > :Time"
+
+ v, err := us.GetReplica().SelectInt(query, map[string]interface{}{"Time": time})
+ if err != nil {
+ result.Err = model.NewLocAppError("SqlUserStore.AnalyticsDailyActiveUsers", "store.sql_user.analytics_daily_active_users.app_error", nil, err.Error())
+ } else {
+ result.Data = v
+ }
+
+ storeChannel <- result
+ close(storeChannel)
+ }()
+
+ return storeChannel
+}
+
func (us SqlUserStore) GetUnreadCount(userId string) StoreChannel {
storeChannel := make(StoreChannel, 1)
diff --git a/store/store.go b/store/store.go
index 88a553b7ca..730a923c52 100644
--- a/store/store.go
+++ b/store/store.go
@@ -175,6 +175,7 @@ type UserStore interface {
GetSystemAdminProfiles() StoreChannel
PermanentDelete(userId string) StoreChannel
AnalyticsUniqueUserCount(teamId string) StoreChannel
+ AnalyticsActiveCount(time int64) StoreChannel
GetUnreadCount(userId string) StoreChannel
GetUnreadCountForChannel(userId string, channelId string) StoreChannel
GetRecentlyActiveUsersForTeam(teamId string) StoreChannel
diff --git a/webapp/components/analytics/system_analytics.jsx b/webapp/components/analytics/system_analytics.jsx
index dd7b902605..89cc98f0be 100644
--- a/webapp/components/analytics/system_analytics.jsx
+++ b/webapp/components/analytics/system_analytics.jsx
@@ -358,6 +358,32 @@ class SystemAnalytics extends React.Component {
/>
);
+ const dailyActiveUsers = (
+