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
This commit is contained in:
Eric
2024-08-30 17:13:07 -05:00
committed by GitHub
parent 78bd5db0b8
commit 4ffde1dc09
3 changed files with 71 additions and 0 deletions
@@ -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 },
},
+4
View File
@@ -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'},
// ╔═╗╔╦╗╔╗ ╔═╗╔╦╗╔═╗
// ║╣ ║║║╠╩╗║╣ ║║╚═╗
+63
View File
@@ -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'));