460 |
* FALSE is returned. |
* FALSE is returned. |
461 |
*/ |
*/ |
462 |
int check_system(Service_T s) { |
int check_system(Service_T s) { |
463 |
|
|
464 |
|
Resource_T r= NULL; |
465 |
|
|
466 |
|
ASSERT(s); |
467 |
|
|
468 |
|
for(r= s->resourcelist; r; r= r->next) { |
469 |
|
check_process_resources(s, r); |
470 |
|
} |
471 |
|
|
472 |
return TRUE; |
return TRUE; |
473 |
} |
} |
474 |
|
|
621 |
/** |
/** |
622 |
* Check process resources |
* Check process resources |
623 |
*/ |
*/ |
624 |
static void check_process_resources(Service_T s, Resource_T pr) { |
static void check_process_resources(Service_T s, Resource_T r) { |
625 |
|
|
626 |
int okay= TRUE; |
int okay= TRUE; |
627 |
char report[STRLEN]={0}; |
char report[STRLEN]={0}; |
628 |
|
|
629 |
ASSERT(s && pr); |
ASSERT(s && r); |
630 |
|
|
631 |
|
switch(r->resource_id) { |
632 |
|
|
|
switch(pr->resource_id) { |
|
633 |
case RESOURCE_ID_CPU_PERCENT: |
case RESOURCE_ID_CPU_PERCENT: |
634 |
if(Util_evalQExpression(pr->operator, s->inf->cpu_percent, pr->limit)) { |
if(Util_evalQExpression(r->operator, s->inf->cpu_percent, r->limit)) { |
635 |
snprintf(report, STRLEN, |
snprintf(report, STRLEN, |
636 |
"'%s' cpu usage of %.1f%% matches resource limit [cpu usage%s%.1f%%]", |
"'%s' cpu usage of %.1f%% matches resource limit [cpu usage%s%.1f%%]", |
637 |
s->name, s->inf->cpu_percent/10.0, operatorshortnames[pr->operator], |
s->name, s->inf->cpu_percent/10.0, operatorshortnames[r->operator], |
638 |
pr->limit/10.0); |
r->limit/10.0); |
639 |
okay= FALSE; |
okay= FALSE; |
640 |
} else { |
} else { |
641 |
DEBUG("'%s' cpu usage check passed [current cpu usage=%.1f%%]\n", |
DEBUG("'%s' cpu usage check passed [current cpu usage=%.1f%%]\n", |
643 |
} |
} |
644 |
break; |
break; |
645 |
|
|
646 |
case RESOURCE_ID_MEM_PERCENT: |
case RESOURCE_ID_CPUUSER: |
647 |
if(Util_evalQExpression(pr->operator, s->inf->mem_percent, pr->limit)) { |
if(Util_evalQExpression(r->operator, systeminfo.total_cpu_user_percent, r->limit)) { |
648 |
snprintf(report, STRLEN, |
snprintf(report, STRLEN, |
649 |
"'%s' mem usage of %.1f%% matches resource limit [mem usage%s%.1f%%]", |
"'%s' cpu user usage of %.1f%% matches resource limit [cpu user usage%s%.1f%%]", |
650 |
s->name, s->inf->mem_percent/10.0, operatorshortnames[pr->operator], |
s->name, systeminfo.total_cpu_user_percent/10.0, operatorshortnames[r->operator], |
651 |
pr->limit/10.0); |
r->limit/10.0); |
652 |
okay= FALSE; |
okay= FALSE; |
653 |
} else { |
} else { |
654 |
DEBUG("'%s' mem usage check passed [current mem usage=%.1f%%]\n", |
DEBUG("'%s' cpu user usage check passed [current cpu user usage=%.1f%%]\n", |
655 |
s->name, s->inf->mem_percent/10.0); |
s->name, systeminfo.total_cpu_user_percent/10.0); |
656 |
} |
} |
657 |
break; |
break; |
658 |
|
|
659 |
case RESOURCE_ID_MEM_KBYTE: |
case RESOURCE_ID_CPUSYSTEM: |
660 |
if(Util_evalQExpression(pr->operator, s->inf->mem_kbyte, pr->limit)) { |
if(Util_evalQExpression(r->operator, systeminfo.total_cpu_syst_percent, r->limit)) { |
661 |
snprintf(report, STRLEN, |
snprintf(report, STRLEN, |
662 |
"'%s' mem amount of %ldkB matches resource limit [mem amount%s%ldkB]", |
"'%s' cpu system usage of %.1f%% matches resource limit [cpu system usage%s%.1f%%]", |
663 |
s->name, s->inf->mem_kbyte, operatorshortnames[pr->operator], pr->limit); |
s->name, systeminfo.total_cpu_syst_percent/10.0, operatorshortnames[r->operator], |
664 |
|
r->limit/10.0); |
665 |
okay= FALSE; |
okay= FALSE; |
666 |
} else { |
} else { |
667 |
DEBUG("'%s' mem amount check passed [current mem amount=%ldkB]\n", |
DEBUG("'%s' cpu system usage check passed [current cpu system usage=%.1f%%]\n", |
668 |
s->name, s->inf->mem_kbyte); |
s->name, systeminfo.total_cpu_syst_percent/10.0); |
669 |
|
} |
670 |
|
break; |
671 |
|
|
672 |
|
case RESOURCE_ID_CPUWAIT: |
673 |
|
if(Util_evalQExpression(r->operator, systeminfo.total_cpu_wait_percent, r->limit)) { |
674 |
|
snprintf(report, STRLEN, |
675 |
|
"'%s' cpu wait usage of %.1f%% matches resource limit [cpu wait usage%s%.1f%%]", |
676 |
|
s->name, systeminfo.total_cpu_wait_percent/10.0, operatorshortnames[r->operator], |
677 |
|
r->limit/10.0); |
678 |
|
okay= FALSE; |
679 |
|
} else { |
680 |
|
DEBUG("'%s' cpu wait usage check passed [current cpu wait usage=%.1f%%]\n", |
681 |
|
s->name, systeminfo.total_cpu_wait_percent/10.0); |
682 |
|
} |
683 |
|
break; |
684 |
|
|
685 |
|
case RESOURCE_ID_MEM_PERCENT: |
686 |
|
if(s->type == TYPE_SYSTEM) { |
687 |
|
if(Util_evalQExpression(r->operator, systeminfo.total_mem_percent, r->limit)) { |
688 |
|
snprintf(report, STRLEN, |
689 |
|
"'%s' mem usage of %.1f%% matches resource limit [mem usage%s%.1f%%]", |
690 |
|
s->name, systeminfo.total_mem_percent/10.0, operatorshortnames[r->operator], |
691 |
|
r->limit/10.0); |
692 |
|
okay= FALSE; |
693 |
|
} else { |
694 |
|
DEBUG("'%s' mem usage check passed [current mem usage=%.1f%%]\n", |
695 |
|
s->name, systeminfo.total_mem_percent/10.0); |
696 |
|
} |
697 |
|
} else { |
698 |
|
if(Util_evalQExpression(r->operator, s->inf->mem_percent, r->limit)) { |
699 |
|
snprintf(report, STRLEN, |
700 |
|
"'%s' mem usage of %.1f%% matches resource limit [mem usage%s%.1f%%]", |
701 |
|
s->name, s->inf->mem_percent/10.0, operatorshortnames[r->operator], |
702 |
|
r->limit/10.0); |
703 |
|
okay= FALSE; |
704 |
|
} else { |
705 |
|
DEBUG("'%s' mem usage check passed [current mem usage=%.1f%%]\n", |
706 |
|
s->name, s->inf->mem_percent/10.0); |
707 |
|
} |
708 |
|
} |
709 |
|
break; |
710 |
|
|
711 |
|
case RESOURCE_ID_MEM_KBYTE: |
712 |
|
if(s->type == TYPE_SYSTEM) { |
713 |
|
if(Util_evalQExpression(r->operator, systeminfo.total_mem_kbyte, r->limit)) { |
714 |
|
snprintf(report, STRLEN, |
715 |
|
"'%s' mem amount of %ldkB matches resource limit [mem amount%s%ldkB]", |
716 |
|
s->name, systeminfo.total_mem_kbyte, operatorshortnames[r->operator], r->limit); |
717 |
|
okay= FALSE; |
718 |
|
} else { |
719 |
|
DEBUG("'%s' mem amount check passed [current mem amount=%ldkB]\n", |
720 |
|
s->name, systeminfo.total_mem_kbyte); |
721 |
|
} |
722 |
|
} else { |
723 |
|
if(Util_evalQExpression(r->operator, s->inf->mem_kbyte, r->limit)) { |
724 |
|
snprintf(report, STRLEN, |
725 |
|
"'%s' mem amount of %ldkB matches resource limit [mem amount%s%ldkB]", |
726 |
|
s->name, s->inf->mem_kbyte, operatorshortnames[r->operator], r->limit); |
727 |
|
okay= FALSE; |
728 |
|
} else { |
729 |
|
DEBUG("'%s' mem amount check passed [current mem amount=%ldkB]\n", |
730 |
|
s->name, s->inf->mem_kbyte); |
731 |
|
} |
732 |
} |
} |
733 |
break; |
break; |
734 |
|
|
735 |
case RESOURCE_ID_LOAD1: |
case RESOURCE_ID_LOAD1: |
736 |
if(Util_evalQExpression(pr->operator, |
if(Util_evalQExpression(r->operator, |
737 |
(int)(systeminfo.loadavg[0]*10.0), pr->limit)) { |
(int)(systeminfo.loadavg[0]*10.0), r->limit)) { |
738 |
snprintf(report, STRLEN, |
snprintf(report, STRLEN, |
739 |
"'%s' loadavg(1min) of %.1f matches resource limit " |
"'%s' loadavg(1min) of %.1f matches resource limit " |
740 |
"[loadavg(1min)%s%.1f]", |
"[loadavg(1min)%s%.1f]", |
741 |
s->name, systeminfo.loadavg[0], operatorshortnames[pr->operator], |
s->name, systeminfo.loadavg[0], operatorshortnames[r->operator], |
742 |
pr->limit/10.0); |
r->limit/10.0); |
743 |
okay= FALSE; |
okay= FALSE; |
744 |
} else { |
} else { |
745 |
DEBUG("'%s' loadavg(1min) check passed [current loadavg(1min)=%.1f]\n", |
DEBUG("'%s' loadavg(1min) check passed [current loadavg(1min)=%.1f]\n", |
748 |
break; |
break; |
749 |
|
|
750 |
case RESOURCE_ID_LOAD5: |
case RESOURCE_ID_LOAD5: |
751 |
if(Util_evalQExpression(pr->operator, |
if(Util_evalQExpression(r->operator, |
752 |
(int)(systeminfo.loadavg[1]*10.0), pr->limit)) { |
(int)(systeminfo.loadavg[1]*10.0), r->limit)) { |
753 |
snprintf(report, STRLEN, |
snprintf(report, STRLEN, |
754 |
"'%s' loadavg(5min) of %.1f matches resource limit " |
"'%s' loadavg(5min) of %.1f matches resource limit " |
755 |
"[loadavg(5min)%s%.1f]", |
"[loadavg(5min)%s%.1f]", |
756 |
s->name, systeminfo.loadavg[1], operatorshortnames[pr->operator], |
s->name, systeminfo.loadavg[1], operatorshortnames[r->operator], |
757 |
pr->limit/10.0); |
r->limit/10.0); |
758 |
okay= FALSE; |
okay= FALSE; |
759 |
} else { |
} else { |
760 |
DEBUG("'%s' loadavg(5min) check passed [current loadavg(5min)=%.1f]\n", |
DEBUG("'%s' loadavg(5min) check passed [current loadavg(5min)=%.1f]\n", |
763 |
break; |
break; |
764 |
|
|
765 |
case RESOURCE_ID_LOAD15: |
case RESOURCE_ID_LOAD15: |
766 |
if(Util_evalQExpression(pr->operator, |
if(Util_evalQExpression(r->operator, |
767 |
(int)(systeminfo.loadavg[2]*10.0), pr->limit)) { |
(int)(systeminfo.loadavg[2]*10.0), r->limit)) { |
768 |
snprintf(report, STRLEN, |
snprintf(report, STRLEN, |
769 |
"'%s' loadavg(15min) of %.1f matches resource limit " |
"'%s' loadavg(15min) of %.1f matches resource limit " |
770 |
"[loadavg(15min)%s%.1f]", |
"[loadavg(15min)%s%.1f]", |
771 |
s->name, systeminfo.loadavg[2], operatorshortnames[pr->operator], |
s->name, systeminfo.loadavg[2], operatorshortnames[r->operator], |
772 |
pr->limit/10.0); |
r->limit/10.0); |
773 |
okay= FALSE; |
okay= FALSE; |
774 |
} else { |
} else { |
775 |
DEBUG("'%s' loadavg(15min) check passed [current loadavg(15min)=%.1f]\n", |
DEBUG("'%s' loadavg(15min) check passed [current loadavg(15min)=%.1f]\n", |
778 |
break; |
break; |
779 |
|
|
780 |
case RESOURCE_ID_CHILDREN: |
case RESOURCE_ID_CHILDREN: |
781 |
if(Util_evalQExpression(pr->operator, s->inf->children, pr->limit)) { |
if(Util_evalQExpression(r->operator, s->inf->children, r->limit)) { |
782 |
snprintf(report, STRLEN, |
snprintf(report, STRLEN, |
783 |
"'%s' children of %i matches resource limit [children%s%ld]", |
"'%s' children of %i matches resource limit [children%s%ld]", |
784 |
s->name, s->inf->children, operatorshortnames[pr->operator], pr->limit); |
s->name, s->inf->children, operatorshortnames[r->operator], r->limit); |
785 |
okay= FALSE; |
okay= FALSE; |
786 |
} else { |
} else { |
787 |
DEBUG("'%s' children check passed [current children=%i]\n", |
DEBUG("'%s' children check passed [current children=%i]\n", |
790 |
break; |
break; |
791 |
|
|
792 |
case RESOURCE_ID_TOTAL_MEM_KBYTE: |
case RESOURCE_ID_TOTAL_MEM_KBYTE: |
793 |
if(Util_evalQExpression(pr->operator, s->inf->total_mem_kbyte, pr->limit)) { |
if(Util_evalQExpression(r->operator, s->inf->total_mem_kbyte, r->limit)) { |
794 |
snprintf(report, STRLEN, |
snprintf(report, STRLEN, |
795 |
"'%s' total mem amount of %ldkB matches resource limit" |
"'%s' total mem amount of %ldkB matches resource limit" |
796 |
" [total mem amount%s%ldkB]", |
" [total mem amount%s%ldkB]", |
797 |
s->name, s->inf->total_mem_kbyte, operatorshortnames[pr->operator], |
s->name, s->inf->total_mem_kbyte, operatorshortnames[r->operator], |
798 |
pr->limit); |
r->limit); |
799 |
okay= FALSE; |
okay= FALSE; |
800 |
} else { |
} else { |
801 |
DEBUG("'%s' total mem amount check passed " |
DEBUG("'%s' total mem amount check passed " |
804 |
break; |
break; |
805 |
|
|
806 |
case RESOURCE_ID_TOTAL_MEM_PERCENT: |
case RESOURCE_ID_TOTAL_MEM_PERCENT: |
807 |
if(Util_evalQExpression(pr->operator, s->inf->total_mem_percent, pr->limit)) { |
if(Util_evalQExpression(r->operator, s->inf->total_mem_percent, r->limit)) { |
808 |
snprintf(report, STRLEN, |
snprintf(report, STRLEN, |
809 |
"'%s' total mem amount of %.1f%% matches resource limit" |
"'%s' total mem amount of %.1f%% matches resource limit" |
810 |
" [total mem amount%s%.1f%%]", |
" [total mem amount%s%.1f%%]", |
811 |
s->name, (float)s->inf->total_mem_percent/10.0, |
s->name, (float)s->inf->total_mem_percent/10.0, |
812 |
operatorshortnames[pr->operator], (float)pr->limit/10.0); |
operatorshortnames[r->operator], (float)r->limit/10.0); |
813 |
okay= FALSE; |
okay= FALSE; |
814 |
} else { |
} else { |
815 |
DEBUG("'%s' total mem amount check passed " |
DEBUG("'%s' total mem amount check passed " |
819 |
break; |
break; |
820 |
|
|
821 |
default: |
default: |
822 |
log("'%s' error -- unknown resource ID: [%d]\n", s->name, pr->resource_id); |
log("'%s' error -- unknown resource ID: [%d]\n", s->name, r->resource_id); |
823 |
return; |
return; |
824 |
} |
} |
825 |
|
|
826 |
if(! okay) { |
if(! okay) { |
827 |
Event_post(s, EVENT_RESOURCE, STATE_FAILED, pr->action, report); |
Event_post(s, EVENT_RESOURCE, STATE_FAILED, r->action, "%s", report); |
828 |
} else { |
} else { |
829 |
Event_post(s, EVENT_RESOURCE, STATE_PASSED, pr->action, |
Event_post(s, EVENT_RESOURCE, STATE_PASSED, r->action, |
830 |
"'%s' resource passed", s->name); |
"'%s' resource passed", s->name); |
831 |
} |
} |
832 |
|
|