Can't figure out how to get attachment sizing trends out of JIRA.
Example:
Unzipped | Zipped | Total Attachments by Month | ||||
Month | Files | Bytes | Files | Bytes | Files | Bytes |
2014-01 | 2,264 | 2,117,700,771 | 575 | 1,608,367,762 | 2,839 | 3,726,068,533 |
2014-02 | 2,053 | 1,713,796,369 | 372 | 1,388,456,805 | 2,425 | 3,102,253,174 |
Here's a Groovy Script Runner sample code that will get you a nice HTML table. You can put this script into a scripted field or anywhere else that you can execute groovy code.
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.AttachmentManager import com.atlassian.jira.issue.attachment.Attachment; import com.atlassian.jira.issue.attachment.AttachmentConstants import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; import java.text.SimpleDateFormat; import org.joda.time.DateTime List<Attachment> attachments = ComponentAccessor.getOfBizDelegator().findAll(AttachmentConstants.ATTACHMENT_ENTITY_NAME).collect({ ComponentAccessor.getAttachmentManager().getAttachment(it.getLong("id")) }) SimpleDateFormat monthFormat = new SimpleDateFormat("Y-MM"); Multimap<String, Attachment> multimap = ArrayListMultimap.create(); attachments.each({ multimap.put(monthFormat.format(it.created), it) }) def zipmimes = ["application/zip"] def lines = multimap.keySet().collect({ key -> def atts = multimap.get(key) def tfiles = atts.size() def tbytes = String.format("%,8d%n",atts.sum{it.filesize }?:0) // def zips = atts.findAll({it.zip || zipmimes.contains(it.mimetype)}) def zfiles = zips.size() def zbytes = String.format("%,8d%n",zips.sum{it.filesize}?:0) // def uzips = atts.findAll({!it.zip && !zipmimes.contains(it.mimetype)}) def uzfiles = uzips.size() def uzbytes = String.format("%,8d%n", uzips.sum{it.filesize}?:0) "<tr><td>$key</td><td>$uzfiles</td><td>$uzbytes</td><td>$zfiles</td><td>$zbytes</td><td>$tfiles</td><td>$tbytes</td>" }) $/ <table class="aui"> <thead><tr><th id="month">Month</th><th id="name" colspan="2">Unzipped</th><th id="type" colspan="2">Zipped</th> <th id="order" colspan="2">Total Attachments by Month</th></tr></thead> <tbody> <tr><td>Month</td><td>Files</td><td>Bytes</td><td>Files</td><td>Bytes</td><td>Files</td><td>Bytes</td>${lines.join()} </tbody> </table> /$
Here's a sample table produced by this script:
Month | Unzipped | Zipped | Total Attachments by Month | |||
---|---|---|---|---|---|---|
Month | Files | Bytes | Files | Bytes | Files | Bytes |
2015-11 | 11 | 9,315,894 | 0 | 0 | 11 | 9,315,894 |
2016-01 | 27 | 6,905,986 | 0 | 0 | 27 | 6,905,986 |
2015-10 | 6 | 646,983 | 2 | 286,290 | 8 | 933,273 |
2014-03 | 22 | 2,667,618 | 3 | 1,270,255 | 25 | 3,937,873 |
2016-05 | 55 | 21,215,496 | 1 | 576,759 | 56 | 21,792,255 |
2016-04 | 97 | 24,387,805 | 2 | 233,084 | 99 | 24,620,889 |
Well, figured out the first part of my idiocy. which was expecting it to run NOT in admin>script fields. I do have a follow-up, though. We have a couple of exception errors on it.
Mostly property errors in static type checking
image2016-5-26 10:25:26.png
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can ignore static type checks or modify the code and add types to the variables. Is it working now ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No; selecting Preview only swirls into oblivion with timeout error. If I bypass preview and simply add the script to the field, then the executions fail.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is a pretty heavy script if your instance is quite big and has a lot of attachments and this might be the reason for the timeout. My intention was to give you an idea of how the script should look like, but you might need to optimise it.
Would you provide some more context about the use case you're trying to implement ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Well, I know that our attachments currently account for around 150GB of space on the server. I need to trend the data flows, though, and this was a handy way to do it. I know our old server admin did it and ended up with the same chart, which is how I knew it was possible.
I don't need it for every case, or on every issue, unlike some scripted fields. This would be a one-shot run for the field, maybe run every quarter for trending data.
Does that help?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.