2017-04-05 08:29:48 -04:00
|
|
|
module Gitlab
|
|
|
|
class UsageData
|
2017-04-05 08:49:22 -04:00
|
|
|
include Gitlab::CurrentSettings
|
|
|
|
|
2017-04-05 08:29:48 -04:00
|
|
|
class << self
|
2016-10-19 17:29:01 -04:00
|
|
|
def data(force_refresh: false)
|
|
|
|
Rails.cache.fetch('usage_data', force: force_refresh, expires_in: 2.weeks) { uncached_data }
|
2017-04-05 08:29:48 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def uncached_data
|
|
|
|
license_usage_data.merge(system_usage_data)
|
|
|
|
end
|
|
|
|
|
2016-10-19 17:29:01 -04:00
|
|
|
def to_json(force_refresh: false)
|
|
|
|
data(force_refresh: force_refresh).to_json
|
2017-04-05 08:29:48 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def system_usage_data
|
|
|
|
{
|
|
|
|
counts: {
|
|
|
|
boards: Board.count,
|
|
|
|
ci_builds: ::Ci::Build.count,
|
|
|
|
ci_pipelines: ::Ci::Pipeline.count,
|
|
|
|
ci_runners: ::Ci::Runner.count,
|
|
|
|
ci_triggers: ::Ci::Trigger.count,
|
|
|
|
deploy_keys: DeployKey.count,
|
|
|
|
deployments: Deployment.count,
|
|
|
|
environments: Environment.count,
|
|
|
|
groups: Group.count,
|
|
|
|
issues: Issue.count,
|
|
|
|
keys: Key.count,
|
|
|
|
labels: Label.count,
|
|
|
|
lfs_objects: LfsObject.count,
|
|
|
|
merge_requests: MergeRequest.count,
|
|
|
|
milestones: Milestone.count,
|
|
|
|
notes: Note.count,
|
|
|
|
pages_domains: PagesDomain.count,
|
|
|
|
projects: Project.count,
|
|
|
|
protected_branches: ProtectedBranch.count,
|
|
|
|
releases: Release.count,
|
|
|
|
services: Service.where(active: true).count,
|
|
|
|
snippets: Snippet.count,
|
|
|
|
todos: Todo.count,
|
2017-03-09 11:00:25 -05:00
|
|
|
uploads: Upload.count,
|
2017-04-05 08:29:48 -04:00
|
|
|
web_hooks: WebHook.count
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def license_usage_data
|
2017-04-05 08:49:22 -04:00
|
|
|
usage_data = { uuid: current_application_settings.uuid,
|
|
|
|
version: Gitlab::VERSION,
|
2017-04-05 08:29:48 -04:00
|
|
|
active_user_count: User.active.count,
|
2017-01-18 13:33:33 -05:00
|
|
|
recorded_at: Time.now,
|
|
|
|
mattermost_enabled: Gitlab.config.mattermost.enabled }
|
2017-04-05 08:29:48 -04:00
|
|
|
|
|
|
|
usage_data
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|