Ad Widget

Collapse

Statistics with python pandas

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • LenR
    Senior Member
    • Sep 2009
    • 1005

    #1

    Statistics with python pandas

    I'm not sure how useful this might be, but I was playing around after someone asked what would happen across the board if our CPU usage increased by 25%. The math isn't the point, the use of pandas is.

    I use the pyzabbix api, so added the standard includes

    import pandas as pd
    import numpy as np

    Then for each host in a prior selected host group:

    - find the CPU Busy item (if it exists
    - get a weeks trends
    - The data returned by the API can be loaded directly into a pandas dataframe :-O
    - calculate the avg, max and standard deviation
    - calculate a worse case, where the max plus the std-dev increase by 25%
    - then lest hosts that are currently running over 50% CPU Busy with the calculated scare values

    for host in hosts:
    cpu_item = zapi.item.get(hostids=host['hostid'],search={'name': 'CPU Busy'})
    if len(cpu_item) == 0:
    # print("No item for", host['name'])
    continue
    cpu_trend = zapi.trend.get(itemids=cpu_item[0]['itemid'],limit=168,output=["clock", "value_avg", "value_max"])
    if len(cpu_trend) == 0:
    # print("No trend for", host['name'])
    continue
    df = pd.DataFrame(cpu_trend)
    cpu_avg_max = df['value_max'].astype(float).mean()
    cpu_max_avg = df['value_avg'].astype(float).max()
    cpu_avg_std = df['value_avg'].astype(float).std()
    cpu_up_var = (cpu_max_avg + cpu_avg_std) * 1.25

    if cpu_avg_max > 50:
    print(host['name']+','+str(cpu_max_avg)+','+str(cpu_avg_max)+','+str (cpu_avg_std)+','+str(cpu_up_var))




  • LenR
    Senior Member
    • Sep 2009
    • 1005

    #2
    Another example, using the same data, but list hosts that had more than 5 hours above 80% CPU busy for the past week:
    '
    df = pd.DataFrame(cpu_trend)
    cpu_avg_max = df['value_max'].astype(float).mean()
    freq = df['clock'][df['value_max'].astype(float) > 80].count()
    if freq > 5:
    print(host['name']+','+str(freq)+','+str(cpu_avg_max))


    Comment

    Working...