#
# CPUperf monitor

test CPUperf_load {
    # sub classe must set this: static set name "load";
    static set idlevar noneset;
   
    static set description "Monitors CPU load";
    static set label "Total CPU";

    static set arguments
	"idle_yellow:int:Minimum % the CPU must be idle unless yellow status is reported (default: 15)",
	"idle_red:int:Minimum % the CPU must be idle unless red status is reported (default: 10)",
	"item:string:column name we should report the results under (default: cpu)"
	"perf:int:time in minutes between sending performance data (0 for no performance data)";

    init {
        instance import idle_yellow;
	instance import idle_red;
	instance set idle_yellow if( ${idle_yellow}, ${idle_yellow}, 15 );
	instance set idle_red if( ${idle_red}, ${idle_red}, 10 );
	instance import item report_item;
	instance set report_item if( ${report_item}, ${report_item}, "cpu" );
	instance set id 1;
	instance import perf perf_frequency;
	instance set firstpass 1;
    }

    discover {
    }

    monitor {
        debug 6 get ${idlevar};
        get ${idlevar};
        debug 6 got ${idlevar} = ${${idlevar}};
	instance set idle ${${idlevar}};
    }

    report {
	status clear null( ${idle} ) && ${firstpass} "&clear status not known (yet)";
	status purple null( ${idle} ) && not( ${firstpass} ) "&purple CPU test failing";
        status red ( ${idle} < ${idle_red} ) && not( null( ${idle} ) )  "&red " " only " ${idle} "% idle!" ;
        status yellow ( ${idle} < ${idle_yellow} ) && not( null( ${idle} ) )  "&yellow " " only " ${idle} "% idle" ;
        status green not( null( ${idle} ) ) "&green " ${idle} "% idle";
	instance set firstpass 0;
    }

    perf {
        export always cpu.%idle, ${idle};
	export always cpu.label, ${label};
    }
}
        
