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,
|
2017-06-19 13:56:27 -04:00
|
|
|
ci_internal_pipelines: ::Ci::Pipeline.internal.count,
|
|
|
|
ci_external_pipelines: ::Ci::Pipeline.external.count,
|
2017-04-05 08:29:48 -04:00
|
|
|
ci_runners: ::Ci::Runner.count,
|
|
|
|
ci_triggers: ::Ci::Trigger.count,
|
2017-05-07 18:35:56 -04:00
|
|
|
ci_pipeline_schedules: ::Ci::PipelineSchedule.count,
|
2017-04-05 08:29:48 -04:00
|
|
|
deploy_keys: DeployKey.count,
|
|
|
|
deployments: Deployment.count,
|
|
|
|
environments: Environment.count,
|
2017-06-15 06:50:45 -04:00
|
|
|
in_review_folder: Environment.in_review_folder.count,
|
2017-04-05 08:29:48 -04:00
|
|
|
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,
|
2017-07-19 03:07:17 -04:00
|
|
|
projects_imported_from_github: Project.where(import_type: 'github').count,
|
2017-04-05 08:29:48 -04:00
|
|
|
protected_branches: ProtectedBranch.count,
|
|
|
|
releases: Release.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
|
2017-07-19 10:45:28 -04:00
|
|
|
}.merge(services_usage)
|
2017-04-05 08:29:48 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def license_usage_data
|
2017-04-06 15:16:57 -04:00
|
|
|
usage_data = {
|
|
|
|
uuid: current_application_settings.uuid,
|
2017-05-09 15:58:22 -04:00
|
|
|
hostname: Gitlab.config.gitlab.host,
|
2017-04-06 15:16:57 -04:00
|
|
|
version: Gitlab::VERSION,
|
|
|
|
active_user_count: User.active.count,
|
|
|
|
recorded_at: Time.now,
|
|
|
|
mattermost_enabled: Gitlab.config.mattermost.enabled,
|
|
|
|
edition: 'CE'
|
|
|
|
}
|
2017-04-05 08:29:48 -04:00
|
|
|
|
|
|
|
usage_data
|
|
|
|
end
|
2017-07-19 10:45:28 -04:00
|
|
|
|
|
|
|
def services_usage
|
|
|
|
types = {
|
|
|
|
JiraService: :projects_jira_active,
|
|
|
|
SlackService: :projects_slack_notifications_active,
|
|
|
|
SlackSlashCommandsService: :projects_slack_slash_active,
|
|
|
|
PrometheusService: :projects_prometheus_active
|
|
|
|
}
|
|
|
|
|
|
|
|
results = Service.unscoped.where(type: types.keys, active: true).group(:type).count
|
|
|
|
results.each_with_object({}) { |(key, value), response| response[types[key.to_sym]] = value }
|
|
|
|
end
|
2017-04-05 08:29:48 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|