Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagegroovy
titlepost.groovy
import com.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 = 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

def spaceKey = event.page.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:

...