?? graph.c
字號:
sprintf(Buffer2, "./htdocs/Subnet-%c-%s.html", config.tag, Buffer1); file = fopen(Buffer2, "wt"); fprintf(file, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n"); fprintf(file, "<HTML>\n<HEAD><TITLE>Bandwidthd - Subnet %s</TITLE>\n", Buffer1); if (config.meta_refresh) fprintf(file, "<META HTTP-EQUIV=\"REFRESH\" content=\"%u\">\n", config.meta_refresh); fprintf(file, "<META HTTP-EQUIV=\"EXPIRES\" content=\"-1\">\n"); fprintf(file, "<META HTTP-EQUIV=\"PRAGMA\" content=\"no-cache\">\n"); fprintf(file, "</HEAD>\n<BODY vlink=blue>\n%s<br>\n<CENTER><a name=\"Top\"></a>", ctime(&WriteTime)); fprintf(file, "<img src=\"logo.gif\" ALT=\"Logo\"><BR>"); fprintf(file, "Programmed by David Hinkle, Commissioned by <a href=\"http://www.derbytech.com\">DerbyTech</a> wireless networking.<BR>\n"); fprintf(file, "<BR>\n - <a href=\"index.html\">Daily</a> -- <a href=\"index2.html\">Weekly</a> -- "); fprintf(file, "<a href=\"index3.html\">Monthly</a> -- <a href=\"index4.html\">Yearly</a> - <BR>\n"); fprintf(file, "<BR>\nPick a Subnet:<BR>\n"); if (config.tag == '1') fprintf(file, "- <a href=\"index.html\">Top20</a> -"); else fprintf(file, "- <a href=\"index%c.html\">Top20</a> -", config.tag); for (Counter = 0; Counter < SubnetCount; Counter++) { HostIp2CharIp(SubnetTable[Counter].ip, Buffer2); fprintf(file, "- <a href=\"Subnet-%c-%s.html\">%s</a> -", config.tag, Buffer2, Buffer2); } fprintf(file, "<H1>%s - %s</H1></center>", Buffer1, PeriodDesc); fprintf(file, "<table width=\"100%%\" border=1 cellspacing=0>\n"); // PASS 1: Write out the table fprintf(file, "<TR bgcolor=lightblue><TD>Ip and Name<TD align=center>Total<TD align=center>Total Sent<TD align=center>Total Received<TD align=center>FTP<TD align=center>HTTP<TD align=center>P2P<TD align=center>TCP<TD align=center>UDP<TD align=center>ICMP\n"); for (tCounter=0, Counter=0; Counter < NumIps; Counter++) { if (SubnetTable[SubnetCounter].ip == (SummaryData[Counter]->IP & SubnetTable[SubnetCounter].mask)) { // The ip belongs to this subnet PrintTableLine(file, SummaryData[Counter], tCounter++); } } fprintf(file, "</table>\n"); // PASS 2: The graphs for (Counter=0; Counter < NumIps; Counter++) { if (SubnetTable[SubnetCounter].ip == (SummaryData[Counter]->IP & SubnetTable[SubnetCounter].mask)) { // The ip belongs to this subnet if (SummaryData[Counter]->Graph) { HostIp2CharIp(SummaryData[Counter]->IP, Buffer1); rdns(HostName, SummaryData[Counter]->IP); fprintf(file, "<a name=\"%s-%c\"></a><H1><a href=\"#top\">(Top)</a> %s - %s</H1><BR>\nSend:<br>\n<img src=%s-%c-S.png ALT=\"Sent traffic graph for %s\"><BR>\n<img src=legend.gif ALT=\"Legend\"><br>\nReceived:<br>\n<img src=%s-%c-R.png ALT=\"Received traffic for %s\"><BR>\n<img src=legend.gif ALT=\"Legend\"><br>\n<BR>\n", Buffer1, config.tag, Buffer1, HostName, Buffer1, config.tag, Buffer1, Buffer1, config.tag, Buffer1); } } } fprintf(file, "</BODY></HTML>\n"); fclose(file); } free(SummaryData); }void GraphIp(struct IPDataStore *DataStore, struct SummaryData *SummaryData, time_t timestamp) { FILE *OutputFile; char outputfilename[50]; gdImagePtr im, im2; int white; unsigned long long int YMax; char CharIp[20]; time_t GraphBeginTime; // TODO: First determine if graph will be printed before creating image and drawing backround, etc if (DataStore->ip == 0) strcpy(CharIp, "Total"); else HostIp2CharIp(DataStore->ip, CharIp); GraphBeginTime = timestamp - config.range; im = gdImageCreate(XWIDTH, YHEIGHT); white = gdImageColorAllocate(im, 255, 255, 255); //gdImageFill(im, 10, 10, white); im2 = gdImageCreate(XWIDTH, YHEIGHT); white = gdImageColorAllocate(im2, 255, 255, 255); //gdImageFill(im2, 10, 10, white); YMax = GraphData(im, im2, DataStore, GraphBeginTime, SummaryData); if (YMax != 0) { // Finish the graph PrepareXAxis(im, timestamp); PrepareYAxis(im, YMax); PrepareXAxis(im2, timestamp); PrepareYAxis(im2, YMax); sprintf(outputfilename, "./htdocs/%s-%c-S.png", CharIp, config.tag); OutputFile = fopen(outputfilename, "wb"); gdImagePng(im, OutputFile); fclose(OutputFile); sprintf(outputfilename, "./htdocs/%s-%c-R.png", CharIp, config.tag); OutputFile = fopen(outputfilename, "wb"); gdImagePng(im2, OutputFile); fclose(OutputFile); } else { // The graph isn't worth clutering up the web pages with sprintf(outputfilename, "./htdocs/%s-%c-R.png", CharIp, config.tag); unlink(outputfilename); sprintf(outputfilename, "./htdocs/%s-%c-S.png", CharIp, config.tag); unlink(outputfilename); } gdImageDestroy(im); gdImageDestroy(im2); }// Returns YMaxunsigned long long int GraphData(gdImagePtr im, gdImagePtr im2, struct IPDataStore *DataStore, time_t timestamp, struct SummaryData *SummaryData) { unsigned long long int YMax=0; struct DataStoreBlock *CurrentBlock; struct IPData *Data; // TODO: These should be a structure!!!! // TODO: This is an awfull lot of data to be allocated on the stack unsigned long long total[XWIDTH]; unsigned long long icmp[XWIDTH]; unsigned long long udp[XWIDTH]; unsigned long long tcp[XWIDTH]; unsigned long long ftp[XWIDTH]; unsigned long long http[XWIDTH]; unsigned long long p2p[XWIDTH]; int Count[XWIDTH]; unsigned long long total2[XWIDTH]; unsigned long long icmp2[XWIDTH]; unsigned long long udp2[XWIDTH]; unsigned long long tcp2[XWIDTH]; unsigned long long ftp2[XWIDTH]; unsigned long long http2[XWIDTH]; unsigned long long p2p2[XWIDTH]; size_t DataPoints; double x; int xint; int Counter; char Buffer[30]; char Buffer2[50]; int blue, lblue, red, yellow, purple, green, brown, black; int blue2, lblue2, red2, yellow2, purple2, green2, brown2, black2; unsigned long long int SentPeak = 0; unsigned long long int ReceivedPeak = 0; yellow = gdImageColorAllocate(im, 255, 255, 0); purple = gdImageColorAllocate(im, 255, 0, 255); green = gdImageColorAllocate(im, 0, 255, 0); blue = gdImageColorAllocate(im, 0, 0, 255); lblue = gdImageColorAllocate(im, 128, 128, 255); brown = gdImageColorAllocate(im, 128, 0, 0); red = gdImageColorAllocate(im, 255, 0, 0); black = gdImageColorAllocate(im, 0, 0, 0); yellow2 = gdImageColorAllocate(im2, 255, 255, 0); purple2 = gdImageColorAllocate(im2, 255, 0, 255); green2 = gdImageColorAllocate(im2, 0, 255, 0); blue2 = gdImageColorAllocate(im2, 0, 0, 255); lblue2 = gdImageColorAllocate(im2, 128, 128, 255); brown2 = gdImageColorAllocate(im2, 128, 0, 0); red2 = gdImageColorAllocate(im2, 255, 0, 0); black2 = gdImageColorAllocate(im2, 0, 0, 0); CurrentBlock = DataStore->FirstBlock; Data = CurrentBlock->Data; DataPoints = CurrentBlock->NumEntries; memset(SummaryData, 0, sizeof(struct SummaryData)); SummaryData->IP = Data[0].ip; memset(Count, 0, sizeof(Count[0])*XWIDTH); memset(total, 0, sizeof(total[0])*XWIDTH); memset(icmp, 0, sizeof(total[0])*XWIDTH); memset(udp, 0, sizeof(total[0])*XWIDTH); memset(tcp, 0, sizeof(total[0])*XWIDTH); memset(ftp, 0, sizeof(total[0])*XWIDTH); memset(http, 0, sizeof(total[0])*XWIDTH); memset(p2p, 0, sizeof(total[0])*XWIDTH); memset(total2, 0, sizeof(total[0])*XWIDTH); memset(icmp2, 0, sizeof(total[0])*XWIDTH); memset(udp2, 0, sizeof(total[0])*XWIDTH); memset(tcp2, 0, sizeof(total[0])*XWIDTH); memset(ftp2, 0, sizeof(total[0])*XWIDTH); memset(http2, 0, sizeof(total[0])*XWIDTH); memset(p2p2, 0, sizeof(total[0])*XWIDTH); // Change this to just run through all the datapoints we have stored in ram // Sum up the bytes/second while(DataPoints > 0) // We have data to graph { for (Counter = 0; Counter < DataPoints; Counter++) // Graph it all { x = (Data[Counter].timestamp-timestamp)*((XWIDTH-XOFFSET)/config.range)+XOFFSET; xint = x; if (xint >= 0 && xint < XWIDTH) { Count[xint]++; if (Data[Counter].Send.total > SentPeak) SentPeak = Data[Counter].Send.total; total[xint] += Data[Counter].Send.total; icmp[xint] += Data[Counter].Send.icmp; udp[xint] += Data[Counter].Send.udp; tcp[xint] += Data[Counter].Send.tcp; ftp[xint] += Data[Counter].Send.ftp; http[xint] += Data[Counter].Send.http; p2p[xint] += Data[Counter].Send.p2p; if (Data[Counter].Receive.total > ReceivedPeak) ReceivedPeak = Data[Counter].Receive.total; total2[xint] += Data[Counter].Receive.total; icmp2[xint] += Data[Counter].Receive.icmp; udp2[xint] += Data[Counter].Receive.udp; tcp2[xint] += Data[Counter].Receive.tcp; ftp2[xint] += Data[Counter].Receive.ftp; http2[xint] += Data[Counter].Receive.http; p2p2[xint] += Data[Counter].Receive.p2p; } } CurrentBlock = CurrentBlock->Next; if (CurrentBlock) { Data = CurrentBlock->Data; DataPoints = CurrentBlock->NumEntries; } else DataPoints = 0; } // Convert SentPeak and ReceivedPeak from bytes to bytes/second SentPeak /= config.interval; ReceivedPeak /= config.interval; // Preform the Average for(Counter=XOFFSET+1; Counter < XWIDTH; Counter++) { if (Count[Counter] > 0) { SummaryData->Total += total[Counter] + total2[Counter]; SummaryData->TotalSent += total[Counter]; SummaryData->TotalReceived += total2[Counter]; SummaryData->TCP += tcp[Counter] + tcp2[Counter]; SummaryData->FTP += ftp[Counter] + ftp2[Counter]; SummaryData->HTTP += http[Counter] + http2[Counter]; SummaryData->P2P += p2p[Counter] + p2p2[Counter]; SummaryData->UDP += udp[Counter] + udp2[Counter]; SummaryData->ICMP += icmp[Counter] + icmp2[Counter]; // Preform the average total[Counter] /= (Count[Counter]*config.interval); tcp[Counter] /= (Count[Counter]*config.interval); ftp[Counter] /= (Count[Counter]*config.interval); http[Counter] /= (Count[Counter]*config.interval); p2p[Counter] /= (Count[Counter]*config.interval); udp[Counter] /= (Count[Counter]*config.interval); icmp[Counter] /= (Count[Counter]*config.interval); total2[Counter] /= (Count[Counter]*config.interval); tcp2[Counter] /= (Count[Counter]*config.interval); ftp2[Counter] /= (Count[Counter]*config.interval); http2[Counter] /= (Count[Counter]*config.interval); p2p2[Counter] /= (Count[Counter]*config.interval); udp2[Counter] /= (Count[Counter]*config.interval); icmp2[Counter] /= (Count[Counter]*config.interval); if (total[Counter] > YMax) YMax = total[Counter]; if (total2[Counter] > YMax) YMax = total2[Counter]; } } YMax += YMax*0.05; // Add an extra 5% if ((SummaryData->IP != 0 && SummaryData->Total < config.graph_cutoff)) { SummaryData->Graph = FALSE; return(0); }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -