github.com/kotovmak/go-admin@v1.1.1/plugins/admin/controller/system.go (about)

     1  package controller
     2  
     3  import (
     4  	"fmt"
     5  	"html/template"
     6  	"os"
     7  	"runtime"
     8  
     9  	"github.com/kotovmak/go-admin/context"
    10  	"github.com/kotovmak/go-admin/modules/auth"
    11  	"github.com/kotovmak/go-admin/modules/language"
    12  	"github.com/kotovmak/go-admin/modules/system"
    13  	"github.com/kotovmak/go-admin/template/types"
    14  )
    15  
    16  func (h *Handler) SystemInfo(ctx *context.Context) {
    17  
    18  	size := types.Size(6, 6, 6)
    19  
    20  	box1 := aBox().
    21  		WithHeadBorder().
    22  		SetHeader("<b>" + lg("application") + "</b>").
    23  		SetBody(stripedTable([]map[string]types.InfoItem{
    24  			{
    25  				"key":   types.InfoItem{Content: lg("app_name")},
    26  				"value": types.InfoItem{Content: "GoAdmin"},
    27  			}, {
    28  				"key":   types.InfoItem{Content: lg("go_admin_version")},
    29  				"value": types.InfoItem{Content: template.HTML(system.Version())},
    30  			}, {
    31  				"key":   types.InfoItem{Content: lg("theme_name")},
    32  				"value": types.InfoItem{Content: template.HTML(aTemplate().Name())},
    33  			}, {
    34  				"key":   types.InfoItem{Content: lg("theme_version")},
    35  				"value": types.InfoItem{Content: template.HTML(aTemplate().GetVersion())},
    36  			},
    37  		})).
    38  		GetContent()
    39  
    40  	app := system.GetAppStatus()
    41  
    42  	box2 := aBox().
    43  		WithHeadBorder().
    44  		SetHeader("<b>" + lg("application run") + "</b>").
    45  		SetBody(stripedTable([]map[string]types.InfoItem{
    46  			{
    47  				"key":   types.InfoItem{Content: lg("current_heap_usage")},
    48  				"value": types.InfoItem{Content: template.HTML(app.HeapAlloc)},
    49  			},
    50  			{
    51  				"key":   types.InfoItem{Content: lg("heap_memory_obtained")},
    52  				"value": types.InfoItem{Content: template.HTML(app.HeapSys)},
    53  			},
    54  			{
    55  				"key":   types.InfoItem{Content: lg("heap_memory_idle")},
    56  				"value": types.InfoItem{Content: template.HTML(app.HeapIdle)},
    57  			},
    58  			{
    59  				"key":   types.InfoItem{Content: lg("heap_memory_in_use")},
    60  				"value": types.InfoItem{Content: template.HTML(app.HeapInuse)},
    61  			},
    62  			{
    63  				"key":   types.InfoItem{Content: lg("heap_memory_released")},
    64  				"value": types.InfoItem{Content: template.HTML(app.HeapReleased)},
    65  			},
    66  			{
    67  				"key":   types.InfoItem{Content: lg("heap_objects")},
    68  				"value": types.InfoItem{Content: itos(app.HeapObjects)},
    69  			},
    70  		}) + `<div><hr></div>` + stripedTable([]map[string]types.InfoItem{
    71  			{
    72  				"key":   types.InfoItem{Content: lg("next_gc_recycle")},
    73  				"value": types.InfoItem{Content: template.HTML(app.NextGC)},
    74  			}, {
    75  				"key":   types.InfoItem{Content: lg("last_gc_time")},
    76  				"value": types.InfoItem{Content: template.HTML(app.LastGC)},
    77  			}, {
    78  				"key":   types.InfoItem{Content: lg("total_gc_pause")},
    79  				"value": types.InfoItem{Content: template.HTML(app.PauseTotalNs)},
    80  			}, {
    81  				"key":   types.InfoItem{Content: lg("last_gc_pause")},
    82  				"value": types.InfoItem{Content: template.HTML(app.PauseNs)},
    83  			}, {
    84  				"key":   types.InfoItem{Content: lg("gc_times")},
    85  				"value": types.InfoItem{Content: itos(app.NumGC)},
    86  			},
    87  		})).
    88  		GetContent()
    89  
    90  	col1 := aCol().SetSize(size).SetContent(box1 + box2).GetContent()
    91  
    92  	box4 := aBox().
    93  		WithHeadBorder().
    94  		SetHeader("<b>" + lg("application run") + "</b>").
    95  		SetBody(stripedTable([]map[string]types.InfoItem{
    96  			{
    97  				"key":   types.InfoItem{Content: lg("golang_version")},
    98  				"value": types.InfoItem{Content: template.HTML(runtime.Version())},
    99  			}, {
   100  				"key":   types.InfoItem{Content: lg("process_id")},
   101  				"value": types.InfoItem{Content: itos(os.Getpid())},
   102  			}, {
   103  				"key":   types.InfoItem{Content: lg("server_uptime")},
   104  				"value": types.InfoItem{Content: template.HTML(app.Uptime)},
   105  			}, {
   106  				"key":   types.InfoItem{Content: lg("current_goroutine")},
   107  				"value": types.InfoItem{Content: itos(app.NumGoroutine)},
   108  			},
   109  		}) + `<div><hr></div>` + stripedTable([]map[string]types.InfoItem{
   110  			{
   111  				"key":   types.InfoItem{Content: lg("current_memory_usage")},
   112  				"value": types.InfoItem{Content: template.HTML(app.MemAllocated)},
   113  			}, {
   114  				"key":   types.InfoItem{Content: lg("total_memory_allocated")},
   115  				"value": types.InfoItem{Content: template.HTML(app.MemTotal)},
   116  			}, {
   117  				"key":   types.InfoItem{Content: lg("memory_obtained")},
   118  				"value": types.InfoItem{Content: itos(app.MemSys)},
   119  			}, {
   120  				"key":   types.InfoItem{Content: lg("pointer_lookup_times")},
   121  				"value": types.InfoItem{Content: itos(app.Lookups)},
   122  			}, {
   123  				"key":   types.InfoItem{Content: lg("memory_allocate_times")},
   124  				"value": types.InfoItem{Content: itos(app.MemMallocs)},
   125  			}, {
   126  				"key":   types.InfoItem{Content: lg("memory_free_times")},
   127  				"value": types.InfoItem{Content: itos(app.MemFrees)},
   128  			},
   129  		}) + `<div><hr></div>` + stripedTable([]map[string]types.InfoItem{
   130  			{
   131  				"key":   types.InfoItem{Content: lg("bootstrap_stack_usage")},
   132  				"value": types.InfoItem{Content: template.HTML(app.StackInuse)},
   133  			}, {
   134  				"key":   types.InfoItem{Content: lg("stack_memory_obtained")},
   135  				"value": types.InfoItem{Content: template.HTML(app.StackSys)},
   136  			}, {
   137  				"key":   types.InfoItem{Content: lg("mspan_structures_usage")},
   138  				"value": types.InfoItem{Content: template.HTML(app.MSpanInuse)},
   139  			}, {
   140  				"key":   types.InfoItem{Content: lg("mspan_structures_obtained")},
   141  				"value": types.InfoItem{Content: template.HTML(app.HeapSys)},
   142  			}, {
   143  				"key":   types.InfoItem{Content: lg("mcache_structures_usage")},
   144  				"value": types.InfoItem{Content: template.HTML(app.MCacheInuse)},
   145  			}, {
   146  				"key":   types.InfoItem{Content: lg("mcache_structures_obtained")},
   147  				"value": types.InfoItem{Content: template.HTML(app.MCacheSys)},
   148  			}, {
   149  				"key":   types.InfoItem{Content: lg("profiling_bucket_hash_table_obtained")},
   150  				"value": types.InfoItem{Content: template.HTML(app.BuckHashSys)},
   151  			}, {
   152  				"key":   types.InfoItem{Content: lg("gc_metadata_obtained")},
   153  				"value": types.InfoItem{Content: template.HTML(app.GCSys)},
   154  			}, {
   155  				"key":   types.InfoItem{Content: lg("other_system_allocation_obtained")},
   156  				"value": types.InfoItem{Content: template.HTML(app.OtherSys)},
   157  			},
   158  		})).
   159  		GetContent()
   160  
   161  	col2 := aCol().SetSize(size).SetContent(box4).GetContent()
   162  
   163  	row := aRow().SetContent(col1 + col2).GetContent()
   164  
   165  	h.HTML(ctx, auth.Auth(ctx), types.Panel{
   166  		Content:     row,
   167  		Description: language.GetFromHtml("system info", "system"),
   168  		Title:       language.GetFromHtml("system info", "system"),
   169  	})
   170  }
   171  
   172  func stripedTable(list []map[string]types.InfoItem) template.HTML {
   173  	return aTable().
   174  		SetStyle("striped").
   175  		SetHideThead().
   176  		SetMinWidth("0.01%").
   177  		SetThead(types.Thead{
   178  			types.TheadItem{Head: "key", Width: "50%"},
   179  			types.TheadItem{Head: "value"},
   180  		}).
   181  		SetInfoList(list).GetContent()
   182  }
   183  
   184  func lg(v template.HTML) template.HTML {
   185  	return language.GetFromHtml(v, "system")
   186  }
   187  
   188  func itos(i interface{}) template.HTML {
   189  	return template.HTML(fmt.Sprintf("%v", i))
   190  }