Sfoglia il codice sorgente

feat: db storage usage report (#18464) (#18467)

Basic report to check storage usage by each table.

Note: This is not 100% accurate and will never be 100% accurate but gives rough indication of which table is consuming how much storage.

`no-docs`

[skip ci]

(cherry picked from commit abaa830bbc)

Co-authored-by: Ankush Menat <ankush@frappe.io>
version-14
mergify[bot] 2 anni fa
committed by GitHub
parent
commit
7cfe2d2f59
Non sono state trovate chiavi note per questa firma nel database ID Chiave GPG: 4AEE18F83AFDEB23
5 ha cambiato i file con 90 aggiunte e 0 eliminazioni
  1. +0
    -0
      frappe/core/report/database_storage_usage_by_tables/__init__.py
  2. +7
    -0
      frappe/core/report/database_storage_usage_by_tables/database_storage_usage_by_tables.js
  3. +28
    -0
      frappe/core/report/database_storage_usage_by_tables/database_storage_usage_by_tables.json
  4. +40
    -0
      frappe/core/report/database_storage_usage_by_tables/database_storage_usage_by_tables.py
  5. +15
    -0
      frappe/core/report/database_storage_usage_by_tables/test_database_storage_usage_by_tables.py

+ 0
- 0
frappe/core/report/database_storage_usage_by_tables/__init__.py Vedi File


+ 7
- 0
frappe/core/report/database_storage_usage_by_tables/database_storage_usage_by_tables.js Vedi File

@@ -0,0 +1,7 @@
// Copyright (c) 2022, Frappe Technologies and contributors
// For license information, please see license.txt
/* eslint-disable */

frappe.query_reports["Database Storage Usage By Tables"] = {
filters: [],
};

+ 28
- 0
frappe/core/report/database_storage_usage_by_tables/database_storage_usage_by_tables.json Vedi File

@@ -0,0 +1,28 @@
{
"add_total_row": 1,
"columns": [],
"creation": "2022-10-19 02:25:24.326791",
"disable_prepared_report": 0,
"disabled": 0,
"docstatus": 0,
"doctype": "Report",
"filters": [],
"idx": 0,
"is_standard": "Yes",
"letter_head": "abc",
"modified": "2022-10-19 02:59:00.365307",
"modified_by": "Administrator",
"module": "Core",
"name": "Database Storage Usage By Tables",
"owner": "Administrator",
"prepared_report": 0,
"query": "",
"ref_doctype": "Error Log",
"report_name": "Database Storage Usage By Tables",
"report_type": "Script Report",
"roles": [
{
"role": "System Manager"
}
]
}

+ 40
- 0
frappe/core/report/database_storage_usage_by_tables/database_storage_usage_by_tables.py Vedi File

@@ -0,0 +1,40 @@
# Copyright (c) 2022, Frappe Technologies and contributors
# For license information, please see license.txt

import frappe

COLUMNS = [
{"label": "Table", "fieldname": "table", "fieldtype": "Data", "width": 200},
{"label": "Size (MB)", "fieldname": "size", "fieldtype": "Float"},
{"label": "Data (MB)", "fieldname": "data_size", "fieldtype": "Float"},
{"label": "Index (MB)", "fieldname": "index_size", "fieldtype": "Float"},
]


def execute(filters=None):
frappe.only_for("System Manager")

data = frappe.db.multisql(
{
"mariadb": """
SELECT table_name AS `table`,
round(((data_length + index_length) / 1024 / 1024), 2) `size`,
round((data_length / 1024 / 1024), 2) as data_size,
round((index_length / 1024 / 1024), 2) as index_size
FROM information_schema.TABLES
ORDER BY (data_length + index_length) DESC;
""",
"postgres": """
SELECT
table_name as "table",
round(pg_total_relation_size(quote_ident(table_name)) / 1024 / 1024, 2) as "size",
round(pg_relation_size(quote_ident(table_name)) / 1024 / 1024, 2) as "data_size",
round(pg_indexes_size(quote_ident(table_name)) / 1024 / 1024, 2) as "index_size"
FROM information_schema.tables
WHERE table_schema = 'public'
ORDER BY 2 DESC;
""",
},
as_dict=1,
)
return COLUMNS, data

+ 15
- 0
frappe/core/report/database_storage_usage_by_tables/test_database_storage_usage_by_tables.py Vedi File

@@ -0,0 +1,15 @@
# Copyright (c) 2022, Frappe Technologies and contributors
# For license information, please see license.txt


from frappe.core.report.database_storage_usage_by_tables.database_storage_usage_by_tables import (
execute,
)
from frappe.tests.utils import FrappeTestCase


class TestDBUsageReport(FrappeTestCase):
def test_basic_query(self):
_, data = execute()
tables = [d.table for d in data]
self.assertFalse({"tabUser", "tabDocField"}.difference(tables))

Caricamento…
Annulla
Salva