Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 36 additions & 25 deletions pipeline/inputs/cpu-metrics.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,51 @@
# CPU Metrics
# CPU metrics

The **cpu** input plugin, measures the CPU usage of a process or the whole system by default \(considering per CPU core\). It reports values in percentage unit for every interval of time set. At the moment this plugin is only available for Linux.
The _CPU_ input plugin, measures the CPU usage of a process or the whole system by default (considering per CPU core). It reports values in percentage unit for every interval of time set. This plugin is available only for Linux.

The following tables describes the information generated by the plugin. The keys below represent the data used by the overall system, all values associated to the keys are in a percentage unit \(0 to 100%\):
The following tables describe the information generated by the plugin. The following keys represent the data used by the overall system, and all values associated to the keys are in a percentage unit (0 to 100%):

The CPU metrics plugin creates metrics that are log-based, such as JSON payload. For
Prometheus-based metrics, see the Node Exporter Metrics input plugin.
The CPU metrics plugin creates metrics that are log-based, such as JSON payload. For Prometheus-based metrics, see the _Node Exporter Metrics_ input plugin.

| key | description |
| Key | Description |
| :--- | :--- |
| cpu\_p | CPU usage of the overall system, this value is the summation of time spent on user and kernel space. The result takes in consideration the numbers of CPU cores in the system. |
| user\_p | CPU usage in User mode, for short it means the CPU usage by user space programs. The result of this value takes in consideration the numbers of CPU cores in the system. |
| system\_p | CPU usage in Kernel mode, for short it means the CPU usage by the Kernel. The result of this value takes in consideration the numbers of CPU cores in the system. |
| threaded | Indicates whether to run this input in its own [thread](../../administration/multithreading.md#inputs). Default: `false`. |
| `cpu_p` | CPU usage of the overall system, this value is the summation of time spent on user and kernel space. The result takes in consideration the numbers of CPU cores in the system. |
| `user_p` | CPU usage in User mode, for short it means the CPU usage by user space programs. The result of this value takes in consideration the numbers of CPU cores in the system. |
| `system_p` | CPU usage in Kernel mode, for short it means the CPU usage by the Kernel. The result of this value takes in consideration the numbers of CPU cores in the system. |
| `threaded` | Indicates whether to run this input in its own [thread](../../administration/multithreading.md#inputs). Default: `false`. |

In addition to the keys reported in the above table, a similar content is created **per** CPU core. The cores are listed from _0_ to _N_ as the Kernel reports:
In addition to the keys reported in the previous table, a similar content is created per CPU core. The cores are listed from `0` to `N` as the Kernel reports:

| key | description |
| Key | Description |
| :--- | :--- |
| cpu**N**.p\_cpu | Represents the total CPU usage by core **N**. |
| cpu**N**.p\_user | Total CPU spent in user mode or user space programs associated to this core. |
| cpu**N**.p\_system | Total CPU spent in system or kernel mode associated to this core. |
| `cpuN.p_cpu` | Represents the total CPU usage by core `N`. |
| `cpuN.p_user` | Total CPU spent in user mode or user space programs associated to this core. |
| `cpuN.p_system` | Total CPU spent in system or kernel mode associated to this core. |

## Configuration Parameters
## Configuration parameters

The plugin supports the following configuration parameters:

| Key | Description | Default |
| :--- | :--- | :--- |
| Interval\_Sec | Polling interval in seconds | 1 |
| Interval\_NSec | Polling interval in nanoseconds | 0 |
| PID | Specify the ID \(PID\) of a running process in the system. By default the plugin monitors the whole system but if this option is set, it will only monitor the given process ID. | |
| `Interval_Sec` | Polling interval in seconds. | `1` |
| `Interval_NSec | Polling interval in nanoseconds` | `0` |
| `PID` | Specify the `ID` (`PID`) of a running process in the system. By default, the plugin monitors the whole system but if this option is set, it will only monitor the given process ID. | _none_ |

## Getting Started
## Get started

In order to get the statistics of the CPU usage of your system, you can run the plugin from the command line or through the configuration file:

### Command Line
### Command line

You can run this filter from the command line using a command like the following:

```bash
$ build/bin/fluent-bit -i cpu -t my_cpu -o stdout -m '*'
build/bin/fluent-bit -i cpu -t my_cpu -o stdout -m '*'
```

The command returns results similar to the following:

```text
Fluent Bit v1.x.x
* Copyright (C) 2019-2020 The Fluent Bit Authors
* Copyright (C) 2015-2018 Treasure Data
Expand All @@ -53,14 +59,15 @@ Fluent Bit v1.x.x
[3] [1452185192, {"cpu_p"=>4.50, "user_p"=>3.50, "system_p"=>1.00, "cpu0.p_cpu"=>6.00, "cpu0.p_user"=>5.00, "cpu0.p_system"=>1.00, "cpu1.p_cpu"=>5.00, "cpu1.p_user"=>3.00, "cpu1.p_system"=>2.00}]
```

As described above, the CPU input plugin gathers the overall usage every one second and flushed the information to the output on the fifth second. On this example we used the **stdout** plugin to demonstrate the output records. In a real use-case you may want to flush this information to some central aggregator such as [Fluentd](http://fluentd.org) or [Elasticsearch](http://elastic.co).
As described previously, the CPU input plugin gathers the overall usage every one second and flushed the information to the output on the fifth second. This example uses the `stdout` plugin to demonstrate the output records. In a real use-case you might want to flush this information to some central aggregator such as [Fluentd](http://fluentd.org) or [Elasticsearch](http://elastic.co).

### Configuration File
### Configuration file

In your main configuration file append the following _Input_ and _Output_ sections:
In your main configuration file append the following `Input` and `Output` sections:

{% tabs %}
{% tab title="fluent-bit.conf" %}

```python
[INPUT]
Name cpu
Expand All @@ -70,10 +77,13 @@ In your main configuration file append the following _Input_ and _Output_ sectio
Name stdout
Match *
```

{% endtab %}

{% tab title="fluent-bit.yaml" %}

```yaml

pipeline:
inputs:
- name: cpu
Expand All @@ -83,5 +93,6 @@ pipeline:
- name: stdout
match: '*'
```

{% endtab %}
{% endtabs %}