From 4ffde1dc09e63565026da894f5cbd2c42835c83b Mon Sep 17 00:00:00 2001 From: Eric Date: Fri, 30 Aug 2024 17:13:07 -0500 Subject: [PATCH] Website: add new metrics to HistoricalUsageSnapshot model. (#21625) Related to: #21259 Changes: - Updated the `receive-usage-analytics` webhook to add new inputs for metrics added in [#21131](https://github.com/fleetdm/fleet/pull/21131) - Updated the `HIstoricalUsageSnapshot` model to add attributes for the new metrics. When this PR is merged: - [ ] Put the website into maintenance mode - [ ] Update the HistoricalUsageSnapshot table to add new columns - [ ] Update all existing records to set the default value for the new columns --- .../webhooks/receive-usage-analytics.js | 4 ++ website/api/models/HistoricalUsageSnapshot.js | 4 ++ .../send-aggregated-metrics-to-datadog.js | 63 +++++++++++++++++++ 3 files changed, 71 insertions(+) diff --git a/website/api/controllers/webhooks/receive-usage-analytics.js b/website/api/controllers/webhooks/receive-usage-analytics.js index 9094c11d79..94f7fec744 100644 --- a/website/api/controllers/webhooks/receive-usage-analytics.js +++ b/website/api/controllers/webhooks/receive-usage-analytics.js @@ -39,6 +39,10 @@ module.exports = { numHostSoftwareInstalledPaths: {type: 'number', defaultsTo: 0}, numSoftwareCPEs: {type: 'number', defaultsTo: 0}, numSoftwareCVEs: {type: 'number', defaultsTo: 0}, + aiFeaturesDisabled: {type: 'boolean', defaultsTo: false }, + maintenanceWindowsEnabled: {type: 'boolean', defaultsTo: false }, + maintenanceWindowsConfigured: {type: 'boolean', defaultsTo: false }, + numHostsFleetDesktopEnabled: {type: 'number', defaultsTo: 0 }, }, diff --git a/website/api/models/HistoricalUsageSnapshot.js b/website/api/models/HistoricalUsageSnapshot.js index 5481d42e53..1f14b9b291 100644 --- a/website/api/models/HistoricalUsageSnapshot.js +++ b/website/api/models/HistoricalUsageSnapshot.js @@ -43,6 +43,10 @@ module.exports = { numHostSoftwareInstalledPaths: {required: true, type: 'number'}, numSoftwareCPEs: {required: true, type: 'number'}, numSoftwareCVEs: {required: true, type: 'number'}, + aiFeaturesDisabled: {required: true, type: 'boolean'}, + maintenanceWindowsEnabled: {required: true, type: 'boolean'}, + maintenanceWindowsConfigured: {required: true, type: 'boolean'}, + numHostsFleetDesktopEnabled: {required: true, type: 'number'}, // ╔═╗╔╦╗╔╗ ╔═╗╔╦╗╔═╗ // ║╣ ║║║╠╩╗║╣ ║║╚═╗ diff --git a/website/scripts/send-aggregated-metrics-to-datadog.js b/website/scripts/send-aggregated-metrics-to-datadog.js index 959c3625b5..af3cccceb6 100644 --- a/website/scripts/send-aggregated-metrics-to-datadog.js +++ b/website/scripts/send-aggregated-metrics-to-datadog.js @@ -406,6 +406,69 @@ module.exports = { }], tags: [`enabled:false`], }); + // aiFeaturesDisabled + let numberOfInstancesWithAiFeaturesDisabled = _.where(latestStatisticsReportedByReleasedFleetVersions, {aiFeaturesDisabled: true}).length; + let numberOfInstancesWithAiFeaturesEnabled = numberOfInstancesToReport - numberOfInstancesWithAiFeaturesDisabled; + metricsToReport.push({ + metric: 'usage_statistics.ai_features', + type: 3, + points: [{ + timestamp: timestampForTheseMetrics, + value: numberOfInstancesWithAiFeaturesEnabled + }], + tags: [`enabled:true`], + }); + metricsToReport.push({ + metric: 'usage_statistics.ai_features', + type: 3, + points: [{ + timestamp: timestampForTheseMetrics, + value: numberOfInstancesWithAiFeaturesDisabled + }], + tags: [`enabled:false`], + }); + // maintenanceWindowsEnabled + let numberOfInstancesWithMaintenanceWindowsEnabled = _.where(latestStatisticsReportedByReleasedFleetVersions, {maintenanceWindowsEnabled: true}).length; + let numberOfInstancesWithMaintenanceWindowsDisabled = numberOfInstancesToReport - numberOfInstancesWithMaintenanceWindowsEnabled; + metricsToReport.push({ + metric: 'usage_statistics.maintenance_windows', + type: 3, + points: [{ + timestamp: timestampForTheseMetrics, + value: numberOfInstancesWithMaintenanceWindowsEnabled + }], + tags: [`enabled:true`], + }); + metricsToReport.push({ + metric: 'usage_statistics.maintenance_windows', + type: 3, + points: [{ + timestamp: timestampForTheseMetrics, + value: numberOfInstancesWithMaintenanceWindowsDisabled + }], + tags: [`enabled:false`], + }); + // maintenanceWindowsConfigured + let numberOfInstancesWithMaintenanceWindowsConfigured = _.where(latestStatisticsReportedByReleasedFleetVersions, {maintenanceWindowsEnabled: true}).length; + let numberOfInstancesWithoutMaintenanceWindowsConfigured = numberOfInstancesToReport - numberOfInstancesWithMaintenanceWindowsEnabled; + metricsToReport.push({ + metric: 'usage_statistics.maintenance_windows_configured', + type: 3, + points: [{ + timestamp: timestampForTheseMetrics, + value: numberOfInstancesWithMaintenanceWindowsConfigured + }], + tags: [`configured:true`], + }); + metricsToReport.push({ + metric: 'usage_statistics.maintenance_windows_configured', + type: 3, + points: [{ + timestamp: timestampForTheseMetrics, + value: numberOfInstancesWithoutMaintenanceWindowsConfigured + }], + tags: [`configured:false`], + }); // Create two metrics to track total number of hosts reported in the last week. let totalNumberOfHostsReportedByPremiumInstancesInTheLastWeek = _.sum(_.pluck(_.filter(latestStatisticsReportedByReleasedFleetVersions, {licenseTier: 'premium'}), 'numHostsEnrolled'));