diff --git a/database/all/internal.go b/database/all/internal.go index 9e261e1..ddaefc8 100644 --- a/database/all/internal.go +++ b/database/all/internal.go @@ -42,9 +42,9 @@ func (conn *Connection) AddStatistics(stats *runtime.GlobalStats, time time.Time } } -func (conn *Connection) DeleteNode(deleteAfter time.Duration) { +func (conn *Connection) PruneNodes(deleteAfter time.Duration) { for _, item := range conn.list { - item.DeleteNode(deleteAfter) + item.PruneNodes(deleteAfter) } } diff --git a/database/database.go b/database/database.go index a23a004..dbdae7d 100644 --- a/database/database.go +++ b/database/database.go @@ -8,24 +8,25 @@ import ( // Connection interface to use for implementation in e.g. influxdb type Connection interface { - // AddNode data for a single node + // AddNode stores data of a single node AddNode(nodeID string, node *runtime.Node) + + // AddStatistics stores global statistics AddStatistics(stats *runtime.GlobalStats, time time.Time) - DeleteNode(deleteAfter time.Duration) + // PruneNodes prunes historical per-node data + PruneNodes(deleteAfter time.Duration) + // Close closes the database connection Close() } // Connect function with config to get DB connection interface type Connect func(config interface{}) (Connection, error) -/* - * for selfbinding in use of the package all - */ - +// Adapters is the list of registered database adapters var Adapters = map[string]Connect{} -func AddDatabaseType(name string, n Connect) { +func RegisterAdapter(name string, n Connect) { Adapters[name] = n } diff --git a/database/influxdb/database.go b/database/influxdb/database.go index b509a78..b168308 100644 --- a/database/influxdb/database.go +++ b/database/influxdb/database.go @@ -49,7 +49,7 @@ func (c Config) Password() string { } func init() { - database.AddDatabaseType("influxdb", Connect) + database.RegisterAdapter("influxdb", Connect) } func Connect(configuration interface{}) (database.Connection, error) { var config Config @@ -80,7 +80,7 @@ func Connect(configuration interface{}) (database.Connection, error) { return db, nil } -func (conn *Connection) DeleteNode(deleteAfter time.Duration) { +func (conn *Connection) PruneNodes(deleteAfter time.Duration) { query := fmt.Sprintf("delete from %s where time < now() - %ds", MeasurementNode, deleteAfter/time.Second) conn.client.Query(client.NewQuery(query, conn.config.Database(), "m")) } diff --git a/database/internal.go b/database/internal.go index 2a0aa94..5a5eb1c 100644 --- a/database/internal.go +++ b/database/internal.go @@ -31,7 +31,7 @@ func deleteWorker(conn Connection, deleteInterval time.Duration, deleteAfter tim for { select { case <-ticker.C: - conn.DeleteNode(deleteAfter) + conn.PruneNodes(deleteAfter) case <-quit: ticker.Stop() return diff --git a/database/logging/file.go b/database/logging/file.go index cfc5790..910a4d0 100644 --- a/database/logging/file.go +++ b/database/logging/file.go @@ -31,7 +31,7 @@ func (c Config) Path() string { } func init() { - database.AddDatabaseType("logging", Connect) + database.RegisterAdapter("logging", Connect) } func Connect(configuration interface{}) (database.Connection, error) { @@ -56,8 +56,8 @@ func (conn *Connection) AddStatistics(stats *runtime.GlobalStats, time time.Time conn.log("AddStatistics: [", time.String(), "] nodes: ", stats.Nodes, ", clients: ", stats.Clients, " models: ", len(stats.Models)) } -func (conn *Connection) DeleteNode(deleteAfter time.Duration) { - conn.log("DeleteNode") +func (conn *Connection) PruneNodes(deleteAfter time.Duration) { + conn.log("PruneNodes") } func (conn *Connection) Close() {