From 22fe14f29261b8eb333f2be5888571dd130c542e Mon Sep 17 00:00:00 2001 From: auron_x Date: Sun, 11 Mar 2007 17:04:11 +0000 Subject: [PATCH] *) first version of Peerload-graphic git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@3469 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- htroot/PeerLoadPicture.java | 29 +++++ source/de/anomic/plasma/plasmaGrafics.java | 123 ++++++++++++++++++++- 2 files changed, 150 insertions(+), 2 deletions(-) create mode 100644 htroot/PeerLoadPicture.java diff --git a/htroot/PeerLoadPicture.java b/htroot/PeerLoadPicture.java new file mode 100644 index 000000000..4633f0e9a --- /dev/null +++ b/htroot/PeerLoadPicture.java @@ -0,0 +1,29 @@ +import java.awt.Image; + +import de.anomic.http.httpHeader; +import de.anomic.plasma.plasmaGrafics; +import de.anomic.server.serverObjects; +import de.anomic.server.serverSwitch; + +public class PeerLoadPicture { + + public static Image respond(httpHeader header, serverObjects post, serverSwitch env) { + + int width = 800; + int height = 600; + boolean showidle = true; + + if (post != null) { + width = post.getInt("width", 800); + height = post.getInt("height", 600); + showidle = post.get("showidle", "true").equals("true"); + } + + //too small values lead to an error, too big to huge CPU/memory consumption, resulting in possible DOS. + if (width < 400 ) width = 400; + if (width > 1920) width = 1920; + if (height < 300) height = 300; + if (height > 1440) height = 1440; + return plasmaGrafics.getPeerLoadPicture(5000, width, height, showidle); + } +} diff --git a/source/de/anomic/plasma/plasmaGrafics.java b/source/de/anomic/plasma/plasmaGrafics.java index c0b3d0367..3f7b6e007 100644 --- a/source/de/anomic/plasma/plasmaGrafics.java +++ b/source/de/anomic/plasma/plasmaGrafics.java @@ -45,10 +45,14 @@ package de.anomic.plasma; +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.image.BufferedImage; import java.util.Date; import java.util.Enumeration; import java.util.Iterator; +import de.anomic.server.serverThread; import de.anomic.yacy.yacyCore; import de.anomic.yacy.yacySearch; import de.anomic.yacy.yacySeed; @@ -76,8 +80,35 @@ public class plasmaGrafics { private static final String COL_WE_LINE = "b0f0f0"; private static final String COL_WE_TEXT = "f0f0f0"; - private static ymageMatrix networkPicture = null; - private static long networkPictureDate = 0; + private static final Color COL_BORDER = new Color( 0, 0, 0); + private static final Color COL_NORMAL_TEXT = new Color( 0, 0, 0); + private static final Color COL_LOAD_BG = new Color(247, 247, 247); + + private static final int CIRCLE_PIECE_COUNT = 6; + private static final String[] CIRCLE_PIECE_NAMES = { + "Idle", + "Stacking", + "Parsing/Indexing", + "DHT-Distribution", + "YaCy Core", + "Misc." + }; + private static final Color[] CIRCLE_PIECE_COLORS = { + new Color(170, 255, 170), + new Color(115, 200, 210), + new Color(255, 130, 0), + new Color(119, 136, 153), + new Color(255, 230, 160), + new Color(190, 50, 180) + }; + + private static final int LEGEND_BOX_SIZE = 10; + + private static ymageMatrix networkPicture = null; + private static long networkPictureDate = 0; + + private static BufferedImage peerloadPicture = null; + private static long peerloadPictureDate = 0; public static ymageMatrix getSearchEventPicture() { if (plasmaSearchEvent.lastEvent == null) return null; @@ -257,5 +288,93 @@ public class plasmaGrafics { } } } + + public static BufferedImage getPeerLoadPicture(long maxAge, int width, int height, boolean showidle) { + if ((peerloadPicture == null) || ((System.currentTimeMillis() - peerloadPictureDate) > maxAge)) { + drawPeerLoadPicture(width, height, showidle); + } + return peerloadPicture; + } + + private static void drawPeerLoadPicture(int width, int height, boolean showidle) { + //prepare image + peerloadPicture = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB); + Graphics2D g = peerloadPicture.createGraphics(); + g.setBackground(COL_LOAD_BG); + g.clearRect(0,0,width,height); + + plasmaSwitchboard sb = plasmaSwitchboard.getSwitchboard(); + Iterator threads = sb.threadNames(); + String threadname; + serverThread thread; + + long busy_time = 0; + long[] thread_times = new long[CIRCLE_PIECE_COUNT]; + + //Iterate over threads + while (threads.hasNext()) { + threadname = (String)threads.next(); + thread = sb.getThread(threadname); + + //count total times + busy_time += thread.getBlockTime(); + busy_time += thread.getExecTime(); + if(showidle) thread_times[0] += thread.getSleepTime(); + + //count threadgroup-specific times + if(threadname.equals(plasmaSwitchboard.CRAWLSTACK)) { + thread_times[1] += thread.getBlockTime()+thread.getExecTime(); + } else if(threadname.equals(plasmaSwitchboard.INDEXER)) { + thread_times[2] = thread.getBlockTime()+thread.getExecTime(); + } else if(threadname.equals(plasmaSwitchboard.INDEX_DIST)) { + thread_times[3] = thread.getBlockTime()+thread.getExecTime(); + } else if(threadname.equals(plasmaSwitchboard.PEER_PING)) { + thread_times[4] = thread.getBlockTime()+thread.getExecTime(); + } else { + thread_times[5] += thread.getBlockTime()+thread.getExecTime(); + } + } + + int[] piece_angles = new int[CIRCLE_PIECE_COUNT]; + //calculate angles + for(int i=0;i