diff options
| author | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2022-06-08 20:54:07 -0700 |
|---|---|---|
| committer | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2022-06-08 20:54:07 -0700 |
| commit | 23411fc23dcf82e0ed35a780bfdda2341bedf819 (patch) | |
| tree | e29a32ec6a387c2943d1b52bc3b8b5861600a639 /hotline | |
| parent | ba29c43bb23de83c7715271e0830cb9f00e9e1c1 (diff) | |
Add flag to enable optional stats HTTP endpoint
re: #29
TODO: add more stat counters
Usage:
```
./mobius-hotline-server -stats-port 5503
```
```
❯ curl -s localhost:5503 | jq .
{
"LoginCount": 0,
"StartTime": "2022-06-08T20:49:10.183921-07:00",
"DownloadCounter": 0,
"UploadCounter": 0
}
```
Diffstat (limited to 'hotline')
| -rw-r--r-- | hotline/server.go | 8 | ||||
| -rw-r--r-- | hotline/stats.go | 7 |
2 files changed, 10 insertions, 5 deletions
diff --git a/hotline/server.go b/hotline/server.go index 1a6d163..76cc248 100644 --- a/hotline/server.go +++ b/hotline/server.go @@ -693,6 +693,8 @@ func (s *Server) handleFileTransfer(conn io.ReadWriteCloser) error { switch fileTransfer.Type { case FileDownload: + s.Stats.DownloadCounter += 1 + fullFilePath, err := readPath(s.Config.FileRoot, fileTransfer.FilePath, fileTransfer.FileName) if err != nil { return err @@ -744,6 +746,8 @@ func (s *Server) handleFileTransfer(conn io.ReadWriteCloser) error { } } case FileUpload: + s.Stats.UploadCounter += 1 + destinationFile := s.Config.FileRoot + ReadFilePath(fileTransfer.FilePath) + "/" + string(fileTransfer.FileName) var file *os.File @@ -829,6 +833,8 @@ func (s *Server) handleFileTransfer(conn io.ReadWriteCloser) error { i := 0 err = filepath.Walk(fullFilePath+"/", func(path string, info os.FileInfo, err error) error { + s.Stats.DownloadCounter += 1 + if err != nil { return err } @@ -1039,8 +1045,6 @@ func (s *Server) handleFileTransfer(conn io.ReadWriteCloser) error { nextAction = dlFldrActionResumeFile } - fmt.Printf("Next Action: %v\n", nextAction) - if _, err := conn.Write([]byte{0, uint8(nextAction)}); err != nil { return err } diff --git a/hotline/stats.go b/hotline/stats.go index dd8ea1d..4b9119d 100644 --- a/hotline/stats.go +++ b/hotline/stats.go @@ -6,9 +6,10 @@ import ( ) type Stats struct { - LoginCount int `yaml:"login count"` - StartTime time.Time `yaml:"start time"` - Uptime time.Duration `yaml:"uptime"` + LoginCount int `yaml:"login count"` + StartTime time.Time `yaml:"start time"` + DownloadCounter int + UploadCounter int } func (s *Stats) String() string { |