-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add server OS data to monitoring collector and telemetry * Fixup naming * Fix functional tests
- Loading branch information
Showing
10 changed files
with
209 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
x-pack/plugins/monitoring/server/kibana_monitoring/collectors/ops_buffer/get_os_info.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import os from 'os'; | ||
import getos from 'getos'; | ||
import { promisify } from 'util'; | ||
|
||
/** | ||
* Returns an object of OS information/ | ||
*/ | ||
export async function getOSInfo() { | ||
const osInfo = { | ||
platform: os.platform(), | ||
// Include the platform name in the release to avoid grouping unrelated platforms together. | ||
// release 1.0 across windows, linux, and darwin don't mean anything useful. | ||
platformRelease: `${os.platform()}-${os.release()}` | ||
}; | ||
|
||
// Get distribution information for linux | ||
if (os.platform() === 'linux') { | ||
try { | ||
const distro = await promisify(getos)(); | ||
osInfo.distro = distro.dist; | ||
// Include distro name in release for same reason as above. | ||
osInfo.distroRelease = `${distro.dist}-${distro.release}`; | ||
} catch (e) { | ||
// ignore errors | ||
} | ||
} | ||
|
||
return osInfo; | ||
} |
53 changes: 53 additions & 0 deletions
53
x-pack/plugins/monitoring/server/kibana_monitoring/collectors/ops_buffer/get_os_info.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
jest.mock('os', () => ({ | ||
platform: jest.fn(), | ||
release: jest.fn(), | ||
})); | ||
jest.mock('getos'); | ||
|
||
import os from 'os'; | ||
import getos from 'getos'; | ||
|
||
import { getOSInfo } from './get_os_info'; | ||
|
||
describe('getOSInfo', () => { | ||
it('returns basic OS info on non-linux', async () => { | ||
os.platform.mockImplementation(() => 'darwin'); | ||
os.release.mockImplementation(() => '1.0.0'); | ||
|
||
const osInfo = await getOSInfo(); | ||
|
||
expect(osInfo).toEqual({ | ||
platform: 'darwin', | ||
platformRelease: 'darwin-1.0.0', | ||
}); | ||
}); | ||
|
||
it('returns basic OS info and distro info on linux', async () => { | ||
os.platform.mockImplementation(() => 'linux'); | ||
os.release.mockImplementation(() => '4.9.93-linuxkit-aufs'); | ||
|
||
// Mock getos response | ||
getos.mockImplementation((cb) => cb(null, { | ||
os: 'linux', | ||
dist: 'Ubuntu Linux', | ||
codename: 'precise', | ||
release: '12.04' | ||
})); | ||
|
||
const osInfo = await getOSInfo(); | ||
|
||
expect(osInfo).toEqual({ | ||
platform: 'linux', | ||
platformRelease: 'linux-4.9.93-linuxkit-aufs', | ||
// linux distro info | ||
distro: 'Ubuntu Linux', | ||
distroRelease: 'Ubuntu Linux-12.04', | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters