Date: Fri, 29 Mar 2024 08:33:12 +0000 (UTC) Message-ID: <861336078.2051.1711701192662@50041d78312e> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_2050_1911201908.1711701192662" ------=_Part_2050_1911201908.1711701192662 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
A possible way to Log User- and Page-Access to statsd is via the= Event system - using Adaptavist's Scriptrunner for Confluence, se&nbs= p;https://scriptrunner.adaptavist.com/latest/confluence/ConfluenceEvent= Handlers.html#_collecting_stats
Read Ac= cess Logging in Confluence for good reasons to log via the Event s= ystem.
To make this work, the jar file from https://github.com/datadog/java-dogstatsd-client#java-dogstat= sd-client must be placed under confluence/WEB-INF/lib and Confluence mu= st be restarted. This will load the jar file into the Tomcat.
The script is executed by an Event Handler in Confluence:
this executes this script for every PageViewEvent:
import co= m.atlassian.confluence.spaces.SpaceManager import com.atlassian.sal.api.component.ComponentLocator import com.atlassian.confluence.event.events.content.page.* import groovy.transform.Field import com.timgroup.statsd.StatsDClient; import com.timgroup.statsd.NonBlockingStatsDClient; def spaceManager =3D ComponentLocator.getComponent(SpaceManager) def pageManager =3D ComponentLocator.getComponent(PageManager) String userName=3D"Anonymous" def currentUser =3D AuthenticatedUserThreadLocal.get() if (currentUser) { userName=3D(String)currentUser.name } //System.out.println("Start...") def event =3D event as PageEvent def spaceKey =3D event.page.spaceKey def pageId =3D event.page.id as String //System.out.println("Posting.....") String[] tags =3D ["user:${userName}", "space:${spaceKey}", "user:${pageId}= "] StatsDClient statsdpage =3D new NonBlockingStatsDClient("confluence.stats.v= iews","localhost",8125,tags); statsdpage.incrementCounter("page"); try { //System.out.println("Closing socket"); statsdpage.stop(); } catch(Exception ex) { //System.out.println("Catching the exception"); } //System.out.println("End......")
Viewing the data in DataDog - here its all Page Views pr. Space:
Or tracking a single User pr. Space:
Finally - vice versa - Monitoring a single Space for PageViews pr. User:=
For some reason, this kills the Confluence Tomcat with "java.io.IOExcept= ion: Too many open files", so my best guess is that the script is not relea= sing some resources. Raising limits has not helped...
12-Mar-20= 17 10:39:30.087 SEVERE [http-nio-8090-Acceptor-0] org.apache.tomcat.util.ne= t.NioEndpoint$Acceptor.run Socket accept failed java.io.IOException: Too many open files =09at sun.nio.ch.ServerSocketChannelImpl.accept0(Native Method) =09at sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.jav= a:422) =09at sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.jav= a:250) =09at org.apache.tomcat.util.net.NioEndpoint$Acceptor.run(NioEndpoint.java:= 682) =09at java.lang.Thread.run(Thread.java:745)