/****************************************************************************** ** Nagios check_disk_io plugin ** ** License : GPL ** Author : Patricio M Dorantes Jamarne ** Version : 0.5 ** ** ** This program is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program. If not, see . ** ** Please visit also http://www.ibm.com/developerworks/wikis/display/WikiPtype/ryo ** Parts of the code within this plugin come from there. ** ** Thanks to: Konstantin Reichert; I didn't just based this plugin on his, I almost ** ripped off his work but with the KISS concept. ** ** Comments, complains or congrats, please write me via g+ ** ********************************************************************************/ #include #include #include #include perfstat_partition_total_t sto_lparstats; double percent_ent; void print_usage() { } void print_help() { } void check_lpar_util(int delta) { perfstat_partition_total_t lparstats; u_longlong_t entitled_purr, unused_purr; u_longlong_t delta_purr, delta_time_base; double phys_proc_consumed, entitlement; if (!perfstat_partition_total((perfstat_id_t*)NULL, &lparstats, sizeof(perfstat_partition_total_t), 1) ) exit(-1); if (delta == 0 ) // sto_lparstats = &lparstats; mmm era un apuntador.... pq no funciono? memcpy( &sto_lparstats, &lparstats, sizeof(perfstat_partition_total_t)); else { entitlement = (double)lparstats.entitled_proc_capacity / 100.0 ; delta_purr = ( lparstats.puser - sto_lparstats.puser + lparstats.psys - sto_lparstats.psys + lparstats.pidle - sto_lparstats.pidle + lparstats.pwait - sto_lparstats.pwait ); delta_time_base = lparstats.timebase_last - sto_lparstats.timebase_last; if (lparstats.type.b.shared_enabled) { entitled_purr = delta_time_base * entitlement; if (entitled_purr < delta_purr) entitled_purr = delta_purr; } phys_proc_consumed = (double)delta_purr / (double)delta_time_base; percent_ent = (double)((phys_proc_consumed / entitlement) * 100); } } int main(int argc, char* argv[]) { int arguments; int retval=3; float warn_th = 75; float crit_th = 90; double tmp; if ( warn_th > crit_th ) { printf("Error: warning threshold is greater than critical threshold"); } while ((arguments = getopt (argc, argv, ":w:c:h")) != -1) { switch (arguments) { case 'w': warn_th = atoi(optarg); break; case 'c': crit_th = atoi(optarg); break; case 'h': print_help(); break; case ':': fprintf (stderr, "Error: Option -%c requires an argument.\n", optopt); exit(2); break; case '?': fprintf (stderr, "Error: Unknown -%c argument.\n", optopt); exit(2); break; default: abort(); } } check_lpar_util(0); sleep(1); check_lpar_util(1); if (percent_ent >= crit_th ) { retval = 2; printf("AIXCPU CRITICAL - CPU usage is at %f |cpuusage=%f;%f;%f \n",percent_ent,percent_ent,warn_th,crit_th); } else if (percent_ent >= warn_th ) { retval = 1; printf("AIXCPU WARNING - CPU usage is at %f |cpuusage=%f;%f;%f \n",percent_ent,percent_ent,warn_th,crit_th); } else { retval = 0; printf("AIXCPU OK - CPU usage is at %f |cpuusage=%f;%f;%f \n",percent_ent,percent_ent,warn_th,crit_th); } return retval; }