commit before applying 2p patch
This commit is contained in:
parent
4c33b5dd0e
commit
70faf517f3
@ -27,6 +27,7 @@ func (m *Manager) SaveInstance(i *instance.Instance) error {
|
|||||||
Identified: i.Identified,
|
Identified: i.Identified,
|
||||||
Implementation: i.Implementation,
|
Implementation: i.Implementation,
|
||||||
NextFetch: i.NextFetch,
|
NextFetch: i.NextFetch,
|
||||||
|
LastError: i.LastError,
|
||||||
NodeInfoURL: i.NodeInfoURL,
|
NodeInfoURL: i.NodeInfoURL,
|
||||||
ServerImplementationString: i.ServerImplementationString,
|
ServerImplementationString: i.ServerImplementationString,
|
||||||
ServerVersionString: i.ServerVersionString,
|
ServerVersionString: i.ServerVersionString,
|
||||||
@ -49,6 +50,7 @@ func (m *Manager) SaveInstance(i *instance.Instance) error {
|
|||||||
ei.Fetching = i.Fetching
|
ei.Fetching = i.Fetching
|
||||||
ei.HighestID = i.HighestID
|
ei.HighestID = i.HighestID
|
||||||
ei.Hostname = i.Hostname
|
ei.Hostname = i.Hostname
|
||||||
|
ei.LastError = i.LastError
|
||||||
ei.Identified = i.Identified
|
ei.Identified = i.Identified
|
||||||
ei.Implementation = string(i.Implementation)
|
ei.Implementation = string(i.Implementation)
|
||||||
ei.NextFetch = i.NextFetch
|
ei.NextFetch = i.NextFetch
|
||||||
@ -56,7 +58,6 @@ func (m *Manager) SaveInstance(i *instance.Instance) error {
|
|||||||
ei.ServerImplementationString = i.ServerImplementationString
|
ei.ServerImplementationString = i.ServerImplementationString
|
||||||
ei.ServerVersionString = i.ServerVersionString
|
ei.ServerVersionString = i.ServerVersionString
|
||||||
ei.SuccessCount = i.SuccessCount
|
ei.SuccessCount = i.SuccessCount
|
||||||
|
|
||||||
r := m.db.Save(&ei)
|
r := m.db.Save(&ei)
|
||||||
return r.Error
|
return r.Error
|
||||||
}
|
}
|
||||||
@ -77,6 +78,7 @@ func (m *Manager) ListInstances() ([]*instance.Instance, error) {
|
|||||||
x.Fetching = i.Fetching
|
x.Fetching = i.Fetching
|
||||||
x.HighestID = i.HighestID
|
x.HighestID = i.HighestID
|
||||||
x.Hostname = i.Hostname
|
x.Hostname = i.Hostname
|
||||||
|
x.LastError = i.LastError
|
||||||
x.Identified = i.Identified
|
x.Identified = i.Identified
|
||||||
x.Implementation = i.Implementation
|
x.Implementation = i.Implementation
|
||||||
x.NextFetch = i.NextFetch
|
x.NextFetch = i.NextFetch
|
||||||
|
@ -21,7 +21,7 @@ type StoredToot struct {
|
|||||||
Content []byte
|
Content []byte
|
||||||
TextContent []byte
|
TextContent []byte
|
||||||
URL string
|
URL string
|
||||||
Hostname string
|
Hostname string `gorm:"index:hostnameindex"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type APInstance struct {
|
type APInstance struct {
|
||||||
@ -34,6 +34,7 @@ type APInstance struct {
|
|||||||
Identified bool
|
Identified bool
|
||||||
Fetching bool
|
Fetching bool
|
||||||
Disabled bool
|
Disabled bool
|
||||||
|
LastError string
|
||||||
Implementation string
|
Implementation string
|
||||||
NextFetch time.Time
|
NextFetch time.Time
|
||||||
NodeInfoURL string
|
NodeInfoURL string
|
||||||
|
24
database/readshortcuts.go
Normal file
24
database/readshortcuts.go
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package database
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (m *Manager) TootCountForHostname(hostname string) (uint, error) {
|
||||||
|
var c uint
|
||||||
|
e := m.db.Model(&StoredToot{}).Where("hostname = ?", hostname).Count(&c)
|
||||||
|
if e.Error != nil {
|
||||||
|
return 0, e.Error
|
||||||
|
} else {
|
||||||
|
return c, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Manager) GetAPInstanceFromUUID(uuid *uuid.UUID) (*APInstance, error) {
|
||||||
|
var i APInstance
|
||||||
|
e := m.db.Model(&APInstance{}).Where("uuid = ?", uuid).First(&i)
|
||||||
|
if e.Error != nil {
|
||||||
|
return nil, e.Error
|
||||||
|
}
|
||||||
|
return &i, nil
|
||||||
|
}
|
@ -37,6 +37,7 @@ type Instance struct {
|
|||||||
Implementation string
|
Implementation string
|
||||||
InitialFSMState string
|
InitialFSMState string
|
||||||
NextFetch time.Time
|
NextFetch time.Time
|
||||||
|
LastError string
|
||||||
NodeInfoURL string
|
NodeInfoURL string
|
||||||
ServerImplementationString string
|
ServerImplementationString string
|
||||||
ServerVersionString string
|
ServerVersionString string
|
||||||
|
@ -20,15 +20,19 @@ func (a *Server) instances() []hash {
|
|||||||
now := time.Now()
|
now := time.Now()
|
||||||
for _, v := range a.feta.manager.ListInstances() {
|
for _, v := range a.feta.manager.ListInstances() {
|
||||||
i := make(hash)
|
i := make(hash)
|
||||||
|
// TODO move this locking onto a method on Instance that just
|
||||||
|
// returns a new hash
|
||||||
// FIXME figure out why a very short lock here deadlocks
|
// FIXME figure out why a very short lock here deadlocks
|
||||||
v.Lock()
|
v.Lock()
|
||||||
i["hostname"] = v.Hostname
|
i["hostname"] = v.Hostname
|
||||||
|
i["uuid"] = v.UUID.String()
|
||||||
i["nextCheck"] = v.NextFetch.UTC().Format(time.RFC3339)
|
i["nextCheck"] = v.NextFetch.UTC().Format(time.RFC3339)
|
||||||
i["nextCheckAfter"] = (-1 * now.Sub(v.NextFetch)).String()
|
i["nextCheckAfter"] = (-1 * now.Sub(v.NextFetch)).String()
|
||||||
i["successCount"] = v.SuccessCount
|
i["successCount"] = v.SuccessCount
|
||||||
i["errorCount"] = v.ErrorCount
|
i["errorCount"] = v.ErrorCount
|
||||||
i["identified"] = v.Identified
|
i["identified"] = v.Identified
|
||||||
i["status"] = v.Status() //FIXME maybe this is why
|
//this only locks the FSM, not the whole instance struct
|
||||||
|
i["status"] = v.Status()
|
||||||
i["software"] = "unknown"
|
i["software"] = "unknown"
|
||||||
i["version"] = "unknown"
|
i["version"] = "unknown"
|
||||||
if v.Identified {
|
if v.Identified {
|
||||||
@ -38,6 +42,14 @@ func (a *Server) instances() []hash {
|
|||||||
v.Unlock()
|
v.Unlock()
|
||||||
resp = append(resp, i)
|
resp = append(resp, i)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, item := range resp {
|
||||||
|
count, err := a.feta.dbm.TootCountForHostname(item["hostname"].(string))
|
||||||
|
item["tootCount"] = 0
|
||||||
|
if err != nil {
|
||||||
|
item["tootCount"] = count
|
||||||
|
}
|
||||||
|
}
|
||||||
return resp
|
return resp
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,10 +87,27 @@ func (a *Server) getInstanceListHandler() http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
func (a *Server) instanceHandler(c echo.Context) error {
|
||||||
|
tu := c.Param("uuid")
|
||||||
|
u, err := uuid.Parse(tu)
|
||||||
|
if err != nil {
|
||||||
|
return c.String(http.StatusNotFound, "404 not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
i := a.feta.manager.ListInstances() {
|
||||||
|
tc := pongo2.Context{
|
||||||
|
"instance": i,
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.Render(http.StatusOK, "instance.html", tc)
|
||||||
|
}
|
||||||
|
|
||||||
func (a *Server) indexHandler(c echo.Context) error {
|
func (a *Server) indexHandler(c echo.Context) error {
|
||||||
tc := pongo2.Context{
|
tc := pongo2.Context{
|
||||||
"time": time.Now().UTC().Format(time.RFC3339Nano),
|
"time": time.Now().UTC().Format(time.RFC3339Nano),
|
||||||
"gitrev": a.feta.version,
|
"gitrev": a.feta.version,
|
||||||
|
"instances": a.instances(),
|
||||||
}
|
}
|
||||||
return c.Render(http.StatusOK, "index.html", tc)
|
return c.Render(http.StatusOK, "index.html", tc)
|
||||||
}
|
}
|
||||||
|
@ -95,6 +95,7 @@ func (s *Server) initRouter() {
|
|||||||
|
|
||||||
// Routes
|
// Routes
|
||||||
s.e.GET("/", s.indexHandler)
|
s.e.GET("/", s.indexHandler)
|
||||||
|
s.e.GET("/instance/:uuid", s.instanceHandler)
|
||||||
s.e.GET("/stats.json", s.statsHandler)
|
s.e.GET("/stats.json", s.statsHandler)
|
||||||
s.e.GET("/.well-known/healthcheck.json", s.healthCheckHandler)
|
s.e.GET("/.well-known/healthcheck.json", s.healthCheckHandler)
|
||||||
//a.e.GET("/about", s.aboutHandler)
|
//a.e.GET("/about", s.aboutHandler)
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
<meta name="author" content="">
|
<meta name="author" content="">
|
||||||
-->
|
-->
|
||||||
<title>{{ htmltitle }}</title>
|
<title>{{ htmltitle }}</title>
|
||||||
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css" integrity="sha384-Bfad6CLCknfcloXFOyFnlgtENryhrpZCe29RTifKEixXQZ38WheV+i/6YWSzkz3V" crossorigin="anonymous">
|
||||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
@ -9,17 +9,25 @@
|
|||||||
<table class="table table-striped table-hover">
|
<table class="table table-striped table-hover">
|
||||||
<thead class="thead-dark">
|
<thead class="thead-dark">
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col">Key</th>
|
<th scope="col">instance id</th>
|
||||||
<th scope="col">Value</th>
|
<th scope="col">hostname</th>
|
||||||
|
<th scope="col">status</th>
|
||||||
|
<th scope="col">tootCount</th>
|
||||||
|
<th scope="col">Detail</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for stat in stats %}
|
{% for instance in instances %}
|
||||||
<tr>
|
<tr>
|
||||||
{{stat.key}}
|
<td><a href="/instance/{{instance.uuid}}">{{instance.uuid}}</a></td>
|
||||||
</tr>
|
<td><a href="https://{{instance.hostname}}">{{instance.hostname}}</a></td>
|
||||||
<tr>
|
<td>{{instance.status}}</td>
|
||||||
{{stat.value}}
|
<td>{{instance.tootCount}}</td>
|
||||||
|
<td><a
|
||||||
|
href="/instance/{{instance.uuid}}"
|
||||||
|
class="btn btn-info">
|
||||||
|
<i class="fab fa-mastodon"></i>
|
||||||
|
</button></td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
Loading…
Reference in New Issue
Block a user