As an alternative / addition to the bundled Space Details macro for Confluence:
here’s a simple user macro which displays extra details about a Confluence Space such as number of pages, number of blog posts, total size of attachments, etc. which you may find useful for a Community Management Dashboard:
NB: I couldn’t figure out how to round to 2 decimal places for the attachment size in Velocity without Velocity MathTool, if you know how to do that please drop me a line via the comments
To create the user macro:
1. Login to Confluence as a Confluence Administrator
2. Select Browse -> Confluence Admin
3. Select User Macros -> Create a new user macro
4. Enter the information as provided below:
Template:
## Macro title: Space Meta Data
## Macro has a body: Y or N (N)
## Body processing: Selected body processing option
## Output: Selected output option
##
## Developed by: Andrew Frayling
## Date created: 03/05/2012
## Installed by: <your name>
## Macro to display information such as number of pages, number of blog posts, attachment size, etc. about a Space.
## @noparams
## Get space details
#set ( $spaceName = $space.getName() )
#set ( $spaceKey = $space.getKey() )
#set ( $spaceHome = $space.getHomePage() )
#set ( $spaceCreator = $space.getCreatorName() )
#set ( $spaceCreationDate = $space.getCreationDate() )
#set ( $spaceDescription = $space.getDescription() )
#set ( $pageCount = $spaceManager.findPageTotal($space) )
#set ( $blogCount = $spaceManager.getNumberOfBlogPosts($space) )
## Get all pages in the current Space
#set ( $allPagesInSpace = $pageManager.getPages($space, true) )
## Reset total attachment file size
#set ( $totalAttachmentFileSizeForSpace = 0 )
## Reset total number of attachments
#set ( $totalAttachmentCount = 0 )
## Loop through all pages in the current Space
#foreach ($page in $allPagesInSpace)
## reset the attachment count for each page
#set ( $pageAttachmentCount = 0 )
## reset the attachment file size total for each page
#set ( $totalFileSizePerPage = 0 )
## get the attachments for each page
#set ( $allAttachments = $page.getAttachments() )
## Loop through each attachment
#foreach ($attachment in $allAttachments)
## Increment the attachment count for the page
#set ( $pageAttachmentCount = $pageAttachmentCount + 1 )
## Sum the size of the attachments on the page
#set ( $totalFileSizePerPage = $totalFileSizePerPage + $attachment.getFileSize() )
#end
## End looping through attachments
## Increment total attachment count for the current Space
#set ( $totalAttachmentCount = $totalAttachmentCount + $pageAttachmentCount )
## Sum the total size of attachments for the current Space
#set ( $totalAttachmentFileSizeForSpace = $totalAttachmentFileSizeForSpace + $totalFileSizePerPage )
#end
## End looping through pages
## Convert attachment size to MBs
#set ( $attachmentSizeMb = ($totalAttachmentFileSizeForSpace / 1024.00) / 1024.00 )
## Display Space Details
<table class="confluenceTable">
<tbody>
<tr>
<th class="confluenceTh">Name</th>
<td class="confluenceTd">$spaceName</td>
</tr>
<tr>
<th class="confluenceTh">Key</th>
<td class="confluenceTd">$spaceKey</td>
</tr>
<tr>
<th class="confluenceTh">Description</th>
<td class="confluenceTd">$spaceDescription.getBodyAsString()</td>
</tr>
<tr>
<th class="confluenceTh">Home Page</th>
<td class="confluenceTd">#contentLink2($spaceHome true false)</td>
</tr>
<tr>
<th class="confluenceTh">Created By</th>
<td class="confluenceTd">#usernameLink($spaceCreator) ($action.dateFormatter.formatDateTime($spaceCreationDate))</td>
</tr>
<tr>
<th class="confluenceTh">Number of Pages</th>
<td class="confluenceTd">$pageCount</td>
</tr>
<tr>
<th class="confluenceTh">Number of Blog Posts</th>
<td class="confluenceTd">$blogCount</td>
</tr>
<tr>
<th class="confluenceTh">Number of Attachments</th>
<td class="confluenceTd">$totalAttachmentCount (including all versions)</td>
</tr>
<tr>
<th class="confluenceTh">Total Size of Attachments</th>
<td class="confluenceTd">$attachmentSizeMb MB</td>
</tr>
</tbody>
</table>
5. Click Save
You can then use the macro on a page by using:
{spacemeta}
Or select the macro from the Macro Browser via Insert -> Other Macros:
I Hope you find this useful. The source code is available on Bitbucket.
Related Links
- Confluence Space Details Macro
- Confluence
- Confluence User Macros
- Confluence Community Management Dashboard
- Apache Velocity
- Velocity MathTool
- Source code on Bitbucket
Got a Confluence tip? Tweet it now then see it in the Confluence docs.















