Commit af67f5e9 authored by 's avatar
Browse files

Initial graphing, abw_const.cfg, bug fixes


git-svn-id: file:///home/svn/mapi/trunk@449 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent 46999478
......@@ -41,4 +41,6 @@ install: all
mkdir -p /var/lib/rrd
cp abw /usr/local/bin
cp abw_restart.sh /usr/local/bin
cp rrd_create.sh /usr/local/bin
cp -u abw.cfg /etc
cp -u abw_const.cfg /etc
......@@ -400,13 +400,14 @@ int main(int argc, char *argv[])
p=*pp;
if (!global_spec.no_stdout)
printf("%d %u.%u\n", i, (unsigned int)(tm.tv_sec),
printf("%d %u.%u\n", p->id, (unsigned int)(tm.tv_sec),
(unsigned int)(tm.tv_usec));
j=0;
while (j<MAX_PROTOCOLS && (q=p->flow_run[j])) {
printf("%s:", q->protocol);
if (!global_spec.no_stdout && !global_spec.stdout_simple)
printf(" %s:", q->protocol);
if ((q->pkt_counter_res=(struct dmapi_results*)
mapi_read_results(q->fd, q->pkt_counter_fid))==NULL) {
......@@ -441,8 +442,12 @@ int main(int argc, char *argv[])
p->parameters->interval.tv_usec * 0.000001;
if (!global_spec.no_stdout) {
printf(" %0.2f packets/s %0.2f bytes/s %0.2f Mb/s\n", packets/seconds,
bytes/seconds, mbps2/seconds);
if (!global_spec.stdout_simple)
printf(" %0.2f %0.2f %0.2f", packets/seconds,
bytes/seconds, mbps2/seconds);
else
printf(" %0.2f packets/s %0.2f bytes/s %0.2f Mb/s\n",
packets/seconds, bytes/seconds, mbps2/seconds);
}
/* If interval is at least 1 second, then store results
......@@ -451,7 +456,7 @@ int main(int argc, char *argv[])
if (p->parameters->interval.tv_sec) {
sprintf(command, "rrdtool update %s %u:%llu:%llu:%u",
q->rrd_filename, (unsigned int)(tm.tv_sec),
packets, bytes, (unsigned int)round(mbps));
packets, bytes, (unsigned int)round(mbps2));
if (debug)
printf("%s: system(%s)\n", __func__, command);
......@@ -498,7 +503,7 @@ int main(int argc, char *argv[])
} /* while (j<MAX_PROTOCOLS && (q=p->flow_run[j])) */
if (!global_spec.no_stdout)
if (!global_spec.no_stdout && global_spec.stdout_simple)
printf("\n");
pp++;
......@@ -506,6 +511,9 @@ int main(int argc, char *argv[])
} /* while (i<MAX_FLOWS && *pp) */
if (!global_spec.no_stdout)
printf("\n");
/* TODO: wait until next checkpoint (not a fixed delay) of
the flow whose checkpoint is earliest */
......
......@@ -84,8 +84,9 @@ typedef struct {
* flows, one for each protocol to be monitored.
*/
typedef struct {
int subject_id; /* id field in tSubject table */
int parameters_id; /* id field in tParameters table */
int id; /* used as flow number when printing results */
int subject_id; /* id field in tSubject table */
int parameters_id; /* id field in tParameters table */
subject_t *subject;
parameters_t *parameters;
time_t start_time_timestamp;
......@@ -123,6 +124,7 @@ typedef struct {
configuration or print results) */
int no_results; /* if non-zero do not print results */
int no_stdout; /* if non-zero do not print results to stdout */
int stdout_simple; /* if non-zero print results as numbers only */
/* Following configuration can be read from command-line or conf. file */
char *db; /* MySQL database name, if NULL do not insert results
......
......@@ -26,6 +26,7 @@ void usage() {
fprintf(stderr, " -h print this help message\n");
fprintf(stderr, " -D or --debug[=n] set debug level to n (n can be specified with --debug only)\n");
fprintf(stderr, " -q or --no_stdout do not print results on stdout\n");
fprintf(stderr, " --stdout_simple print results as numbers only\n");
fprintf(stderr, " --no_measure do not do measurements\n");
fprintf(stderr, "\nSubject options:\n");
......@@ -119,6 +120,9 @@ int read_command_line(int argc, char *argv[], global_spec_t *global_spec) {
case LO_NO_STDOUT:
global_spec->no_stdout=1;
break;
case LO_STDOUT_SIMPLE:
global_spec->stdout_simple=1;
break;
case LO_NO_MEASURE:
global_spec->no_measure=1;
break;
......@@ -524,6 +528,9 @@ int read_conf_file(global_spec_t *global_spec)
param=cat->params;
while (param) {
if (!strcmp(param->name, "id"))
p->id=atoi(param->value);
if (!strcmp(param->name, "subject_id"))
p->subject_id=atoi(param->value);
......@@ -607,12 +614,11 @@ int read_const_conf_file(global_spec_t *global_spec)
}
/* Parse configuration file and load its content into a sequence of
structures representing categories and their items in the file */
if (pc_load(ABW_CONST_CFG)!=1) {
fprintf(stderr, "%s: pc_load() did not load file %s\n", __func__,
ABW_CONST_CFG);
return -1;
}
* structures representing categories and their items in the file.
* This file is optional, if we cannot load it, just return.
*/
if (pc_load(ABW_CONST_CFG)!=1)
return 0;
/* Go over all [subject] sections */
......
......@@ -27,7 +27,7 @@ enum {
LO_STATISTICS, LO_INTERVAL, LO_START_TIME, LO_END_TIME, LO_LINK_MBPS,
LO_CONF_FILENAME, LO_CONF_FROM_MYSQL, LO_CONF_TO_MYSQL, LO_CLEAR_CONF,
LO_NO_MEASURE, LO_NO_RESULTS, LO_NO_STDOUT, LO_DB, LO_USER, LO_PASSWD,
LO_DEBUG, LO_RRD_FILE, LO_MPLS };
LO_DEBUG, LO_RRD_FILE, LO_MPLS, LO_STDOUT_SIMPLE };
/* Long option names and argument types */
static const struct option long_options[] = {
......@@ -57,6 +57,7 @@ static const struct option long_options[] = {
{ "username", required_argument, 0, LO_USER },
{ "passwd", optional_argument, 0, LO_PASSWD },
{ "debug", optional_argument, 0, LO_DEBUG },
{ "stdout_simple", no_argument, 0, LO_STDOUT_SIMPLE },
{ 0, 0, 0, 0 }
};
......
# This file adds constant information about interfaces (not dependant
# on particular measurements).
#
# Only [subject] sections are recognized. id MUST be present but is not
# relevant to id in main configuration file. [subject] sections in main
# configuration file are refered to by a combination of hostname and
# and interface which both MUST be present.
#
# mpls can be yes or no (default no), if yes, packets with MPLS headers
# come to this interface and must be considered in header filtering
#
# link_mbps is physical installed bandwidth in Mb/s of the monitored link
# connected to this interface, default is 1000
[subject]
id=1
hostname=perfmon1.cesnet.cz
interface=eth1
mpls=yes
link_mbps=1000
[subject]
id=2
hostname=perfmon1.cesnet.cz
interface=eth2
......@@ -3,7 +3,8 @@
if [ "$1x" = "-hx" ]; then
echo "Usage: abw_restart.sh [-h|-f]"
echo "-h - print this help message"
echo "-f - force restart of abw, that is kill it and restart"
echo "-f - force restart of abw"
echo "-m - restart MAPI only and not abw"
exit 0;
fi
......@@ -13,6 +14,12 @@ else
FORCE=0
fi
if [ "$1x" = "-mx" ]; then
MAPI=1
else
MAPI=0
fi
PROCESSES_MAPID=`ps -ef|grep mapid|grep -v grep|wc -l`
echo "PROCESSES_MAPID: $PROCESSES_MAPID"
......@@ -33,6 +40,10 @@ else
echo agent already running
fi
if [ $MAPI = 1 ]; then
exit 0
fi
PROCESSES_ABW=`ps -ef|grep abw|grep -v grep|grep -v abw_restart.sh|wc -l`
echo "PROCESSES_ABW: $PROCESSES_ABW"
......
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
#include "abw_rrd.h"
#include "abw.h"
extern int debug;
/* TODO: check for overflow */
char *abw_rrd_create_filename(char *hostname, char *interface,
int port, int parameters_id, char *protocol) {
static char rrd_filename[MAX_RRD_FILENAME+1];
char *ch;
strcpy(rrd_filename, RRD_DIRECTORY);
if (hostname)
sprintf(rrd_filename+strlen(rrd_filename), "%s-", hostname);
/* Remove leading '/' and replace other '/' with '_' */
if (interface) {
ch=rrd_filename+strlen(rrd_filename);
if (interface[0]=='/')
sprintf(rrd_filename+strlen(rrd_filename), "%s-", interface+1);
else
sprintf(rrd_filename+strlen(rrd_filename), "%s-", interface);
while (*ch) {
if (*ch=='/')
*ch='_';
ch++;
}
}
if (port>=0)
sprintf(rrd_filename+strlen(rrd_filename), "%d-", port);
if (parameters_id>0)
sprintf(rrd_filename+strlen(rrd_filename), "%d-", parameters_id);
if (protocol)
sprintf(rrd_filename+strlen(rrd_filename), "%s", protocol);
if (rrd_filename[strlen(rrd_filename)-1]=='-')
rrd_filename[strlen(rrd_filename)-1]='\0';
strcat(rrd_filename, ".rrd");
if ((ch=malloc(strlen(rrd_filename)+1))==NULL) {
fprintf(stderr, "%s: malloc() failed\n", __func__);
return NULL;
}
strcpy(ch, rrd_filename);
return ch;
} /* abw_rrd_create_filename() */
int abw_rrd_create_file(char *filename) {
struct stat rrd_file_stat;
char command[MAX_COMMAND+1];
memset((void *)&rrd_file_stat, 0, (size_t)sizeof(rrd_file_stat));
if (stat(filename, &rrd_file_stat)<0) {
if (errno!=ENOENT) {
fprintf(stderr, "%s: stat() failed\n", __func__);
return -1;
}
if (debug)
printf("%s: RRD file %s does not exist, it will be created\n",
__func__, filename);
sprintf(command, "%s %s", RRD_CREATE_SCRIPT, filename);
if (debug)
printf("%s: system(%s)\n", __func__, command);
if (system(command)<0) {
fprintf(stderr, "%s: system(%s) failed\n", __func__, command);
return -1;
}
}
else {
if (debug)
printf("%s: RRD file %s already exists\n", __func__, filename);
}
return 0;
} /* abw_rrd_create_file() */
#ifndef __ABW_RRD_H
#define __ABW_RRD_H
#include "abw.h"
#define MAX_RRD_FILENAME 256
#define RRD_CREATE_SCRIPT "/usr/local/bin/rrd_create.sh"
#define RRD_DIRECTORY "/var/lib/rrd/" /* include trailing / */
char *abw_rrd_create_filename(char *hostname, char *interface,
int port, int parameters_id, char *protocol);
int abw_rrd_create_file(char *filename);
#endif
# Each line includes:
#
# <flow_id> <timestamp> <bytes for characteristic 1> ...
# <measurement_id> <timestamp> <packets> <bytes> <mbps> ...
#
1 1234567890.100000 0 0 0 0 0
2 1234567890.100000 0 0 0 0 0
1 1234567890.200000 0 0 0 0 0
2 1234567890.200000 0 0 0 0 0
# one triple of <packets> <bytes> <mbps> for each protocol in
# alphabetical order
1 1234567890.100000 0 0 0
2 1234567890.100000 0 0 0
1 1234567890.200000 0 0 0
2 1234567890.200000 0 0 0
......@@ -11,9 +11,9 @@ fi
rm -f $1
rrdtool create $1 --start 0 --step 1 \
DS:packets:COUNTER:5:U:U \
DS:bytes:COUNTER:5:U:U \
DS:mbps:COUNTER:5:U:U \
DS:packets:GAUGE:5:U:U \
DS:bytes:GAUGE:5:U:U \
DS:mbps:GAUGE:5:U:U \
RRA:AVERAGE:0.5:1:10800 \
RRA:AVERAGE:0.5:10:8640 \
RRA:AVERAGE:0.5:60:20160 \
......
RRD_DIR=/var/lib/rrd
rrdtool graph abw-L4-900.png --width 350 --height 250 \
--end now --start end-900s \
--slope-mode --interlaced --vertical-label "out Mb/s in" \
--title "L4 protocols, 1 second averages" -X 0 \
DEF:all_in=$RRD_DIR/jra1-1.cesnet.cz-dev_dag0-0-1-all.rrd:mbps:AVERAGE \
DEF:all_in_max=/var/lib/rrd/jra1-1.cesnet.cz-dev_dag0-0-1-all.rrd:mbps:MAX:step=60 \
DEF:tcp_in=/var/lib/rrd/jra1-1.cesnet.cz-dev_dag0-0-1-tcp.rrd:mbps:AVERAGE \
DEF:udp_in=/var/lib/rrd/jra1-1.cesnet.cz-dev_dag0-0-1-udp.rrd:mbps:AVERAGE \
DEF:all_out=/var/lib/rrd/jra1-2.cesnet.cz-dev_dag0-0-2-all.rrd:mbps:AVERAGE \
DEF:all_out_max=/var/lib/rrd/jra1-2.cesnet.cz-dev_dag0-0-2-all.rrd:mbps:MAX:step=60 \
DEF:tcp_out=/var/lib/rrd/jra1-2.cesnet.cz-dev_dag0-0-2-tcp.rrd:mbps:AVERAGE \
DEF:udp_out=/var/lib/rrd/jra1-2.cesnet.cz-dev_dag0-0-2-udp.rrd:mbps:AVERAGE \
CDEF:all_out_neg=all_out,-1,* \
CDEF:all_out_neg_max=all_out_max,-1,* \
CDEF:tcp_out_neg=tcp_out,-1,* \
CDEF:udp_out_neg=udp_out,-1,* \
LINE1:all_in_max#0000FF:"Max in (60 sec)" \
AREA:all_in#FFFF00:"Other in" \
LINE:0 \
AREA:tcp_in#00FF00:"TCP in":STACK \
AREA:udp_in#FF0000:"UDP in":STACK \
LINE1:all_out_neg_max#0000FF:"Max out (60 sec) " \
AREA:all_out_neg#FFFF0060:"Other out" \
LINE:0 \
AREA:tcp_out_neg#00FF0060:"TCP out":STACK \
AREA:udp_out_neg#FF000060:"UDP out":STACK \
LINE:0#000000
# Use:
#
# rrd_graph_simple.sh <RRD file> <start timestamp> <end timestamp>
rrdtool graph out.png -s $2 -e $3 -h 400 \
DEF:linea=$1:packets:AVERAGE LINE3:linea#FF0000:"Packets" \
DEF:lineb=$1:bytes:AVERAGE LINE3:lineb#00FF00:"Bytes" \
DEF:linec=$1:mbps:AVERAGE LINE3:linec#0000FF:"Mb/s" \
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment