This repository has been archived by the owner on Mar 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
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
7 changed files
with
362 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package crew | ||
|
||
import ( | ||
"sync/atomic" | ||
|
||
"github.com/safing/portbase/api" | ||
"github.com/safing/portbase/metrics" | ||
"github.com/tevino/abool" | ||
) | ||
|
||
var ( | ||
connectOpDurationHistogram *metrics.Histogram | ||
connectOpDownloadDataHistogram *metrics.Histogram | ||
connectOpUploadDataHistogram *metrics.Histogram | ||
|
||
metricsRegistered = abool.New() | ||
) | ||
|
||
func registerMetrics() (err error) { | ||
// Only register metrics once. | ||
if !metricsRegistered.SetToIf(false, true) { | ||
return nil | ||
} | ||
|
||
// Connect Op Stats. | ||
|
||
_, err = metrics.NewGauge( | ||
"spn/op/connect/active/total", | ||
nil, | ||
getActiveConnectOpsStat, | ||
&metrics.Options{ | ||
Name: "SPN Active Connect Operations", | ||
Permission: api.PermitUser, | ||
}, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
connectOpDurationHistogram, err = metrics.NewHistogram( | ||
"spn/op/connect/duration/seconds", | ||
nil, | ||
&metrics.Options{ | ||
Name: "SPN Connect Operation Duration", | ||
Permission: api.PermitUser, | ||
}, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
connectOpDownloadDataHistogram, err = metrics.NewHistogram( | ||
"spn/op/connect/download/bytes", | ||
nil, | ||
&metrics.Options{ | ||
Name: "SPN Connect Operation Downloaded Data", | ||
Permission: api.PermitUser, | ||
}, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
connectOpUploadDataHistogram, err = metrics.NewHistogram( | ||
"spn/op/connect/upload/bytes", | ||
nil, | ||
&metrics.Options{ | ||
Name: "SPN Connect Operation Uploaded Data", | ||
Permission: api.PermitUser, | ||
}, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return err | ||
} | ||
|
||
func getActiveConnectOpsStat() float64 { | ||
return float64(atomic.LoadInt64(activeConnectOps)) | ||
} |
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
Oops, something went wrong.