cancel
Showing results for 
Search instead for 
Did you mean: 

where is all the space

michaelc
Champ on-the-rise
Champ on-the-rise
I was hoping someone had a simple script for this, I have been looking but I have not found one.

I have in the last few week seen a large increase on the space being used.
I want to know by directory how much space is being used.

does anyone have a script that would give me a result like that.
1 REPLY 1

sanket
Champ on-the-rise
Champ on-the-rise
You can use the below code (as a utility or a java-backed webscript) :
If it is a webscript, pass the space nodeRef as a parameter and then call the methods mentioned below.

public String prepareSearchKey(NodeRef spaceNodeRef){
      StringBuffer searchQry = new StringBuffer("");
      searchQry.append(" PATH:\"").append("prepare_lucene_query_from_the_passed_spaceNodeRef").append("\" AND");
      //searchQry.append(" @cm\\:content.contains:\"").append("contentUrl").append("\" AND");
      String lStrSearchQry = searchQry.substring(0, searchQry.length() - LUCENEQUERYPREFIX_LENGTH);
      LOGGER.debug("Key prepared:"+lStrSearchQry);
      return lStrSearchQry;
   }
   public double calculateSize(String searchKey){
      SearchParameters sp = new SearchParameters();
      double totalSizeCalculated = 0.0;
      NodeRef fileNodeRef = null;
      sp.addStore(Repository.getStoreRef());
        sp.setLanguage(SearchService.LANGUAGE_LUCENE);
        sp.setQuery(searchKey);
        ResultSet results = null;
        try
        {
           results = serviceRegistry.getSearchService().query(sp);
            LOGGER.debug("Total Docs Found:-"+results.length());
            float size[] = new float[results.length()];
            int counter = 0;
            for(ResultSetRow row : results)
            {
                try {
               NodeRef currentNodeRef = row.getNodeRef();
               fileNodeRef = currentNodeRef;
               if(!serviceRegistry.getNodeService().getType(fileNodeRef).equals(ContentModel.TYPE_SYSTEM_FOLDER) &&
                     !serviceRegistry.getNodeService().getType(fileNodeRef).equals(WorkflowModel.TYPE_PACKAGE)){
                  FileInfo fInfo = serviceRegistry.getFileFolderService().getFileInfo(fileNodeRef);
                  Map props = fInfo.getProperties();
                  String contentString = props.get(QName.createQName("{http://www.alfresco.org/model/content/1.0}content")).toString();
                  String sizeString = contentString.substring(contentString.indexOf("|size=")+CONTENTSIZEPREFIX_LENGTH, contentString.indexOf("|encoding"));
                  
                  LOGGER.debug("File "+row.getIndex()+" with size:"+ Integer.parseInt(sizeString));
                  
                  size[counter] = Float.parseFloat(sizeString);
                  totalSizeCalculated = totalSizeCalculated + (size[counter]/(1000*1000));//calc in MB
                  counter++;
               }
            } catch (Exception e) {
               // TODO Auto-generated catch block
               LOGGER.debug(e.getMessage());
               continue;
            }
            }
           
           
        }
        finally{
           results.close();
        }
        return totalSizeCalculated;
   }