Last active
May 27, 2020 12:09
-
-
Save milendyankov/632fc1e2a7501203b09b63ebfd4d6a47 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.liferay.portal.kernel.dao.jdbc.DataAccess; | |
import com.liferay.portal.util.PropsValues; | |
import java.nio.file.Files; | |
import java.nio.charset.Charset | |
import java.nio.file.StandardOpenOption | |
/* | |
Calculating the size of very large folder trees can take very long time | |
In such case the web server may timeout with 504 error | |
To work around that, the data can be stored in a tmp file | |
It can be later on retrived with | |
`print (new File('/tmp/datasize').text)` | |
*/ | |
def tmpFile = new File("/tmp/datasize") | |
def tmpFileWriter = Files.newBufferedWriter(tmpFile.toPath(), Charset.forName("UTF-8"), StandardOpenOption.CREATE, StandardOpenOption.APPEND); | |
// append current time to the temporary file | |
tmpFileWriter.write("Date: " + new Date()) | |
tmpFileWriter.newLine() | |
// get the document library size | |
def dl_folder = new File(PropsValues.LIFERAY_HOME + "/data/document_library") | |
println "Document library size: " + (long)(dl_folder.directorySize() / 1024 / 1024) + " MB" | |
// append DL size to the temporary file | |
tmpFileWriter.write("Document library size: " + (long)(dl_folder.directorySize() / 1024 / 1024) + " MB") | |
tmpFileWriter.newLine() | |
// get the database size | |
def conn = DataAccess.getConnection(); | |
def stmt = conn.createStatement(); | |
def q = ''' | |
SELECT table_schema "DB Name", | |
Round(Sum(data_length + index_length) / 1024 / 1024, 1) "DB Size in MB" | |
FROM information_schema.tables | |
GROUP BY table_schema; | |
''' | |
def rs = stmt.executeQuery(q); | |
while (rs.next()) { | |
println('Database schema "' + rs.getString(1) + '" size: ' + rs.getInt(2) + ' MB'); | |
// append DB schema size to the temporary file | |
tmpFileWriter.write('Database schema "' + rs.getString(1) + '" size: ' + rs.getInt(2) + ' MB') | |
tmpFileWriter.newLine() | |
} | |
rs.close() | |
stmt.close() | |
tmpFileWriter.flush() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment