📄 get_io.c
字号:
#include "public.h"
//#include "monitor.h"
//#include "msgqueue.h"
#include "sysmoni.h"
#include "standdb.h"
/************************************************************/
/* 文件名 : get_io.c */
/* 描述 : 使用unix命令形成有关数据的文本文件 */
/* 分析该文件,将超出警戒的数据报警写入消息队列
如果消息队列满则写入异常文件 */
/* 编写人 : genius.xuyong */
/* 创建日期: 19 Aug. 2002 */
/* 修改 : 22 Oct. 2002 */
/************************************************************/
extern long gl_qmsgsend; /*msgqueue code,extern from main*/
int get_io( char *acz_device,
char *acz_machine_code,
char *acz_module_code,
char *acz_object_code,
char *acz_create_time)
{
FILE *lh_file;
char lcz_buf[LEN];
int i;
system("sar -d >out/io.dat"); /*command get resourinfo*/
lh_file = fopen("out/io.dat","r"); /*open a resource info file*/
if (NULL == lh_file )
{
printf("open file resource error!\n");
fclose( lh_file );
return ( -1 );
}
memset(lcz_buf,0x00,LEN); /*set lcz_buf string is null*/
i=0;
while (NULL != fgets(lcz_buf,sizeof(lcz_buf),lh_file))
/*read a line from file,if is eof then break the while cycle*/
{
/*if the line include char '0' then deal the line ,
*else continue the cycle*/
if (NULL==strstr(lcz_buf,"0"))
{
continue;
}
else
{
decompose_io(lcz_buf,acz_machine_code,acz_module_code,acz_object_code,acz_create_time);
/*deal data function,decompose a buf string
* to a cpu struct array*/
i++;
}
}
fclose( lh_file );
/* deal_cpu(&ls_cpu,acz_device,acz_unusualfile,acz_lckfile,acz_procname);/*send cpu msg */
/* deal_mem(&ls_cpu,acz_device,acz_unusualfile,acz_lckfile,acz_procname);/*send mem msg */
return ( 0 );
}
/************************************************/
/*FUNCTION : decompose_string */
/*DESCRIPTION: decompose a data string,change
*buf string to long type data, and send them to
*a cpu struct. the in_parameter are a string and
*a cpuinfo struct */
/*INCLUDE: */
/*AUTHOR: genius.xuyong */
/*CREATE DATE: 2002-08-08 */
/************************************************/
int decompose_io(char *acz_buf,CPUINFO *as_cpu,char* acz_machine_code,char* acz_module_code,char* acz_object_code,char * create_time,char* complete_time)
{
int i,j,k;
char lc_char;
char lcz_tmp[8][19];
char complete_time[20]="";
long ll_array[20];
long ll_pos;
char lc_state[11]; /*磁盘属性状态*/
char lc_code[11][10]; /*磁盘属性编码*/
char gcz_io[10][20]={"00:00:00","device","%busy","avque","r+w/s","blks/s","avwait","avserv"}; /*IO模块属性数组*/
memset(lcz_tmp,0x00,10);/*set the lcz_tmp is null*/
j=0; /*set the first position is lcz_tmp[0]*/
k=0; /*set the first position is ll_array[0]*/
for (i=0;;i++)/*this cycle is read a char from the buffer char*/
{
lc_char=acz_buf[i];/*put the buffer char to lc_char*/
if (lc_char=='\n')/*if the char is the end of the buffer*/
{
if (j>0) /*if counter j >0,mean lcz_tmp not null*/
{
lcz_tmp[k][j]='\0';
if (lc_state[k]=='1')
{
get_format_time(complete_time,sizeof(complete_time));
Write_MonitorInfo(lc_code[k], acz_object_code,lcz_tmp[k],create_time,complete_time);
}
}
break; /* the exit of the cycle*/
}
if (lc_char!=0x20) /*if the char is not null*/
{
lcz_tmp[k][j]=lc_char;
j++; /*the value of lc_char append to lcz_tmp */
}
else
{
if (j>0)
{
lcz_tmp[k][j]='\0';
memset(lc_state,0x00,strlen(lc_state));
memset(lc_code,0x00,10);
if (k==0)
{ memset(lc_state,0x00,strlen(lc_state));
memset(lc_code,0x00,10);
Read_Property(gcz_cpu,acz_module_code,lc_state,lc_code);
if ( Read_Object(lcz_tmp[k], acz_module_code,acz_object_code)==0)
break;
}
if (lc_state[k]=='1')
{
get_format_time(complete_time,sizeof(complete_time));
Write_MonitorInfo(lc_code[k], acz_object_code,lcz_tmp[k],create_time,complete_time);
}
k++;
}
memset(lcz_tmp,0x00,10);/*set lcz_tmp is null*/
j=0; /*set the first position is lcz_tmp[0]*/
}
}
return ( 0 );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -