Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Stat Chart (#787) #789

Merged
merged 3 commits into from
Feb 10, 2023
Merged

Add Stat Chart (#787) #789

merged 3 commits into from
Feb 10, 2023

Conversation

NickLanam
Copy link
Member

@NickLanam NickLanam commented Feb 6, 2023

Signed-off-by: Nick Lanam nlanam@pixielabs.ai

image

Summary: Adds a new chart type, 'StatChart', which just displays the latest value of a single metric with units and label.

Relevant Issues: Fixes #787

Type of change: /kind feature

Test Plan: Try this script with this vis spec.

import px
import pxviews

ns_per_ms = 1000 * 1000
ns_per_s = 1000 * ns_per_ms
# Window size to use on time_ column for bucketing.
window_ns = px.DurationNanos(10 * ns_per_s)

def resource_timeseries(start_time: str, node: px.Node):
    ''' Gets the windowed process stats (CPU, memory, etc) for the input node.

    Args:
    @start_time Starting time of the data to examine.
    @node: The full name of the node to filter on.
    '''
    df = pxviews.container_process_timeseries(start_time, px.now(), window_ns)
    df = df[df.ctx['node'] == node]
    df['node'] = df.ctx['node']

    df = df.groupby(['time_', 'node']).agg(
        cpu_usage=('cpu_usage', px.sum),
        actual_disk_read_throughput=('actual_disk_read_throughput', px.sum),
        actual_disk_write_throughput=('actual_disk_write_throughput', px.sum),
        total_disk_read_throughput=('total_disk_read_throughput', px.sum),
        total_disk_write_throughput=('total_disk_write_throughput', px.sum),
        rss=('rss', px.sum),
        vsize=('vsize', px.sum),
    )

    df.groupby_col = df['node']
    return df
{
  "variables": [
      {
          "name": "start_time",
          "type": "PX_STRING",
          "description": "The relative start time of the window. Current time is assumed to be now",
          "defaultValue": "-5m"
      },
      {
          "name": "node",
          "type": "PX_NODE",
          "description": "The node name to filter on"
      }
  ],
  "globalFuncs": [
      {
          "outputName": "resource_timeseries",
          "func": {
              "name": "resource_timeseries",
              "args": [
                  {
                      "name": "start_time",
                      "variable": "start_time"
                  },
                  {
                      "name": "node",
                      "variable": "node"
                  }
              ]
          }
      }
  ],
  "widgets": [
      {
          "name": "CPU Stat",
          "position": {
              "x": 0,
              "y": 0,
              "w": 1,
              "h": 1
          },
          "globalFuncOutputName": "resource_timeseries",
          "displaySpec": {
              "@type": "types.px.dev/px.vispb.StatChart",
              "title": "CPU Usage",
              "stat": {
                  "value": "cpu_usage"
              }
          }
      },
      {
        "name": "Bytes Read Stat",
        "position": {
            "x": 2,
            "y": 0,
            "w": 2,
            "h": 2
        },
        "globalFuncOutputName": "resource_timeseries",
        "displaySpec": {
            "@type": "types.px.dev/px.vispb.StatChart",
            "title": "Bytes Read",
            "stat": {
                "value": "total_disk_read_throughput"
            }
        }
    }
  ]
}

Changelog Message:

New chart type: Stat. Shows a label, metric, and units for that metric.

@aimichelle
Copy link
Member

Screenshots?

@NickLanam
Copy link
Member Author

Screenshots?

I think I attached those a couple of seconds after you loaded the page

@zasgar zasgar changed the title [GH-787] Add Stat Chart Add Stat Chart (#787) Feb 7, 2023
Summary:

Fixes pixie-io#787

Test Plan:

Signed-off-by: Nick Lanam <nlanam@pixielabs.ai>
Signed-off-by: Nick Lanam <nlanam@pixielabs.ai>
src/api/proto/vispb/vis.proto Show resolved Hide resolved
src/pxl_scripts/watch.sh Outdated Show resolved Hide resolved
Copy link
Member

@aimichelle aimichelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marking as request changes, since I didn't for my previous comments.

Signed-off-by: Nick Lanam <nlanam@pixielabs.ai>
@NickLanam NickLanam requested a review from aimichelle February 9, 2023 23:36
@aimichelle aimichelle merged commit 2f940fb into pixie-io:main Feb 10, 2023
@NickLanam NickLanam deleted the stat-chart branch February 10, 2023 20:34
RagalahariP pushed a commit to RagalahariP/pixie that referenced this pull request Feb 15, 2023
Signed-off-by: Nick Lanam <nlanam@pixielabs.ai>

<img width="577" alt="image"
src="https://user-images.githubusercontent.com/314133/217108680-81070f25-58a0-4a29-ad75-4fbc5699bc89.png">

Summary: Adds a new chart type, 'StatChart', which just displays the
latest value of a single metric with units and label.

Relevant Issues: Fixes pixie-io#787

Type of change: /kind feature

Test Plan: Try this script with this vis spec.
```python
import px
import pxviews

ns_per_ms = 1000 * 1000
ns_per_s = 1000 * ns_per_ms
# Window size to use on time_ column for bucketing.
window_ns = px.DurationNanos(10 * ns_per_s)

def resource_timeseries(start_time: str, node: px.Node):
    ''' Gets the windowed process stats (CPU, memory, etc) for the input node.

    Args:
    @start_time Starting time of the data to examine.
    @node: The full name of the node to filter on.
    '''
    df = pxviews.container_process_timeseries(start_time, px.now(), window_ns)
    df = df[df.ctx['node'] == node]
    df['node'] = df.ctx['node']

    df = df.groupby(['time_', 'node']).agg(
        cpu_usage=('cpu_usage', px.sum),
        actual_disk_read_throughput=('actual_disk_read_throughput', px.sum),
        actual_disk_write_throughput=('actual_disk_write_throughput', px.sum),
        total_disk_read_throughput=('total_disk_read_throughput', px.sum),
        total_disk_write_throughput=('total_disk_write_throughput', px.sum),
        rss=('rss', px.sum),
        vsize=('vsize', px.sum),
    )

    df.groupby_col = df['node']
    return df
```
```json
{
  "variables": [
      {
          "name": "start_time",
          "type": "PX_STRING",
          "description": "The relative start time of the window. Current time is assumed to be now",
          "defaultValue": "-5m"
      },
      {
          "name": "node",
          "type": "PX_NODE",
          "description": "The node name to filter on"
      }
  ],
  "globalFuncs": [
      {
          "outputName": "resource_timeseries",
          "func": {
              "name": "resource_timeseries",
              "args": [
                  {
                      "name": "start_time",
                      "variable": "start_time"
                  },
                  {
                      "name": "node",
                      "variable": "node"
                  }
              ]
          }
      }
  ],
  "widgets": [
      {
          "name": "CPU Stat",
          "position": {
              "x": 0,
              "y": 0,
              "w": 1,
              "h": 1
          },
          "globalFuncOutputName": "resource_timeseries",
          "displaySpec": {
              "@type": "types.px.dev/px.vispb.StatChart",
              "title": "CPU Usage",
              "stat": {
                  "value": "cpu_usage"
              }
          }
      },
      {
        "name": "Bytes Read Stat",
        "position": {
            "x": 2,
            "y": 0,
            "w": 2,
            "h": 2
        },
        "globalFuncOutputName": "resource_timeseries",
        "displaySpec": {
            "@type": "types.px.dev/px.vispb.StatChart",
            "title": "Bytes Read",
            "stat": {
                "value": "total_disk_read_throughput"
            }
        }
    }
  ]
}
```

Changelog Message:
```release-note
New chart type: Stat. Shows a label, metric, and units for that metric.
```

---------

Signed-off-by: Nick Lanam <nlanam@pixielabs.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Stat Chart Type to UI
3 participants