dis: Display initial statistics
This commit is contained in:
parent
6d30a42e56
commit
964e74a9f4
12 changed files with 252 additions and 7 deletions
12
cmd/info.go
12
cmd/info.go
|
|
@ -63,6 +63,18 @@ func (i info) Run(context wisski_distillery.Context) error {
|
|||
context.Printf("Last Update: %v\n", info.LastUpdate.String())
|
||||
context.Printf("Last Cron: %v\n", info.LastCron.String())
|
||||
|
||||
context.Printf("Bundles: (count %d)\n", info.Statistics.Bundles.TotalBundles)
|
||||
for _, bundle := range info.Statistics.Bundles.Bundles {
|
||||
if bundle.Count == 0 {
|
||||
continue
|
||||
}
|
||||
context.Printf("- %s %d %v\n", bundle.Label, bundle.Count, bundle.MainBundle)
|
||||
}
|
||||
context.Printf("Graphs: (count %d)\n", len(info.Statistics.Triplestore.Graphs))
|
||||
for _, graph := range info.Statistics.Triplestore.Graphs {
|
||||
context.Printf("- %s %d\n", graph.URI, graph.Count)
|
||||
}
|
||||
|
||||
context.Printf("SSH Keys: (count %d)\n", len(info.SSHKeys))
|
||||
for _, key := range info.SSHKeys {
|
||||
context.Printf("- %s\n", key)
|
||||
|
|
|
|||
|
|
@ -265,11 +265,106 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="pure-u-1-1">
|
||||
<h2 id="stats">Statistics</h2>
|
||||
</div>
|
||||
|
||||
<div class="pure-u-1 pure-u-xl-1-2">
|
||||
<div class="padding">
|
||||
<div class="overflow">
|
||||
<table class="pure-table pure-table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="5">
|
||||
Bundles
|
||||
</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>
|
||||
Label
|
||||
</th>
|
||||
<th>
|
||||
Machine Name
|
||||
</th>
|
||||
<th>
|
||||
Count
|
||||
</th>
|
||||
<th>
|
||||
LastEdit
|
||||
</th>
|
||||
<th>
|
||||
MainBundle
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{ range .Info.Statistics.Bundles.Bundles }}
|
||||
<tr>
|
||||
<td>
|
||||
<code>{{ .Label }}</code>
|
||||
</td>
|
||||
<td>
|
||||
<code>{{ .MachineName }}</code>
|
||||
</td>
|
||||
<td>
|
||||
<code>{{ .Count }}</code>
|
||||
</td>
|
||||
<td>
|
||||
<code>{{ .LastEdit }}</code>
|
||||
</td>
|
||||
<td>
|
||||
<code>{{ .MainBundle }}</code>
|
||||
</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="pure-u-1 pure-u-xl-1-2">
|
||||
<div class="padding">
|
||||
<div class="overflow">
|
||||
<table class="pure-table pure-table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="2">
|
||||
Triplestore
|
||||
</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>
|
||||
URI
|
||||
</th>
|
||||
<th>
|
||||
Count
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{ range .Info.Statistics.Triplestore.Graphs }}
|
||||
<tr>
|
||||
<td>
|
||||
<code>{{ .URI }}</code>
|
||||
</td>
|
||||
<td>
|
||||
<code>{{ .Count }}</code>
|
||||
</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="pure-u-1-1">
|
||||
<h2 id="ssh">SSH Keys</h2>
|
||||
<table class="pure-table pure-table-bordered padding">
|
||||
<tbody>
|
||||
{{ range .Info.Keys }}
|
||||
{{ range .Info.SSHKeys }}
|
||||
<tr>
|
||||
<td>
|
||||
<code>{{ . }}</code>
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta charset="utf-8">
|
||||
|
||||
<title>{{ block "block" . }}Distillery Control Page{{ end }}</title>
|
||||
{{ block "styles" . }}styles{{ end }}
|
||||
|
|
|
|||
49
internal/phpx/serialize.go
Normal file
49
internal/phpx/serialize.go
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
package phpx
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
// BooleanIsh represents a boolean php value.
|
||||
//
|
||||
// The value can be serialized to and from php and will behave accordingly.
|
||||
//
|
||||
// The value will always be Marshaled as "true" or "false".
|
||||
//
|
||||
// When Unmarshaled, it behaves as described on https://www.php.net/manual/en/language.types.boolean.php#language.types.boolean.casting.
|
||||
type BooleanIsh bool
|
||||
|
||||
func (bi BooleanIsh) MarshalJSON() ([]byte, error) {
|
||||
if bi {
|
||||
return []byte("true"), nil
|
||||
}
|
||||
return []byte("false"), nil
|
||||
}
|
||||
func (bi *BooleanIsh) UnmarshalJSON(data []byte) (err error) {
|
||||
// unmarshal into a generic value
|
||||
var value any
|
||||
err = json.Unmarshal(data, &value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// check if it is false ish
|
||||
var isFalseIsh bool
|
||||
switch d := value.(type) {
|
||||
case bool:
|
||||
isFalseIsh = !d
|
||||
case int:
|
||||
isFalseIsh = d == 0
|
||||
case float64:
|
||||
isFalseIsh = d == 0
|
||||
case string:
|
||||
isFalseIsh = d == "" || d == "0"
|
||||
case []any:
|
||||
isFalseIsh = len(d) == 0
|
||||
case map[string]any:
|
||||
isFalseIsh = len(d) == 0
|
||||
case nil:
|
||||
isFalseIsh = true
|
||||
}
|
||||
*bi = BooleanIsh(!isFalseIsh)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
@ -1,12 +1,15 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# This script is used to start a user shell inside the docker container.
|
||||
# if the user is not www-data, re-invoke self as www-data
|
||||
if [ "$USER" != "www-data" ]; then
|
||||
sudo -u www-data /bin/bash /user_shell.sh "$@"
|
||||
exit $?
|
||||
fi
|
||||
|
||||
# Now start a shell in the proper path
|
||||
cd "/var/www/data/project"
|
||||
export "PATH=/var/www/data/project/vendor/bin:$PATH"
|
||||
|
||||
if [ "$USER" = "www-data" ]; then
|
||||
/bin/bash "$@"
|
||||
else
|
||||
sudo -u www-data /bin/bash "$@"
|
||||
fi;
|
||||
# Re-invoke the actual command
|
||||
/bin/bash "$@"
|
||||
|
|
@ -38,6 +38,9 @@ type Information struct {
|
|||
LastUpdate time.Time
|
||||
LastCron time.Time
|
||||
|
||||
// Statistics of the wisski (TODO: fix me)
|
||||
Statistics Statistics
|
||||
|
||||
// List of backups made
|
||||
Snapshots []models.Export
|
||||
|
||||
|
|
@ -49,3 +52,39 @@ type Information struct {
|
|||
Prefixes []string // list of prefixes
|
||||
Pathbuilders map[string]string // all the pathbuilders
|
||||
}
|
||||
|
||||
type Statistics struct {
|
||||
Activity struct {
|
||||
MostVisited string `json:"mostVisited"`
|
||||
PageVisits []struct {
|
||||
URL string `json:"url"`
|
||||
Visits int `json:"visits"`
|
||||
} `json:"pageVisits"`
|
||||
TotalEditsLastWeek int `json:"totalEditsLastWeek"`
|
||||
} `json:"activity"`
|
||||
Bundles struct {
|
||||
Bundles []struct {
|
||||
Label string `json:"label"`
|
||||
MachineName string `json:"machineName"`
|
||||
|
||||
Count int `json:"entities"`
|
||||
|
||||
LastEdit int `json:"lastEdit"`
|
||||
|
||||
MainBundle phpx.BooleanIsh `json:"mainBundle"`
|
||||
} `json:"bundleStatistics"`
|
||||
TotalBundles int `json:"totalBundles"`
|
||||
TotalMainBundles int `json:"totalMainBundles"`
|
||||
} `json:"bundles"`
|
||||
Triplestore struct {
|
||||
Graphs []struct {
|
||||
URI string `json:"uri"`
|
||||
Count int `json:"triples"`
|
||||
} `json:"graphStatistics"`
|
||||
Total int `json:"totalTriples"`
|
||||
} `json:"triplestore"`
|
||||
Users struct {
|
||||
LastLogin string `json:"lastLogin"`
|
||||
TotalUsers int `json:"totalUsers"`
|
||||
} `json:"users"`
|
||||
}
|
||||
|
|
|
|||
37
internal/wisski/ingredient/php/extras/stats.go
Normal file
37
internal/wisski/ingredient/php/extras/stats.go
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
package extras
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"log"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/phpx"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient/php"
|
||||
)
|
||||
|
||||
type Stats struct {
|
||||
ingredient.Base
|
||||
|
||||
PHP *php.PHP
|
||||
}
|
||||
|
||||
//go:embed stats.php
|
||||
var statsPHP string
|
||||
|
||||
// Get fetches all statistics from the server
|
||||
func (stats *Stats) Get(server *phpx.Server) (data ingredient.Statistics, err error) {
|
||||
err = stats.PHP.ExecScript(server, &data, statsPHP, "export_statistics")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (stats *Stats) Fetch(flags ingredient.FetchFlags, info *ingredient.Information) (err error) {
|
||||
if flags.Quick {
|
||||
return
|
||||
}
|
||||
|
||||
info.Statistics, _ = stats.Get(flags.Server)
|
||||
return
|
||||
}
|
||||
8
internal/wisski/ingredient/php/extras/stats.php
Normal file
8
internal/wisski/ingredient/php/extras/stats.php
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
function export_statistics() {
|
||||
$service = 'wisski_statistics.statistics';
|
||||
if (empty(\Drupal::hasService($service))) return (object)[];
|
||||
$statistics = \Drupal::service($service);
|
||||
return $statistics->update();
|
||||
}
|
||||
|
|
@ -99,6 +99,7 @@ func (wisski *WissKI) allIngredients() []initFunc {
|
|||
auto[*extras.Prefixes],
|
||||
auto[*extras.Settings],
|
||||
auto[*extras.Pathbuilder],
|
||||
auto[*extras.Stats],
|
||||
|
||||
// info
|
||||
manual(func(info *info.Info) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue