-
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.
Move metrics to setup and add cgroup metrics (#76730)
- Loading branch information
Showing
31 changed files
with
629 additions
and
45 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
13 changes: 13 additions & 0 deletions
13
...core/server/kibana-plugin-core-server.metricsservicesetup.collectioninterval.md
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,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [MetricsServiceSetup](./kibana-plugin-core-server.metricsservicesetup.md) > [collectionInterval](./kibana-plugin-core-server.metricsservicesetup.collectioninterval.md) | ||
|
||
## MetricsServiceSetup.collectionInterval property | ||
|
||
Interval metrics are collected in milliseconds | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
readonly collectionInterval: number; | ||
``` |
24 changes: 24 additions & 0 deletions
24
...ent/core/server/kibana-plugin-core-server.metricsservicesetup.getopsmetrics_.md
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,24 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [MetricsServiceSetup](./kibana-plugin-core-server.metricsservicesetup.md) > [getOpsMetrics$](./kibana-plugin-core-server.metricsservicesetup.getopsmetrics_.md) | ||
|
||
## MetricsServiceSetup.getOpsMetrics$ property | ||
|
||
Retrieve an observable emitting the [OpsMetrics](./kibana-plugin-core-server.opsmetrics.md) gathered. The observable will emit an initial value during core's `start` phase, and a new value every fixed interval of time, based on the `opts.interval` configuration property. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
getOpsMetrics$: () => Observable<OpsMetrics>; | ||
``` | ||
|
||
## Example | ||
|
||
|
||
```ts | ||
core.metrics.getOpsMetrics$().subscribe(metrics => { | ||
// do something with the metrics | ||
}) | ||
|
||
``` | ||
|
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
13 changes: 13 additions & 0 deletions
13
docs/development/core/server/kibana-plugin-core-server.opsmetrics.collected_at.md
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,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [OpsMetrics](./kibana-plugin-core-server.opsmetrics.md) > [collected\_at](./kibana-plugin-core-server.opsmetrics.collected_at.md) | ||
|
||
## OpsMetrics.collected\_at property | ||
|
||
Time metrics were recorded at. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
collected_at: Date; | ||
``` |
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
22 changes: 22 additions & 0 deletions
22
docs/development/core/server/kibana-plugin-core-server.opsosmetrics.cpu.md
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,22 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [OpsOsMetrics](./kibana-plugin-core-server.opsosmetrics.md) > [cpu](./kibana-plugin-core-server.opsosmetrics.cpu.md) | ||
|
||
## OpsOsMetrics.cpu property | ||
|
||
cpu cgroup metrics, undefined when not running in a cgroup | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
cpu?: { | ||
control_group: string; | ||
cfs_period_micros: number; | ||
cfs_quota_micros: number; | ||
stat: { | ||
number_of_elapsed_periods: number; | ||
number_of_times_throttled: number; | ||
time_throttled_nanos: number; | ||
}; | ||
}; | ||
``` |
16 changes: 16 additions & 0 deletions
16
docs/development/core/server/kibana-plugin-core-server.opsosmetrics.cpuacct.md
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,16 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [OpsOsMetrics](./kibana-plugin-core-server.opsosmetrics.md) > [cpuacct](./kibana-plugin-core-server.opsosmetrics.cpuacct.md) | ||
|
||
## OpsOsMetrics.cpuacct property | ||
|
||
cpu accounting metrics, undefined when not running in a cgroup | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
cpuacct?: { | ||
control_group: string; | ||
usage_nanos: number; | ||
}; | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import mockFs from 'mock-fs'; | ||
import { OsCgroupMetricsCollector } from './cgroup'; | ||
|
||
describe('OsCgroupMetricsCollector', () => { | ||
afterEach(() => mockFs.restore()); | ||
|
||
it('returns empty object when no cgroup file present', async () => { | ||
mockFs({ | ||
'/proc/self': { | ||
/** empty directory */ | ||
}, | ||
}); | ||
|
||
const collector = new OsCgroupMetricsCollector({}); | ||
expect(await collector.collect()).toEqual({}); | ||
}); | ||
|
||
it('collects default cgroup data', async () => { | ||
mockFs({ | ||
'/proc/self/cgroup': ` | ||
123:memory:/groupname | ||
123:cpu:/groupname | ||
123:cpuacct:/groupname | ||
`, | ||
'/sys/fs/cgroup/cpuacct/groupname/cpuacct.usage': '111', | ||
'/sys/fs/cgroup/cpu/groupname/cpu.cfs_period_us': '222', | ||
'/sys/fs/cgroup/cpu/groupname/cpu.cfs_quota_us': '333', | ||
'/sys/fs/cgroup/cpu/groupname/cpu.stat': ` | ||
nr_periods 444 | ||
nr_throttled 555 | ||
throttled_time 666 | ||
`, | ||
}); | ||
|
||
const collector = new OsCgroupMetricsCollector({}); | ||
expect(await collector.collect()).toMatchInlineSnapshot(` | ||
Object { | ||
"cpu": Object { | ||
"cfs_period_micros": 222, | ||
"cfs_quota_micros": 333, | ||
"control_group": "/groupname", | ||
"stat": Object { | ||
"number_of_elapsed_periods": 444, | ||
"number_of_times_throttled": 555, | ||
"time_throttled_nanos": 666, | ||
}, | ||
}, | ||
"cpuacct": Object { | ||
"control_group": "/groupname", | ||
"usage_nanos": 111, | ||
}, | ||
} | ||
`); | ||
}); | ||
|
||
it('collects override cgroup data', async () => { | ||
mockFs({ | ||
'/proc/self/cgroup': ` | ||
123:memory:/groupname | ||
123:cpu:/groupname | ||
123:cpuacct:/groupname | ||
`, | ||
'/sys/fs/cgroup/cpuacct/xxcustomcpuacctxx/cpuacct.usage': '111', | ||
'/sys/fs/cgroup/cpu/xxcustomcpuxx/cpu.cfs_period_us': '222', | ||
'/sys/fs/cgroup/cpu/xxcustomcpuxx/cpu.cfs_quota_us': '333', | ||
'/sys/fs/cgroup/cpu/xxcustomcpuxx/cpu.stat': ` | ||
nr_periods 444 | ||
nr_throttled 555 | ||
throttled_time 666 | ||
`, | ||
}); | ||
|
||
const collector = new OsCgroupMetricsCollector({ | ||
cpuAcctPath: 'xxcustomcpuacctxx', | ||
cpuPath: 'xxcustomcpuxx', | ||
}); | ||
expect(await collector.collect()).toMatchInlineSnapshot(` | ||
Object { | ||
"cpu": Object { | ||
"cfs_period_micros": 222, | ||
"cfs_quota_micros": 333, | ||
"control_group": "xxcustomcpuxx", | ||
"stat": Object { | ||
"number_of_elapsed_periods": 444, | ||
"number_of_times_throttled": 555, | ||
"time_throttled_nanos": 666, | ||
}, | ||
}, | ||
"cpuacct": Object { | ||
"control_group": "xxcustomcpuacctxx", | ||
"usage_nanos": 111, | ||
}, | ||
} | ||
`); | ||
}); | ||
}); |
Oops, something went wrong.