Название: K8s Applications mit MicroK8S auf Raspberry PI
Автор: Alfred Sabitzer
Издательство: Bookwire
Жанр: Математика
isbn: 9783742770134
isbn:
xtmp = strings.Replace(xtmp, "%HOSTINFO%", xenv, -1)
}
if strings.Contains(xtmp, "%MEMINFO%") {
runtimeOS := runtime.GOOS
vmStat, err := mem.VirtualMemory()
if err != nil {
log.Println(" Memoryinformation kann nicht gelesen werden: ", err)
}
xenv = "OS : " + runtimeOS +
"<br>Total memory: " + fmt.Sprintf("%5.1f", float64(vmStat.Total)/GB) +
" GB<br>Free memory: " + fmt.Sprintf("%5.1f", float64(vmStat.Free)/GB) +
" GB<br>Used memory: " + fmt.Sprintf("%5.1f", float64(vmStat.Used)/GB) +
" GB<br>Percentage used memory: " + strconv.FormatFloat(vmStat.UsedPercent, 'f', 2, 64)
xtmp = strings.Replace(xtmp, "%MEMINFO%", xenv, -1)
}
xhtml += xtmp
}
if err := scanner.Err(); err != nil {
log.Println(filename+" kann nicht gelesen werden: %s\n", err)
xhtml = loadError(err.Error())
}
}
defer f.Close()
return &Page{Title: title, Body: []byte(xhtml)}, nil
}
func viewHandler(w http.ResponseWriter, r *http.Request) {
title := r.URL.Path[len("/view/"):]
p, _ := loadPage(title)
fmt.Fprintf(w, "%s", p.Body)
}
func main() {
log.Println("Main Started")
http.HandleFunc("/view/", viewHandler)
log.Fatal(http.ListenAndServe(":8080", nil))
log.Println("Main End")
}
Um die Abhängigkeiten richtig auflösen zu können, braucht go auch ein module-File. Diese Dateien werden vom SDK LiteIDE selbstständig erzeugt.
alfred@monitoring:~/GetInfo$ cat go.mod
module GetInfo
go 1.16
require (
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/shirou/gopsutil v3.21.9+incompatible // indirect
github.com/tklauser/go-sysconf v0.3.9 // indirect
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac // indirect
)
alfred@monitoring:~/GetInfo$ cat go.sum
github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA=
github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8=
github.com/go-ole/go-ole v1.2.5 h1:t4MGB5xEDZvXI+0rMjjsfBsD7yAgp/s9ZDkL1JndXwY=
github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/shirou/gopsutil v3.21.9+incompatible h1:LTLpUnfX81MkHeCtSrwNKZwuW5Id6kCa7/P43NdcNn4=
github.com/shirou/gopsutil v3.21.9+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/tklauser/go-sysconf v0.3.9 h1:JeUVdAOWhhxVcU6Eqr/ATFHgXk/mmiItdKeJPev3vTo=
github.com/tklauser/go-sysconf v0.3.9/go.mod h1:11DU/5sG7UexIrp/O6g35hrWzu0JxlwQ3LSFUzyeuhs=
github.com/tklauser/numcpus v0.3.0 h1:ILuRUQBtssgnxw0XXIjKUC56fgnOrFoQQ/4+DeU2biQ=
github.com/tklauser/numcpus v0.3.0/go.mod h1:yFGUr7TUHQRAhyqBcEg0Ge34zDBAsIvJJcyE6boqnA8=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210816074244-15123e1e1f71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac h1:oN6lz7iLW/YC7un8pq+9bOLyXrprv2+DKfkJY+2LJJw=
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
alfred@monitoring:~/GetInfo$
Dieses Programm zeigt nach dem Aufruf von <Link:8080/view/filename> das aufgerufene File <filename> an, und ersetzt gewisse Schlüsselwörter durch konkreten Text. In unserem Beispiel habe ich das File hello.html mit OpenOffice vorbereitet.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title></title>
<meta name="generator" content="LibreOffice 7.1.6.2 (Linux)"/>
<meta name="author" content="Alfred Sabitzer"/>
<meta name="created" content="2021-10-07T16:33:50.696105947"/>
<meta name="changedby" content="Alfred Sabitzer"/>
<meta name="changed" content="2021-10-07T16:36:08.816466992"/>
<style type="text/css">
@page { size: 21cm 29.7cm; margin: 2cm }
p { margin-bottom: 0.25cm; line-height: 115%; background: transparent }
td p { orphans: 0; widows: 0; background: transparent }
</style>
</head>
<body СКАЧАТЬ