mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: update metrics
This commit is contained in:
@ -22,7 +22,8 @@ import (
|
||||
"github.com/usememos/memos/plugin/telegram"
|
||||
"github.com/usememos/memos/server/integration"
|
||||
"github.com/usememos/memos/server/profile"
|
||||
"github.com/usememos/memos/server/service"
|
||||
"github.com/usememos/memos/server/service/backup"
|
||||
"github.com/usememos/memos/server/service/metric"
|
||||
"github.com/usememos/memos/store"
|
||||
)
|
||||
|
||||
@ -38,7 +39,7 @@ type Server struct {
|
||||
apiV2Service *apiv2.APIV2Service
|
||||
|
||||
// Asynchronous runners.
|
||||
backupRunner *service.BackupRunner
|
||||
backupRunner *backup.BackupRunner
|
||||
telegramBot *telegram.Bot
|
||||
}
|
||||
|
||||
@ -54,7 +55,7 @@ func NewServer(ctx context.Context, profile *profile.Profile, store *store.Store
|
||||
Profile: profile,
|
||||
|
||||
// Asynchronous runners.
|
||||
backupRunner: service.NewBackupRunner(store),
|
||||
backupRunner: backup.NewBackupRunner(store),
|
||||
telegramBot: telegram.NewBotWithHandler(integration.NewTelegramHandler(store)),
|
||||
}
|
||||
|
||||
@ -132,6 +133,7 @@ func (s *Server) Start(ctx context.Context) error {
|
||||
}
|
||||
}()
|
||||
|
||||
metric.Enqueue("server start")
|
||||
return s.e.Start(fmt.Sprintf("%s:%d", s.Profile.Addr, s.Profile.Port))
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package service
|
||||
package backup
|
||||
|
||||
import (
|
||||
"context"
|
||||
@ -13,6 +13,7 @@ import (
|
||||
"github.com/usememos/memos/store"
|
||||
)
|
||||
|
||||
// nolint
|
||||
type BackupRunner struct {
|
||||
Store *store.Store
|
||||
}
|
52
server/service/metric/metric.go
Normal file
52
server/service/metric/metric.go
Normal file
@ -0,0 +1,52 @@
|
||||
package metric
|
||||
|
||||
import (
|
||||
"github.com/posthog/posthog-go"
|
||||
|
||||
"github.com/usememos/memos/server/profile"
|
||||
)
|
||||
|
||||
const (
|
||||
PostHogAPIKey = "phc_YFEi1aqUBW9sX2KDzdvMtK43DNu0mkeoKMKc0EQum2t"
|
||||
)
|
||||
|
||||
var (
|
||||
client *MetricClient
|
||||
)
|
||||
|
||||
// nolint
|
||||
type MetricClient struct {
|
||||
workspaceID string
|
||||
profile *profile.Profile
|
||||
phClient *posthog.Client
|
||||
}
|
||||
|
||||
func NewMetricClient(workspaceID string, profile profile.Profile) (*MetricClient, error) {
|
||||
phClient, err := posthog.NewWithConfig(PostHogAPIKey, posthog.Config{
|
||||
Endpoint: "https://app.posthog.com",
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
client = &MetricClient{
|
||||
workspaceID: workspaceID,
|
||||
profile: &profile,
|
||||
phClient: &phClient,
|
||||
}
|
||||
return client, nil
|
||||
}
|
||||
|
||||
func Enqueue(event string) {
|
||||
if client == nil {
|
||||
return
|
||||
}
|
||||
if client.profile.Mode != "prod" {
|
||||
return
|
||||
}
|
||||
|
||||
// nolint
|
||||
(*client.phClient).Enqueue(posthog.Capture{
|
||||
DistinctId: `memos-` + client.workspaceID,
|
||||
Event: event,
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user