BigW Consortium Gitlab

usage_data.rb 1.97 KB
Newer Older
1 2
module Gitlab
  class UsageData
3 4
    include Gitlab::CurrentSettings

5
    class << self
6 7
      def data(force_refresh: false)
        Rails.cache.fetch('usage_data', force: force_refresh, expires_in: 2.weeks) { uncached_data }
8 9 10 11 12 13
      end

      def uncached_data
        license_usage_data.merge(system_usage_data)
      end

14 15
      def to_json(force_refresh: false)
        data(force_refresh: force_refresh).to_json
16 17 18 19 20 21 22 23 24 25
      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,
26
            ci_pipeline_schedules: ::Ci::PipelineSchedule.count,
27 28 29 30 31 32 33 34 35 36 37 38 39
            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,
40
            projects_prometheus_active: PrometheusService.active.count,
41 42 43 44
            protected_branches: ProtectedBranch.count,
            releases: Release.count,
            snippets: Snippet.count,
            todos: Todo.count,
45
            uploads: Upload.count,
46 47 48 49 50 51
            web_hooks: WebHook.count
          }
        }
      end

      def license_usage_data
52 53
        usage_data = {
          uuid: current_application_settings.uuid,
54
          hostname: Gitlab.config.gitlab.host,
55 56 57 58 59 60
          version: Gitlab::VERSION,
          active_user_count: User.active.count,
          recorded_at: Time.now,
          mattermost_enabled: Gitlab.config.mattermost.enabled,
          edition: 'CE'
        }
61 62 63 64 65 66

        usage_data
      end
    end
  end
end