Skip to content

Commit

Permalink
[Fleet] Add agents per OS telemetry (#163039)
Browse files Browse the repository at this point in the history
## Summary

Querying agent operating system to add to telemetry.

How to test locally:
- enroll a few different agents running on different operating system
- wait up to 1h to see the telemetry task triggered
- check debug logs to see that the agents per version telemetry contains
the status information
  • Loading branch information
pierrehilbert authored Aug 3, 2023
1 parent b6d94d7 commit b9dae73
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 1 deletion.
25 changes: 25 additions & 0 deletions x-pack/plugins/fleet/server/collectors/agent_collectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,18 @@ export interface AgentData {
degraded: number;
};
agents_per_policy: number[];
agents_per_os: Array<{
name: string;
version: string;
count: number;
}>;
}

const DEFAULT_AGENT_DATA = {
agent_checkin_status: { error: 0, degraded: 0 },
agents_per_policy: [],
agents_per_version: [],
agents_per_os: [],
};

export const getAgentData = async (
Expand Down Expand Up @@ -117,6 +123,18 @@ export const getAgentData = async (
policies: {
terms: { field: 'policy_id' },
},
os: {
multi_terms: {
terms: [
{
field: 'local_metadata.os.name.keyword',
},
{
field: 'local_metadata.os.version.keyword',
},
],
},
},
},
},
{ signal: abortController.signal }
Expand Down Expand Up @@ -166,10 +184,17 @@ export const getAgentData = async (
(bucket: any) => bucket.doc_count
);

const agentsPerOS = ((response?.aggregations?.os as any).buckets ?? []).map((bucket: any) => ({
name: bucket.key[0],
version: bucket.key[1],
count: bucket.doc_count,
}));

return {
agent_checkin_status: statuses,
agents_per_policy: agentsPerPolicy,
agents_per_version: agentsPerVersion,
agents_per_os: agentsPerOS,
};
} catch (error) {
if (error.statusCode === 404) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ describe('fleet usage telemetry', () => {
last_checkin: '2022-11-21T12:26:24Z',
active: true,
policy_id: 'policy1',
local_metadata: {
os: {
name: 'Ubuntu',
version: '22.04.2 LTS (Jammy Jellyfish)',
},
},
},
{
create: {
Expand All @@ -144,6 +150,12 @@ describe('fleet usage telemetry', () => {
last_checkin: '2022-11-21T12:27:24Z',
active: true,
policy_id: 'policy1',
local_metadata: {
os: {
name: 'Ubuntu',
version: '20.04.5 LTS (Focal Fossa)',
},
},
},
{
create: {
Expand All @@ -158,6 +170,12 @@ describe('fleet usage telemetry', () => {
last_checkin: '2021-11-21T12:27:24Z',
active: false,
policy_id: 'policy1',
local_metadata: {
os: {
name: 'Ubuntu',
version: '20.04.5 LTS (Focal Fossa)',
},
},
},
],
refresh: 'wait_for',
Expand Down Expand Up @@ -374,6 +392,18 @@ describe('fleet usage telemetry', () => {
],
agent_checkin_status: { error: 1, degraded: 1 },
agents_per_policy: [2],
agents_per_os: [
{
name: 'Ubuntu',
version: '20.04.5 LTS (Focal Fossa)',
count: 1,
},
{
name: 'Ubuntu',
version: '22.04.2 LTS (Jammy Jellyfish)',
count: 1,
},
],
fleet_server_config: {
policies: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const FLEET_AGENTS_EVENT_TYPE = 'fleet_agents';

export class FleetUsageSender {
private taskManager?: TaskManagerStartContract;
private taskVersion = '1.1.0';
private taskVersion = '1.1.1';
private taskType = 'Fleet-Usage-Sender';
private wasStarted: boolean = false;
private interval = '1h';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,26 @@ export const fleetUsagesSchema: RootSchema<any> = {
_meta: { description: 'Top messages from fleet server error logs' },
},
},
agents_per_os: {
properties: {
name: {
type: 'keyword',
_meta: {
description: 'Agent OS enrolled to this kibana',
},
},
version: {
type: 'keyword',
_meta: {
description: 'Agent OS version enrolled to this kibana',
},
},
count: {
type: 'long',
_meta: {
description: 'Number of agents enrolled that use this OS',
},
},
},
},
};

0 comments on commit b9dae73

Please sign in to comment.