metrics_reporter_omaha.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. //
  2. // Copyright (C) 2017 The Android Open Source Project
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. #ifndef UPDATE_ENGINE_METRICS_REPORTER_OMAHA_H_
  17. #define UPDATE_ENGINE_METRICS_REPORTER_OMAHA_H_
  18. #include <memory>
  19. #include <string>
  20. #include <base/time/time.h>
  21. #include <metrics/metrics_library.h>
  22. #include "update_engine/certificate_checker.h"
  23. #include "update_engine/common/constants.h"
  24. #include "update_engine/common/error_code.h"
  25. #include "update_engine/metrics_constants.h"
  26. #include "update_engine/metrics_reporter_interface.h"
  27. #include "update_engine/system_state.h"
  28. namespace chromeos_update_engine {
  29. class SystemState;
  30. namespace metrics {
  31. // UpdateEngine.Daily.* metrics.
  32. extern const char kMetricDailyOSAgeDays[];
  33. // UpdateEngine.Check.* metrics.
  34. extern const char kMetricCheckDownloadErrorCode[];
  35. extern const char kMetricCheckReaction[];
  36. extern const char kMetricCheckResult[];
  37. extern const char kMetricCheckTargetVersion[];
  38. extern const char kMetricCheckRollbackTargetVersion[];
  39. extern const char kMetricCheckTimeSinceLastCheckMinutes[];
  40. extern const char kMetricCheckTimeSinceLastCheckUptimeMinutes[];
  41. // UpdateEngine.Attempt.* metrics.
  42. extern const char kMetricAttemptNumber[];
  43. extern const char kMetricAttemptPayloadType[];
  44. extern const char kMetricAttemptPayloadSizeMiB[];
  45. extern const char kMetricAttemptConnectionType[];
  46. extern const char kMetricAttemptDurationMinutes[];
  47. extern const char kMetricAttemptDurationUptimeMinutes[];
  48. extern const char kMetricAttemptTimeSinceLastAttemptMinutes[];
  49. extern const char kMetricAttemptTimeSinceLastAttemptUptimeMinutes[];
  50. extern const char kMetricAttemptPayloadBytesDownloadedMiB[];
  51. extern const char kMetricAttemptPayloadDownloadSpeedKBps[];
  52. extern const char kMetricAttemptDownloadSource[];
  53. extern const char kMetricAttemptResult[];
  54. extern const char kMetricAttemptInternalErrorCode[];
  55. extern const char kMetricAttemptDownloadErrorCode[];
  56. // UpdateEngine.SuccessfulUpdate.* metrics.
  57. extern const char kMetricSuccessfulUpdateAttemptCount[];
  58. extern const char kMetricSuccessfulUpdateBytesDownloadedMiB[];
  59. extern const char kMetricSuccessfulUpdateDownloadOverheadPercentage[];
  60. extern const char kMetricSuccessfulUpdateDownloadSourcesUsed[];
  61. extern const char kMetricSuccessfulUpdateDurationFromSeenDays[];
  62. extern const char kMetricSuccessfulUpdateDurationFromSeenTimeRestrictedDays[];
  63. extern const char kMetricSuccessfulUpdatePayloadType[];
  64. extern const char kMetricSuccessfulUpdatePayloadSizeMiB[];
  65. extern const char kMetricSuccessfulUpdateRebootCount[];
  66. extern const char kMetricSuccessfulUpdateTotalDurationMinutes[];
  67. extern const char kMetricSuccessfulUpdateTotalDurationUptimeMinutes[];
  68. extern const char kMetricSuccessfulUpdateUpdatesAbandonedCount[];
  69. extern const char kMetricSuccessfulUpdateUrlSwitchCount[];
  70. // UpdateEngine.Rollback.* metric.
  71. extern const char kMetricRollbackResult[];
  72. // UpdateEngine.EnterpriseRollback.* metrics.
  73. extern const char kMetricEnterpriseRollbackFailure[];
  74. extern const char kMetricEnterpriseRollbackSuccess[];
  75. // UpdateEngine.CertificateCheck.* metrics.
  76. extern const char kMetricCertificateCheckUpdateCheck[];
  77. extern const char kMetricCertificateCheckDownload[];
  78. // UpdateEngine.KernelKey.* metrics.
  79. extern const char kMetricKernelMinVersion[];
  80. extern const char kMetricKernelMaxRollforwardVersion[];
  81. extern const char kMetricKernelMaxRollforwardSetSuccess[];
  82. // UpdateEngine.* metrics.
  83. extern const char kMetricFailedUpdateCount[];
  84. extern const char kMetricInstallDateProvisioningSource[];
  85. extern const char kMetricTimeToRebootMinutes[];
  86. } // namespace metrics
  87. class MetricsReporterOmaha : public MetricsReporterInterface {
  88. public:
  89. MetricsReporterOmaha();
  90. ~MetricsReporterOmaha() override = default;
  91. void Initialize() override;
  92. void ReportRollbackMetrics(metrics::RollbackResult result) override;
  93. void ReportEnterpriseRollbackMetrics(
  94. bool success, const std::string& rollback_version) override;
  95. void ReportDailyMetrics(base::TimeDelta os_age) override;
  96. void ReportUpdateCheckMetrics(
  97. SystemState* system_state,
  98. metrics::CheckResult result,
  99. metrics::CheckReaction reaction,
  100. metrics::DownloadErrorCode download_error_code) override;
  101. void ReportUpdateAttemptMetrics(SystemState* system_state,
  102. int attempt_number,
  103. PayloadType payload_type,
  104. base::TimeDelta duration,
  105. base::TimeDelta duration_uptime,
  106. int64_t payload_size,
  107. metrics::AttemptResult attempt_result,
  108. ErrorCode internal_error_code) override;
  109. void ReportUpdateAttemptDownloadMetrics(
  110. int64_t payload_bytes_downloaded,
  111. int64_t payload_download_speed_bps,
  112. DownloadSource download_source,
  113. metrics::DownloadErrorCode payload_download_error_code,
  114. metrics::ConnectionType connection_type) override;
  115. void ReportAbnormallyTerminatedUpdateAttemptMetrics() override;
  116. void ReportSuccessfulUpdateMetrics(
  117. int attempt_count,
  118. int updates_abandoned_count,
  119. PayloadType payload_type,
  120. int64_t payload_size,
  121. int64_t num_bytes_downloaded[kNumDownloadSources],
  122. int download_overhead_percentage,
  123. base::TimeDelta total_duration,
  124. base::TimeDelta total_duration_uptime,
  125. int reboot_count,
  126. int url_switch_count) override;
  127. void ReportCertificateCheckMetrics(ServerToCheck server_to_check,
  128. CertificateCheckResult result) override;
  129. void ReportFailedUpdateCount(int target_attempt) override;
  130. void ReportTimeToReboot(int time_to_reboot_minutes) override;
  131. void ReportInstallDateProvisioningSource(int source, int max) override;
  132. void ReportInternalErrorCode(ErrorCode error_code) override;
  133. void ReportKeyVersionMetrics(int kernel_min_version,
  134. int kernel_max_rollforward_version,
  135. bool kernel_max_rollforward_success) override;
  136. void ReportEnterpriseUpdateSeenToDownloadDays(
  137. bool has_time_restriction_policy, int time_to_update_days) override;
  138. private:
  139. friend class MetricsReporterOmahaTest;
  140. std::unique_ptr<MetricsLibraryInterface> metrics_lib_;
  141. DISALLOW_COPY_AND_ASSIGN(MetricsReporterOmaha);
  142. }; // class metrics
  143. } // namespace chromeos_update_engine
  144. #endif // UPDATE_ENGINE_METRICS_REPORTER_OMAHA_H_