重命名: trunk/src/README -> ../README 删除: ../branches/sys_nicmonitor-1.4-龙芯-32/Makefile 删除: ../branches/sys_nicmonitor-1.4-龙芯-32/Makefile.config 删除: ../branches/sys_nicmonitor-1.4-龙芯-32/const.h 删除: ../branches/sys_nicmonitor-1.4-龙芯-32/dotconf.h 删除: ../branches/sys_nicmonitor-1.4-龙芯-32/mnic.c 删除: ../branches/sys_nicmonitor-1.4-龙芯-32/mnic.h 删除: ../branches/sys_nicmonitor-1.4-龙芯-32/nicinfo_shm.c 删除: ../branches/sys_nicmonitor-1.4-龙芯-32/nicinfo_shm.h 删除: ../branches/sys_nicmonitor-1.4-龙芯-32/proc_inv.h 删除: ../branches/sys_nicmonitor-1.4-龙芯-32/read_netcard.c 删除: ../branches/sys_nicmonitor-1.4-龙芯-32/send_alarm.c 删除: ../branches/sys_nicmonitor-1.4-龙芯-32/sys_netcard.h 删除: ../branches/sys_nicmonitor-1.4-龙芯-32/sys_nicmonitor 删除: ../branches/sys_nicmonitor-1.5/Makefile 删除: ../branches/sys_nicmonitor-1.5/Makefile.config 删除: ../branches/sys_nicmonitor-1.5/README1.5 删除: ../branches/sys_nicmonitor-1.5/const.h 删除: ../branches/sys_nicmonitor-1.5/mnic.c 删除: ../branches/sys_nicmonitor-1.5/mnic.h 删除: ../branches/sys_nicmonitor-1.5/nicinfo_shm.c 删除: ../branches/sys_nicmonitor-1.5/nicinfo_shm.h 删除: ../branches/sys_nicmonitor-1.5/proc_inv.h 删除: ../branches/sys_nicmonitor-1.5/read_netcard.c 删除: ../branches/sys_nicmonitor-1.5/send_alarm.c 删除: ../branches/sys_nicmonitor-1.5/sys_netcard.h 删除: ../branches/sys_nicmonitor-1.5/sys_nicmonitor 删除: ../branches/sys_nicmonitor-1.6/Makefile 删除: ../branches/sys_nicmonitor-1.6/Makefile.config 删除: ../branches/sys_nicmonitor-1.6/README1.5 删除: ../branches/sys_nicmonitor-1.6/README1.6 删除: ../branches/sys_nicmonitor-1.6/const.h 删除: ../branches/sys_nicmonitor-1.6/mnic.c 删除: ../branches/sys_nicmonitor-1.6/mnic.h 删除: ../branches/sys_nicmonitor-1.6/nicinfo_shm.c 删除: ../branches/sys_nicmonitor-1.6/nicinfo_shm.h 删除: ../branches/sys_nicmonitor-1.6/proc_inv.h 删除: ../branches/sys_nicmonitor-1.6/read_netcard.c 删除: ../branches/sys_nicmonitor-1.6/send_alarm.c 删除: ../branches/sys_nicmonitor-1.6/sys_netcard.h 删除: ../branches/sys_nicmonitor-1.6/sys_nicmonitor 重命名: trunk/sys_nicmonitor/src/Pkgfile -> Pkgfile 重命名: trunk/sys_nicmonitor/src/sys_nicmonitor/README -> README 删除: branches/sys_nicmonitor-1.0/Makefile 删除: branches/sys_nicmonitor-1.0/Makefile.config 删除: branches/sys_nicmonitor-1.0/const.h 删除: branches/sys_nicmonitor-1.0/mnic.c 删除: branches/sys_nicmonitor-1.0/mnic.h 删除: branches/sys_nicmonitor-1.0/nicinfo_shm.c 删除: branches/sys_nicmonitor-1.0/nicinfo_shm.h 删除: branches/sys_nicmonitor-1.0/proc_inv.h 删除: branches/sys_nicmonitor-1.0/read_netcard.c 删除: branches/sys_nicmonitor-1.0/send_alarm.c 删除: branches/sys_nicmonitor-1.0/sys_netcard.h 重命名: trunk/sys_nicmonitor/src/build.sh -> build.sh 重命名: trunk/sys_nicmonitor/src/dep/dotconf#1.0.13-1.pkg.tar.gz -> dep/dotconf#1.0.13-1.pkg.tar.gz 重命名: trunk/sys_nicmonitor/src/dep/libman.so -> dep/libman.so 重命名: trunk/sys_nicmonitor/src/dep/run.sh -> dep/run.sh 重命名: trunk/sys_nicmonitor/src/post_add.sh -> post_add.sh 重命名: trunk/sys_nicmonitor/src/post_mk.sh -> post_mk.sh 重命名: trunk/sys_nicmonitor/src/sys_nicmonitor/Makefile -> sys_nicmonitor/Makefile 重命名: trunk/sys_nicmonitor/src/sys_nicmonitor/Makefile.config -> sys_nicmonitor/Makefile.config 重命名: trunk/sys_nicmonitor/src/README -> sys_nicmonitor/README 重命名: trunk/sys_nicmonitor/src/sys_nicmonitor/common.c -> sys_nicmonitor/common.c 重命名: trunk/sys_nicmonitor/src/sys_nicmonitor/const.h -> sys_nicmonitor/const.h 重命名: trunk/sys_nicmonitor/src/sys_nicmonitor/mnic.c -> sys_nicmonitor/mnic.c 重命名: trunk/sys_nicmonitor/src/sys_nicmonitor/mnic.h -> sys_nicmonitor/mnic.h 重命名: trunk/sys_nicmonitor/src/sys_nicmonitor/nicinfo_shm.c -> sys_nicmonitor/nicinfo_shm.c 重命名: trunk/sys_nicmonitor/src/sys_nicmonitor/nicinfo_shm.h -> sys_nicmonitor/nicinfo_shm.h 重命名: trunk/sys_nicmonitor/src/sys_nicmonitor/proc_inv.h -> sys_nicmonitor/proc_inv.h 重命名: trunk/sys_nicmonitor/src/sys_nicmonitor/read_netcard.c -> sys_nicmonitor/read_netcard.c 重命名: trunk/sys_nicmonitor/src/sys_nicmonitor/send_alarm.c -> sys_nicmonitor/send_alarm.c 重命名: trunk/sys_nicmonitor/src/sys_nicmonitor/sys_netcard.h -> sys_nicmonitor/sys_netcard.h 重命名: trunk/sys_nicmonitor/src/sys_nicmonitor/test.c -> sys_nicmonitor/test.c 重命名: trunk/sys_nicmonitor/src/sys_nicmonitor/testread.c -> sys_nicmonitor/testread.c 重命名: trunk/sys_nicmonitor/src/sys_nicmonitor/version.h -> sys_nicmonitor/version.h 删除: tags/README1.5 删除: tags/README1.6 删除: tags/README1.7 删除: tags/libman.so 删除: tags/sys_nicmonitor-1.0.0/Makefile 删除: tags/sys_nicmonitor-1.0.0/Makefile.config 删除: tags/sys_nicmonitor-1.0.0/const.h 删除: tags/sys_nicmonitor-1.0.0/mnic.c 删除: tags/sys_nicmonitor-1.0.0/mnic.h 删除: tags/sys_nicmonitor-1.0.0/nicinfo_shm.c 删除: tags/sys_nicmonitor-1.0.0/nicinfo_shm.h 删除: tags/sys_nicmonitor-1.0.0/proc_inv.h 删除: tags/sys_nicmonitor-1.0.0/read_netcard.c 删除: tags/sys_nicmonitor-1.0.0/send_alarm.c 删除: tags/sys_nicmonitor-1.0.0/sys_netcard.h 删除: tags/sys_nicmonitor-1.5/Makefile 删除: tags/sys_nicmonitor-1.5/Makefile.config 删除: tags/sys_nicmonitor-1.5/const.h 删除: tags/sys_nicmonitor-1.5/mnic.c 删除: tags/sys_nicmonitor-1.5/mnic.h 删除: tags/sys_nicmonitor-1.5/nicinfo_shm.c 删除: tags/sys_nicmonitor-1.5/nicinfo_shm.h 删除: tags/sys_nicmonitor-1.5/proc_inv.h 删除: tags/sys_nicmonitor-1.5/read_netcard.c 删除: tags/sys_nicmonitor-1.5/send_alarm.c 删除: tags/sys_nicmonitor-1.5/sys_netcard.h 删除: tags/sys_nicmonitor-1.6/Makefile 删除: tags/sys_nicmonitor-1.6/Makefile.config 删除: tags/sys_nicmonitor-1.6/const.h 删除: tags/sys_nicmonitor-1.6/mnic.c 删除: tags/sys_nicmonitor-1.6/mnic.h 删除: tags/sys_nicmonitor-1.6/nicinfo_shm.c 删除: tags/sys_nicmonitor-1.6/nicinfo_shm.h 删除: tags/sys_nicmonitor-1.6/proc_inv.h 删除: tags/sys_nicmonitor-1.6/read_netcard.c 删除: tags/sys_nicmonitor-1.6/send_alarm.c 删除: tags/sys_nicmonitor-1.6/sys_netcard.h 删除: tags/sys_nicmonitor-1.7/Makefile 删除: tags/sys_nicmonitor-1.7/Makefile.config 删除: tags/sys_nicmonitor-1.7/const.h 删除: tags/sys_nicmonitor-1.7/mnic.c 删除: tags/sys_nicmonitor-1.7/mnic.h 删除: tags/sys_nicmonitor-1.7/nicinfo_shm.c 删除: tags/sys_nicmonitor-1.7/nicinfo_shm.h 删除: tags/sys_nicmonitor-1.7/proc_inv.h 删除: tags/sys_nicmonitor-1.7/read_netcard.c 删除: tags/sys_nicmonitor-1.7/send_alarm.c 删除: tags/sys_nicmonitor-1.7/sys_netcard.h 删除: tags/sys_nicmonitor-1.8/bin/README 删除: tags/sys_nicmonitor-1.8/bin/install.sh 删除: tags/sys_nicmonitor-1.8/bin/sys_nicmonitor#1.8-x86_64-Linx-Rocky4.2.pkg.tar.gz 删除: tags/sys_nicmonitor-1.8/doc/网卡监视程序动态库使用手册【新】.doc 删除: tags/sys_nicmonitor-1.8/doc/网卡监视程序安装说明以及使用手册【新】.doc 删除: tags/sys_nicmonitor-1.8/src/Pkgfile 删除: tags/sys_nicmonitor-1.8/src/README1.8 删除: tags/sys_nicmonitor-1.8/src/V1.8 删除: tags/sys_nicmonitor-1.8/src/build.sh 删除: tags/sys_nicmonitor-1.8/src/post_add.sh 删除: tags/sys_nicmonitor-1.8/src/post_mk.sh 删除: tags/sys_nicmonitor-1.8/src/sys_nicmonitor-1.8.tar.gz 删除: tags/sys_nicmonitor-1.8/test/Makefile 删除: tags/sys_nicmonitor-1.8/test/dotconf.h 删除: tags/sys_nicmonitor-1.8/test/getmem 删除: tags/sys_nicmonitor-1.8/test/getmem.c 删除: tags/sys_nicmonitor-1.8/test/mnic.h 删除: tags/sys_nicmonitor-1.8/test/nicinfo_shm.h 删除: tags/sys_nicmonitor-1.8/test/read_shm 删除: tags/sys_nicmonitor-1.8/test/read_shm.c 删除: tags/sys_nicmonitor-1.8/test/recv_msg 删除: tags/sys_nicmonitor-1.8/test/recv_msg.c 删除: tags/sys_nicmonitor-1.8/test/sys_netcard.h 重命名: trunk/test/Makefile -> test/Makefile 重命名: trunk/test/dotconf.h -> test/dotconf.h 重命名: trunk/test/getmem.c -> test/getmem.c 重命名: trunk/test/mnic.h -> test/mnic.h 重命名: trunk/test/nicinfo_shm.h -> test/nicinfo_shm.h 重命名: trunk/test/read_shm.c -> test/read_shm.c 重命名: trunk/test/recv_msg.c -> test/recv_msg.c 重命名: trunk/test/sys_netcard.h -> test/sys_netcard.h 删除: trunk/LATEST 删除: trunk/README 删除: trunk/bin/README 删除: trunk/bin/install.sh 删除: trunk/bin/sys_nicmonitor#1.8.1-x86_64-Linx-Rocky4.2.pkg.tar.gz 删除: trunk/doc/网卡监视程序动态库使用手册【新】.doc 删除: trunk/doc/网卡监视程序安装说明以及使用手册【新】.doc 删除: trunk/src/Pkgfile 删除: trunk/src/build.sh 删除: trunk/src/post_add.sh 删除: trunk/src/post_mk.sh 删除: trunk/src/sys_nicmonitor-1.8.tar.gz 删除: trunk/src/sys_nicmonitor-1.9.tar.gz 删除: trunk/sys_nicmonitor/README.md 删除: trunk/sys_nicmonitor/sys_nicmonitor-from-svn.tar.bz2 Signed-off-by: Zhang, Guodong <gdzhang@linx-info.com>
182 lines
4.1 KiB
C
182 lines
4.1 KiB
C
#include <stdio.h>
|
||
#include <stdlib.h>
|
||
#include <string.h>
|
||
#include <unistd.h>
|
||
#include <ctype.h>
|
||
|
||
|
||
#include "sys_netcard.h"
|
||
#define IPSIZE 16
|
||
#define THRNR 10
|
||
#define DAYS 25
|
||
#define LINE_SIZE 2048
|
||
#define HOST_NAME_SIZE 40
|
||
#define BOND_PATH "/proc/net/bonding/*"
|
||
#define LOG_PATH "/var/log/netcard/"
|
||
#define SHM_PATH "/share/sys_netcard_shm_path"
|
||
#define SEM_PATH "/share/sys_netcard_sem_path"
|
||
#define MAX_GW 32
|
||
#define DEV_MAXLEN 32
|
||
#define IPLEN 16
|
||
#define CONF_FILE "/conf/nic/sys_netcard_conf.txt"
|
||
|
||
//#define MNIC_VERSION "1.9"
|
||
|
||
#define NIC_UNKNOWN 0
|
||
#define NIC_DOWN 1
|
||
#define NIC_UNRUNNING 2
|
||
#define NIC_UNLINKABLE 3
|
||
#define NIC_NORMAL 4
|
||
|
||
//网卡设备描述结构
|
||
typedef struct __nic_dev{
|
||
char dev_name[DEV_MAXLEN]; //网卡名称
|
||
char ping_ip[MAX_GW][IPLEN]; //ping地址列表,最多32个
|
||
int gw_num; //地址列表的长度
|
||
}NIC_DEV;
|
||
|
||
typedef struct __config_file_st{
|
||
unsigned char domain;
|
||
short serv;
|
||
short event;
|
||
int udpport;
|
||
int monitor_interval;
|
||
int write_interval;
|
||
int flow_interval;
|
||
int flow_limit;
|
||
int flow_peak;
|
||
char udp[NIC_NAME_LEN];
|
||
NIC_DEV nic[MAXNICNUM]; //被监视网卡的列表
|
||
char ip[IPSIZE];
|
||
int pingnum; //OPTIONAL!! How many times for once ping check? Default is 2.
|
||
int pinglap; //OPTIONAL!! How many seconds does ping wait for reply package? Default is 1.
|
||
int crazyping;
|
||
}CONFIG_FILE_ST;
|
||
|
||
typedef struct inc_name_node{
|
||
char name[NIC_NAME_LEN];
|
||
struct inc_name_node *next;
|
||
}NET_NAME_ST;
|
||
|
||
typedef struct inc_info_node{
|
||
NETCARD_INFO info;
|
||
int status;
|
||
struct inc_info_node *next;
|
||
}NETCARD_INFO_ST;
|
||
|
||
typedef struct net_info{
|
||
NETCARD_INFO info[MAXNICNUM];
|
||
}SHM;
|
||
|
||
typedef struct __thread_env_st{
|
||
D5000_NIC_ALARM Malarm;
|
||
char bond_file_path[64];
|
||
char host_name[HOST_NAME_SIZE];
|
||
int host_name_size;
|
||
CONFIG_FILE_ST *conf;
|
||
}THENV;
|
||
|
||
typedef struct __thread_mem_st{
|
||
int semid;
|
||
SHM *shm_ptr;
|
||
NETCARD_INFO_ST *listp;
|
||
CONFIG_FILE_ST *conf;
|
||
}THMEM;
|
||
|
||
typedef struct __thread_flow_st{
|
||
THENV env;
|
||
THMEM mem;
|
||
}THFLOW;
|
||
|
||
int sys_nic_debug = 1;
|
||
static void get_inc_stats(NETCARD_INFO *net);
|
||
int get_dev_fields(char *str, NETCARD_INFO *ife);
|
||
static char *prase_digit(char **s);
|
||
static void get_inc_stats(NETCARD_INFO *net)
|
||
{
|
||
char linebuf[LINE_SIZE];
|
||
char *retp = NULL;
|
||
char *str = NULL;
|
||
FILE *dev_fp;
|
||
|
||
if((dev_fp = fopen("/proc/net/dev", "r")) == NULL)return;
|
||
memset(linebuf, 0, sizeof(linebuf));
|
||
|
||
|
||
while((retp = fgets(linebuf, sizeof(linebuf), dev_fp)) != NULL){
|
||
// printf("linebuf: %s charname: %s\n", linebuf,net->charname);
|
||
if((str = strstr(linebuf, net->charname)) != NULL){
|
||
str +=strlen(net->charname) + 2;
|
||
get_dev_fields(str, net);
|
||
break;
|
||
}
|
||
}
|
||
fclose(dev_fp);
|
||
}
|
||
static char *prase_digit(char **s)
|
||
{
|
||
char *retp = NULL;
|
||
char *p = *s;
|
||
|
||
if(!p)return NULL;
|
||
while(!isdigit(*p)){
|
||
p++;
|
||
if(*p == '\0')return NULL;
|
||
}
|
||
retp = p;
|
||
while(isdigit(*p)){
|
||
p++;
|
||
if(*p == '\0'){
|
||
*s = NULL;
|
||
return retp;
|
||
}
|
||
}
|
||
*p = '\0';
|
||
p++;
|
||
*s = p;
|
||
return retp;
|
||
}
|
||
|
||
|
||
int get_dev_fields(char *str, NETCARD_INFO *ife)
|
||
{
|
||
if( getenv("SYS_NIC_DEBUG") ) {
|
||
sys_nic_debug = 1;
|
||
}
|
||
|
||
fprintf(stdout, "str:%s\n",str);
|
||
int i = 0;
|
||
char *retp[16];
|
||
while((retp[i] = prase_digit(&str)) != NULL){i++;if(i > 15)break;}
|
||
ife->rx_bytes = atoll(retp[0]);
|
||
ife->rx_packets = atoll(retp[1]);
|
||
ife->rx_errors = atol(retp[2]);
|
||
ife->rx_dropped = atol(retp[3]);
|
||
ife->rx_fifo_errors = atol(retp[4]);
|
||
ife->rx_multicast = atol(retp[7]);
|
||
ife->tx_bytes = atoll(retp[8]);
|
||
ife->tx_packets = atoll(retp[9]);
|
||
ife->tx_errors = atol(retp[10]);
|
||
ife->tx_dropped = atol(retp[11]);
|
||
ife->tx_fifo_errors = atol(retp[12]);
|
||
ife->collisions = atol(retp[13]);
|
||
ife->tx_carrier_errors = atol(retp[14]);
|
||
if( sys_nic_debug ) {
|
||
fprintf(stdout, "ife->rx_bytes:\t%lld\tife->tx_bytes:\t%lld\n",ife->rx_bytes,ife->tx_bytes);
|
||
}
|
||
return 0;
|
||
}
|
||
int main (int argc, char *argv[]){
|
||
THMEM mem;
|
||
NETCARD_INFO_ST *curr;
|
||
NETCARD_INFO net;
|
||
|
||
sprintf(net.charname,"%s","bond0");
|
||
while (1){
|
||
get_inc_stats(&net);
|
||
printf("ifname:%s, tx:%llu rx:%llu\n",net.charname, net.tx_bytes, net.rx_bytes);
|
||
// flush(NULL);
|
||
sleep(1);
|
||
}
|
||
}
|