[[retrievingStatisticsFromTheServer]]
= Retrieving statistics from the server
:author: Daniel Wisnewski
:version: v2.0, April 2017: Reformatted for v8.0.0.

By default we can retrieve server statistics using XMPP, no additional setup is necessary.

== Retrieving statistics using XMPP

Accessing statistics over XMPP protocol requires any XMPP client capable of executing link:http://xmpp.org/extensions/xep-0050.html[XEP-0050: Ad-Hoc Commands]. It's essential to remember, that only administrator (a user whose JID is configured as administrative) can access the statistics.

== Psi XMPP Client

For the purpose of this guide http://psi-im.org/[Psi] client will be used. After successfully configuring and connecting to account with administrative privileges we need to access _Service Discovery_, either from application menu or from context menu of the particular account account:

image:images/admin/monitoring_xmpp_1.png[caption="Figure 1: ", title="Access service discovery", alt="roster-discovery", width="233"]

In the _Service Discovery_ window we need to find _Server Statistics_ component:

image:images/admin/monitoring_xmpp_2.png[caption="Figure 2: ", title="Access statistics component in service discovery", alt="discovery-stats", width="558"]

We can either access statistics for all components or select particular component after expanding the tree. To execute ad-hoc command simply double click on the particular node which will open window with statistics:

image:images/admin/monitoring_xmpp_3.png[caption="Figure 3: ", title="Server statistics", alt="server-stats", width="456"]

In this window, in addition to see the statistics, we can adjust _Stats level_ by selecting desired level from the list and confirm by clicking _Finish_.


== Retrieving statistics using JMX

In order to access statistics over JMX we need to enable support for it in Tigase - xref:monitoring_activation[Monitoring Activation]. Afterwards we can use a number of tools to get to the statistics, for example the following:

== JConsole

After opening JConsole we either select local process or provide details of the remote process, including IP, port and credentials from *etc/jmx.** files:

image:images/admin/monitoring_jmx_jconsole_1.png[caption="Figure 4: JConsole", alt="jconsole", width="754"]

Afterwards we navigate to the MBeans tab from where we can access the `tigase.stats` MBean. It offers similar options to XMPP - either accessing statistics for all components or only for particular component as well as adjusting level for which we want to obtain statistics:

image:images/admin/monitoring_jmx_jconsole_2.png[caption="Figure 5: JConsole", alt="jconsole", width="967"]

== StatsDumper.groovy

In order to collect statistics over period of time following groovy script can be used: link:files/StatsDumper.groovy[StatsDumper.groovy]. It's a Simple JMX client that connects to Tigase and periodically saves all statistics to files.

It takes following parameters:
[source,bash]
----
$ groovy StatsDumper.groovy [hostname] [username] [password] [dir] [port] [delay(ms)] [interval(ms)] [loadhistory(bool)]
----
* `hostname` - address of the instance
* `username` - JMX username
* `password` - JMX username
* `dir` - directory to which save the files with statistics
* `port` - port on which to make the connection
* `delay`(ms) - initial delay in milliseconds after which statistics should be saved
* `interval`(ms) - interval between each retrieval/saving of statistics
* `loadhistory`(bool) - indicates whether or not load statistics history from server (if such is enabled in Tigase)
