Sidehistorik
...
Read Access Logging in Confluence for good reasons to log via the Event system.
Tip |
---|
To make this work, the jar file from https://github.com/datadog/java-dogstatsd-client#java-dogstatsd-client must be placed under confluence/WEB-INF/lib and Confluence must 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:
Kodeblok | ||||
---|---|---|---|---|
| ||||
import com.atlassian.confluence.userspaces.AuthenticatedUserThreadLocalSpaceManager import com.atlassian.confluencesal.user.*; import java.net.URL; import java.net.URLEncoder; import java.net.MalformedURLException; import java.io.UnsupportedEncodingException; import api.component.ComponentLocator import com.atlassian.confluence.pages.Page import com.atlassian.confluence.pages.PageManagerevent.events.content.page.* import comgroovy.atlassian.confluence.spaces.Spacetransform.Field import com.atlassiantimgroup.confluence.spaces.SpaceManagerstatsd.StatsDClient; import com.atlassiantimgroup.sal.api.component.ComponentLocator import com.atlassian.confluence.event.events.content.page.* statsd.NonBlockingStatsDClient; def spaceManager = ComponentLocator.getComponent(SpaceManager) def pageManager = ComponentLocator.getComponent(PageManager) String userName="Anonymous" def currentUser = AuthenticatedUserThreadLocal.get() if (currentUser) { userName=(String)currentUser.name } //System.out.println("Start...") def event = event as PageEvent String def spaceKey eventType=(String) event.page.toString() eventType=eventType.replaceAll("com.atlassian.confluence.event.events.content.page.","") eventType=eventType.substring(0, eventType.indexOf('@')) eventType=eventType.replaceAll("Event","") spaceKey def pageId = event.page.id as String //System.out.println("Posting.....") String[] tags = ["user:${userName}", "space:${spaceKey}", "user:${pageId}"] StatsDClient statsdpage = new NonBlockingStatsDClient("confluence.stats.views","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:
Advarsel | ||
---|---|---|
For some reason, this kills the Confluence Tomcat with "java.io.IOException: Too many open files", so my best guess is that the script is not releasing some resources. Raising limits has not helped...
|