Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.
Go dockerfossgomarkdownmemomicroblognote-takingnotesopen-sourceown-your-datareactself-hostedsqlitetimeline
chore: update metrics
Stevena5df36eff229
diff --git a/api/v1/memo.go b/api/v1/memo.goindex ddd434111..061389779 100644--- a/api/v1/memo.go+++ b/api/v1/memo.go@@ -14,6 +14,7 @@ import ("github.com/usememos/memos/common/log""github.com/usememos/memos/common/util"+ "github.com/usememos/memos/server/service/metric""github.com/usememos/memos/store")@@ -387,6 +388,7 @@ func (s *APIV1Service) CreateMemo(c echo.Context) error {}}}+ metric.Enqueue("memo create")return c.JSON(http.StatusOK, memoResponse)}diff --git a/api/v1/user.go b/api/v1/user.goindex 0b20c7cae..17d314371 100644--- a/api/v1/user.go+++ b/api/v1/user.go@@ -12,6 +12,7 @@ import ("golang.org/x/crypto/bcrypt""github.com/usememos/memos/common/util"+ "github.com/usememos/memos/server/service/metric""github.com/usememos/memos/store")@@ -169,6 +170,7 @@ func (s *APIV1Service) CreateUser(c echo.Context) error {if err := s.createUserCreateActivity(c, userMessage); err != nil {return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create activity").SetInternal(err)}+ metric.Enqueue("user create")return c.JSON(http.StatusOK, userMessage)}diff --git a/cmd/memos.go b/cmd/memos.goindex 1717005e3..f972415c0 100644--- a/cmd/memos.go+++ b/cmd/memos.go@@ -15,6 +15,7 @@ import ("github.com/usememos/memos/common/log""github.com/usememos/memos/server"_profile "github.com/usememos/memos/server/profile"+ "github.com/usememos/memos/server/service/metric""github.com/usememos/memos/store""github.com/usememos/memos/store/db")@@ -64,6 +65,9 @@ var (return}+ // nolint+ metric.NewMetricClient(s.ID, *profile)+c := make(chan os.Signal, 1)// Trigger graceful shutdown on SIGINT or SIGTERM.// The default signal sent by the `kill` command is SIGTERM,diff --git a/go.mod b/go.modindex e78657c6f..458df8fcf 100644--- a/go.mod+++ b/go.mod@@ -106,6 +106,7 @@ require (github.com/mitchellh/mapstructure v1.5.0 // indirectgithub.com/pelletier/go-toml/v2 v2.1.0 // indirectgithub.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect+ github.com/posthog/posthog-go v0.0.0-20230801140217-d607812dee69github.com/spf13/afero v1.10.0 // indirectgithub.com/spf13/cast v1.5.1 // indirectgithub.com/spf13/pflag v1.0.5 // indirectdiff --git a/go.sum b/go.sumindex a9413987d..89e42768c 100644--- a/go.sum+++ b/go.sum@@ -284,6 +284,7 @@ github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26/go.mod h1:dDKJzRmX4S3github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=+github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=@@ -474,6 +475,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNgithub.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=+github.com/posthog/posthog-go v0.0.0-20230801140217-d607812dee69 h1:01dHVodha5BzrMtVmcpPeA4VYbZEsTXQ6m4123zQXJk=+github.com/posthog/posthog-go v0.0.0-20230801140217-d607812dee69/go.mod h1:migYMxlAqcnQy+3eN8mcL0b2tpKy6R+8Zc0lxwk4dKM=github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs=github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=@@ -573,6 +576,7 @@ github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSsgithub.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=+github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=diff --git a/server/server.go b/server/server.goindex 326c27708..fc2aff1ef 100644--- a/server/server.go+++ b/server/server.go@@ -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.BackupRunnertelegramBot *telegram.Bot}@@ -54,7 +55,7 @@ func NewServer(ctx context.Context, profile *profile.Profile, store *store.StoreProfile: 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))}diff --git a/server/service/backup.go b/server/service/backup/backup.gosimilarity index 98%rename from server/service/backup.gorename to server/service/backup/backup.goindex ade63e866..9f0739162 100644--- a/server/service/backup.go+++ b/server/service/backup/backup.go@@ -1,4 +1,4 @@-package service+package backupimport ("context"@@ -13,6 +13,7 @@ import ("github.com/usememos/memos/store")+// nolinttype BackupRunner struct {Store *store.Store}diff --git a/server/service/metric/metric.go b/server/service/metric/metric.gonew file mode 100644index 000000000..504dc1e37--- /dev/null+++ b/server/service/metric/metric.go@@ -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,+ })+}