Search in sources :

Example 11 with Statistic

use of org.jivesoftware.openfire.stats.Statistic in project Openfire by igniterealtime.

the class StatsAction method getLowAndHigh.

/**
     * Given a statistic key and a start date, end date and number of datapoints, returns
     * a String[] containing the low and high values (in that order) for the given time period.
     * 
     * @param key the name of the statistic to return high and low values for.
     * @param timePeriod start date, end date and number of data points.
     * @return low and high values for the given time period / number of datapoints
     */
public static String[] getLowAndHigh(String key, long[] timePeriod) {
    MonitoringPlugin plugin = (MonitoringPlugin) XMPPServer.getInstance().getPluginManager().getPlugin(MonitoringConstants.NAME);
    StatsViewer viewer = (StatsViewer) plugin.getModule(StatsViewer.class);
    Statistic.Type type = viewer.getStatistic(key)[0].getStatType();
    double[] lows = viewer.getMin(key, timePeriod[0], timePeriod[1], (int) timePeriod[2]);
    double[] highs = viewer.getMax(key, timePeriod[0], timePeriod[1], (int) timePeriod[2]);
    String low;
    NumberFormat format = NumberFormat.getNumberInstance();
    format.setMaximumFractionDigits(0);
    if (lows.length > 0) {
        if (type == Statistic.Type.count) {
            double result = 0;
            for (int i = 0; i < lows.length; i++) {
                result += lows[i];
            }
            low = String.valueOf((int) result);
        } else {
            double l = 0;
            for (int i = 0; i < lows.length; i++) {
                if (Double.isNaN(lows[i])) {
                    lows[i] = 0;
                }
                l += lows[i];
            }
            low = format.format(l);
        }
    } else {
        low = String.valueOf(0);
    }
    String high;
    if (highs.length > 0) {
        if (type == Statistic.Type.count) {
            double result = 0;
            for (int i = 0; i < highs.length; i++) {
                result += highs[i];
            }
            high = String.valueOf((int) result);
        } else {
            double h = 0;
            for (int i = 0; i < highs.length; i++) {
                if (Double.isNaN(highs[i])) {
                    highs[i] = 0;
                }
                h += highs[i];
            }
            high = format.format(h);
        }
    } else {
        high = String.valueOf(0);
    }
    return new String[] { low, high };
}
Also used : MonitoringPlugin(org.jivesoftware.openfire.plugin.MonitoringPlugin) Statistic(org.jivesoftware.openfire.stats.Statistic) NumberFormat(java.text.NumberFormat)

Example 12 with Statistic

use of org.jivesoftware.openfire.stats.Statistic in project Openfire by igniterealtime.

the class MultiUserChatManager method addNumberIncomingMessages.

private void addNumberIncomingMessages() {
    // Register a statistic.
    Statistic statistic = new Statistic() {

        @Override
        public String getName() {
            return LocaleUtils.getLocalizedString("muc.stats.incoming.name");
        }

        @Override
        public Type getStatType() {
            return Type.rate;
        }

        @Override
        public String getDescription() {
            return LocaleUtils.getLocalizedString("muc.stats.incoming.description");
        }

        @Override
        public String getUnits() {
            return LocaleUtils.getLocalizedString("muc.stats.incoming.label");
        }

        @Override
        public double sample() {
            double msgcnt = 0;
            for (MultiUserChatService service : getMultiUserChatServices()) {
                msgcnt += service.getIncomingMessageCount(true);
            }
            return msgcnt;
        }

        @Override
        public boolean isPartialSample() {
            // Get this value from the other cluster nodes
            return true;
        }
    };
    StatisticsManager.getInstance().addMultiStatistic(incomingStatKey, trafficStatGroup, statistic);
}
Also used : Statistic(org.jivesoftware.openfire.stats.Statistic)

Example 13 with Statistic

use of org.jivesoftware.openfire.stats.Statistic in project Openfire by igniterealtime.

the class MultiUserChatManager method addTotalRoomStats.

/****************** Statistics code ************************/
private void addTotalRoomStats() {
    // Register a statistic.
    Statistic statistic = new Statistic() {

        @Override
        public String getName() {
            return LocaleUtils.getLocalizedString("muc.stats.active_group_chats.name");
        }

        @Override
        public Type getStatType() {
            return Type.count;
        }

        @Override
        public String getDescription() {
            return LocaleUtils.getLocalizedString("muc.stats.active_group_chats.desc");
        }

        @Override
        public String getUnits() {
            return LocaleUtils.getLocalizedString("muc.stats.active_group_chats.units");
        }

        @Override
        public double sample() {
            double rooms = 0;
            for (MultiUserChatService service : getMultiUserChatServices()) {
                rooms += service.getNumberChatRooms();
            }
            return rooms;
        }

        @Override
        public boolean isPartialSample() {
            return false;
        }
    };
    StatisticsManager.getInstance().addStatistic(roomsStatKey, statistic);
}
Also used : Statistic(org.jivesoftware.openfire.stats.Statistic)

Example 14 with Statistic

use of org.jivesoftware.openfire.stats.Statistic in project Openfire by igniterealtime.

the class MultiUserChatManager method addTotalOccupantsStats.

private void addTotalOccupantsStats() {
    // Register a statistic.
    Statistic statistic = new Statistic() {

        @Override
        public String getName() {
            return LocaleUtils.getLocalizedString("muc.stats.occupants.name");
        }

        @Override
        public Type getStatType() {
            return Type.count;
        }

        @Override
        public String getDescription() {
            return LocaleUtils.getLocalizedString("muc.stats.occupants.description");
        }

        @Override
        public String getUnits() {
            return LocaleUtils.getLocalizedString("muc.stats.occupants.label");
        }

        @Override
        public double sample() {
            double occupants = 0;
            for (MultiUserChatService service : getMultiUserChatServices()) {
                occupants += service.getNumberRoomOccupants();
            }
            return occupants;
        }

        @Override
        public boolean isPartialSample() {
            return false;
        }
    };
    StatisticsManager.getInstance().addStatistic(occupantsStatKey, statistic);
}
Also used : Statistic(org.jivesoftware.openfire.stats.Statistic)

Example 15 with Statistic

use of org.jivesoftware.openfire.stats.Statistic in project Openfire by igniterealtime.

the class ConversationManager method start.

public void start() {
    metadataArchivingEnabled = JiveGlobals.getBooleanProperty("conversation.metadataArchiving", true);
    messageArchivingEnabled = JiveGlobals.getBooleanProperty("conversation.messageArchiving", false);
    if (messageArchivingEnabled && !metadataArchivingEnabled) {
        Log.warn("Metadata archiving must be enabled when message archiving is enabled. Overriding setting.");
        metadataArchivingEnabled = true;
    }
    roomArchivingEnabled = JiveGlobals.getBooleanProperty("conversation.roomArchiving", false);
    roomArchivingStanzasEnabled = JiveGlobals.getBooleanProperty("conversation.roomArchivingStanzas", false);
    roomsArchived = StringUtils.stringToCollection(JiveGlobals.getProperty("conversation.roomsArchived", ""));
    if (roomArchivingEnabled && !metadataArchivingEnabled) {
        Log.warn("Metadata archiving must be enabled when room archiving is enabled. Overriding setting.");
        metadataArchivingEnabled = true;
    }
    idleTime = JiveGlobals.getIntProperty("conversation.idleTime", DEFAULT_IDLE_TIME) * JiveConstants.MINUTE;
    maxTime = JiveGlobals.getIntProperty("conversation.maxTime", DEFAULT_MAX_TIME) * JiveConstants.MINUTE;
    maxAge = JiveGlobals.getIntProperty("conversation.maxAge", DEFAULT_MAX_AGE) * JiveConstants.DAY;
    maxRetrievable = JiveGlobals.getIntProperty("conversation.maxRetrievable", DEFAULT_MAX_RETRIEVABLE) * JiveConstants.DAY;
    // Listen for any changes to the conversation properties.
    propertyListener = new ConversationPropertyListener();
    PropertyEventDispatcher.addListener(propertyListener);
    conversationQueue = new ConcurrentLinkedQueue<Conversation>();
    messageQueue = new ConcurrentLinkedQueue<ArchivedMessage>();
    participantQueue = new ConcurrentLinkedQueue<RoomParticipant>();
    conversationListeners = new CopyOnWriteArraySet<ConversationListener>();
    // Schedule a task to do conversation archiving.
    archiveTask = new TimerTask() {

        @Override
        public void run() {
            new ArchivingTask().run();
        }
    };
    taskEngine.scheduleAtFixedRate(archiveTask, JiveConstants.MINUTE, JiveConstants.MINUTE);
    if (JiveGlobals.getProperty("conversation.maxTimeDebug") != null) {
        Log.info("Monitoring plugin max time value deleted. Must be left over from stalled userCreation plugin run.");
        JiveGlobals.deleteProperty("conversation.maxTimeDebug");
    }
    // Schedule a task to do conversation cleanup.
    cleanupTask = new TimerTask() {

        @Override
        public void run() {
            for (String key : conversations.keySet()) {
                Conversation conversation = conversations.get(key);
                long now = System.currentTimeMillis();
                if ((now - conversation.getLastActivity().getTime() > idleTime) || (now - conversation.getStartDate().getTime() > maxTime)) {
                    removeConversation(key, conversation, new Date(now));
                }
            }
        }
    };
    taskEngine.scheduleAtFixedRate(cleanupTask, JiveConstants.MINUTE * 5, JiveConstants.MINUTE * 5);
    // Schedule a task to do conversation purging.
    maxAgeTask = new TimerTask() {

        @Override
        public void run() {
            if (maxAge > 0) {
                // Delete conversations older than maxAge days
                Connection con = null;
                PreparedStatement pstmt1 = null;
                PreparedStatement pstmt2 = null;
                PreparedStatement pstmt3 = null;
                try {
                    con = DbConnectionManager.getConnection();
                    pstmt1 = con.prepareStatement(DELETE_CONVERSATION_1);
                    pstmt2 = con.prepareStatement(DELETE_CONVERSATION_2);
                    pstmt3 = con.prepareStatement(DELETE_CONVERSATION_3);
                    Date now = new Date();
                    Date maxAgeDate = new Date(now.getTime() - maxAge);
                    ArchiveSearch search = new ArchiveSearch();
                    search.setDateRangeMax(maxAgeDate);
                    MonitoringPlugin plugin = (MonitoringPlugin) XMPPServer.getInstance().getPluginManager().getPlugin(MonitoringConstants.NAME);
                    ArchiveSearcher archiveSearcher = (ArchiveSearcher) plugin.getModule(ArchiveSearcher.class);
                    Collection<Conversation> conversations = archiveSearcher.search(search);
                    int conversationDeleted = 0;
                    for (Conversation conversation : conversations) {
                        Log.debug("Deleting: " + conversation.getConversationID() + " with date: " + conversation.getStartDate() + " older than: " + maxAgeDate);
                        pstmt1.setLong(1, conversation.getConversationID());
                        pstmt1.execute();
                        pstmt2.setLong(1, conversation.getConversationID());
                        pstmt2.execute();
                        pstmt3.setLong(1, conversation.getConversationID());
                        pstmt3.execute();
                        conversationDeleted++;
                    }
                    if (conversationDeleted > 0) {
                        Log.info("Deleted " + conversationDeleted + " conversations with date older than: " + maxAgeDate);
                    }
                } catch (Exception e) {
                    Log.error(e.getMessage(), e);
                } finally {
                    DbConnectionManager.closeConnection(pstmt1, con);
                    DbConnectionManager.closeConnection(pstmt2, con);
                    DbConnectionManager.closeConnection(pstmt3, con);
                }
            }
        }
    };
    taskEngine.scheduleAtFixedRate(maxAgeTask, JiveConstants.MINUTE, JiveConstants.MINUTE);
    // Register a statistic.
    Statistic conversationStat = new Statistic() {

        public String getName() {
            return LocaleUtils.getLocalizedString("stat.conversation.name", MonitoringConstants.NAME);
        }

        public Type getStatType() {
            return Type.count;
        }

        public String getDescription() {
            return LocaleUtils.getLocalizedString("stat.conversation.desc", MonitoringConstants.NAME);
        }

        public String getUnits() {
            return LocaleUtils.getLocalizedString("stat.conversation.units", MonitoringConstants.NAME);
        }

        public double sample() {
            return getConversationCount();
        }

        public boolean isPartialSample() {
            return false;
        }
    };
    StatisticsManager.getInstance().addStatistic(CONVERSATIONS_KEY, conversationStat);
    InternalComponentManager.getInstance().addListener(this);
}
Also used : Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Date(java.util.Date) SQLException(java.sql.SQLException) NotFoundException(org.jivesoftware.util.NotFoundException) MonitoringPlugin(org.jivesoftware.openfire.plugin.MonitoringPlugin) TimerTask(java.util.TimerTask) Statistic(org.jivesoftware.openfire.stats.Statistic) Collection(java.util.Collection)

Aggregations

Statistic (org.jivesoftware.openfire.stats.Statistic)17 org.jivesoftware.openfire.stats.i18nStatistic (org.jivesoftware.openfire.stats.i18nStatistic)3 Date (java.util.Date)2 JFreeChart (org.jfree.chart.JFreeChart)2 MonitoringPlugin (org.jivesoftware.openfire.plugin.MonitoringPlugin)2 Document (com.lowagie.text.Document)1 DocumentException (com.lowagie.text.DocumentException)1 Paragraph (com.lowagie.text.Paragraph)1 DefaultFontMapper (com.lowagie.text.pdf.DefaultFontMapper)1 PdfContentByte (com.lowagie.text.pdf.PdfContentByte)1 PdfTemplate (com.lowagie.text.pdf.PdfTemplate)1 PdfWriter (com.lowagie.text.pdf.PdfWriter)1 Graphics2D (java.awt.Graphics2D)1 Rectangle2D (java.awt.geom.Rectangle2D)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 NumberFormat (java.text.NumberFormat)1