-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
126 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,12 @@ | ||
package metrics | ||
|
||
import ( | ||
"time" | ||
|
||
influxdb2 "github.com/influxdata/influxdb-client-go/v2" | ||
"github.com/influxdata/influxdb-client-go/v2/api" | ||
"github.com/luissimas/zettelkasten-exporter/internal/config" | ||
) | ||
|
||
var influxDB api.WriteAPI | ||
|
||
func ConnectDatabase(cfg config.Config) { | ||
client := influxdb2.NewClient(cfg.InfluxDBURL, string(cfg.InfluxDBToken)) | ||
influxDB = client.WriteAPI(cfg.InfluxDBOrg, cfg.InfluxDBBucket) | ||
type Metrics struct { | ||
NoteCount int | ||
LinkCount int | ||
Notes map[string]NoteMetrics | ||
} | ||
|
||
func RegisterNoteMetric(name string, linkCount int, timestamp time.Time) { | ||
point := influxdb2.NewPoint( | ||
name, | ||
map[string]string{"name": name}, | ||
map[string]interface{}{"link_count": linkCount}, | ||
timestamp, | ||
) | ||
influxDB.WritePoint(point) | ||
type NoteMetrics struct { | ||
Links map[string]int | ||
LinkCount int | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package storage | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/luissimas/zettelkasten-exporter/internal/metrics" | ||
) | ||
|
||
// FakeStorage represents a fake implementation of storage to be used in tests. | ||
type FakeStorage struct{} | ||
|
||
// FakeStorage creates a new `FakeStorage`. | ||
func NewFakeStorage() FakeStorage { | ||
return FakeStorage{} | ||
} | ||
|
||
func (f FakeStorage) WriteMetric(noteName string, metric metrics.NoteMetrics, timestamp time.Time) { | ||
|
||
} | ||
|
||
func (f FakeStorage) IsEmpty() bool { | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package storage | ||
|
||
import ( | ||
"time" | ||
|
||
influxdb2 "github.com/influxdata/influxdb-client-go/v2" | ||
"github.com/influxdata/influxdb-client-go/v2/api" | ||
"github.com/luissimas/zettelkasten-exporter/internal/metrics" | ||
) | ||
|
||
// The measurement name to be used for all metrics within the InfluxDB bucket. | ||
const measurementName = "notes" | ||
|
||
// InfluxDBStorage represents the implementation of a metric storage using InfluxDB. | ||
type InfluxDBStorage struct { | ||
writeAPI api.WriteAPI | ||
queryAPI api.QueryAPI | ||
} | ||
|
||
// NewInfluxDBStorage creates a new `InfluxDBStorage`. | ||
func NewInfluxDBStorage(url, org, bucket, token string) InfluxDBStorage { | ||
client := influxdb2.NewClient(url, string(token)) | ||
writeAPI := client.WriteAPI(org, bucket) | ||
queryAPI := client.QueryAPI(org) | ||
return InfluxDBStorage{writeAPI: writeAPI, queryAPI: queryAPI} | ||
} | ||
|
||
func (i InfluxDBStorage) WriteMetric(noteName string, metric metrics.NoteMetrics, timestamp time.Time) { | ||
point := influxdb2.NewPoint( | ||
measurementName, | ||
map[string]string{"name": noteName}, | ||
map[string]interface{}{"link_count": metric.LinkCount}, | ||
timestamp, | ||
) | ||
i.writeAPI.WritePoint(point) | ||
} | ||
|
||
func (i InfluxDBStorage) IsEmpty() bool { | ||
return false | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package storage | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/luissimas/zettelkasten-exporter/internal/metrics" | ||
) | ||
|
||
// Storage represents a storage for metrics. | ||
type Storage interface { | ||
// WriteMetric writes the note metric to the storage. | ||
WriteMetric(noteName string, metric metrics.NoteMetrics, timestamp time.Time) | ||
// IsEmpty tells if the storage is empty. | ||
IsEmpty() bool | ||
} |