Du ser en gammel version af denne side. Se den nuværende version.

Sammenlign med nuværende Vis sidehistorik

« Forrige Version 4 Næste »

DRAFT

A possible way to Log User- and Page-Access to statsd is via the Event system - using Adaptavist's Scriptrunner for Confluence, se https://scriptrunner.adaptavist.com/latest/confluence/ConfluenceEventHandlers.html#_collecting_stats

Read Access Logging in Confluence for good reasons to log via the Event system.

 

To make this work, the jar file from https://github.com/datadog/java-dogstatsd-client#java-dogstatsd-client musk be placed under confluence/WEB-INF/lib and Confluence must be restarted

 

The script is executed by an Event Handler in Confluence:

this executes this script for every PageViewEvent:

import com.atlassian.confluence.user.AuthenticatedUserThreadLocal
import com.atlassian.confluence.user.*;
import com.atlassian.confluence.pages.Page
import com.atlassian.confluence.pages.PageManager
import com.atlassian.confluence.spaces.Space
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;

StatsDClient statsd = new NonBlockingStatsDClient("confluence.stats.views","localhost",8125,"");

def spaceManager = ComponentLocator.getComponent(SpaceManager)
def pageManager = ComponentLocator.getComponent(PageManager)

String userName="Anonymous"
def currentUser = AuthenticatedUserThreadLocal.get()
if (currentUser)
{
  userName=(String)currentUser.name
}

def event = event as PageEvent
def spaceKey = event.page.spaceKey
def pageId = event.page.id as String

statsd.incrementCounter("page.${pageId}");
statsd.incrementCounter("space.${spaceKey}");
statsd.incrementCounter("user.${userName}.${pageId}");
  • Ingen etiketter