From 30bb5f3a5bf715360aaa80bfd3339fe5cf22d0ab Mon Sep 17 00:00:00 2001 From: Espen Braastad Date: Sat, 11 Nov 2023 16:46:02 +0100 Subject: [PATCH] Add instance id --- README.md | 12 ++++++++ ds/metrics.go | 1 + main.go | 2 ++ templates/metrics.html | 64 +++++++++++++++++++++++++++--------------- 4 files changed, 56 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 1f1f0642..c66a0f32 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,18 @@ If this argument is set, then the administrator needs to manually approve new bi The API request used to approve a bin is an authenticated `PUT /admin/approve/{bin}` +#### `--metrics-username` (default: not set) + +The username used for authentication to the `/metrics` endpoint for Prometheus metrics. If the username is not set, this endpoint is disabled. + +#### `--metrics-password` (default: not set) + +The password used for authentication to the `/metrics` endpoint for Prometheus metrics. If the username is not set, this endpoint is disabled. + +#### `--metrics-id` (default: hostname) + +The string used as the identification of the filebin instance in the Prometheus metrics. By default, this string is the `$HOSTNAME` environment variable. + #### `--mmdb string` (default: not set) The path to an mmdb formatted geoip database like GeoLite2-City.mmdb. This is optional. diff --git a/ds/metrics.go b/ds/metrics.go index ed571035..2ac56d8e 100644 --- a/ds/metrics.go +++ b/ds/metrics.go @@ -6,6 +6,7 @@ import ( ) type Metrics struct { + Id string `json:"-"` CurrentLogEntries int64 `json:"current_log_entries"` CurrentBytes int64 `json:"current_bytes"` CurrentBytesReadable string `json:"current_bytes_readable"` diff --git a/main.go b/main.go index aba4a459..e45cc75a 100644 --- a/main.go +++ b/main.go @@ -66,6 +66,7 @@ var ( adminPasswordFlag = flag.String("admin-password", "", "Admin password") metricsUsernameFlag = flag.String("metrics-username", "", "Metrics username") metricsPasswordFlag = flag.String("metrics-password", "", "Metrics password") + metricsIdFlag = flag.String("metrics-id", os.Getenv("HOSTNAME"), "Metrics identification") // Slack integration slackSecretFlag = flag.String("slack-secret", "", "Slack secret (currently used to approve new bins via Slack if manual approval is enabled)") @@ -203,6 +204,7 @@ func main() { } config.LimitStorageReadable = humanize.Bytes(config.LimitStorageBytes) metrics := ds.Metrics{} + metrics.Id = *metricsIdFlag h := &HTTP{ staticBox: &staticBox, diff --git a/templates/metrics.html b/templates/metrics.html index 289512c8..a8b4dab8 100644 --- a/templates/metrics.html +++ b/templates/metrics.html @@ -1,51 +1,69 @@ -{{ define "metrics" }}HELP data_transfer Approximate data transfer in bytes +{{ define "metrics" }}HELP data_transfer Approximate data transfer from clients to filebin in bytes, measured by file size TYPE data_transfer counter -data_transfer{direction="client-to-filebin"} {{ .BytesClientToFilebin }} -data_transfer{direction="filebin-to-storage"} {{ .BytesFilebinToStorage }} -data_transfer{direction="storage-to-client"} {{ .BytesStorageToClient }} -data_transfer{direction="storage-to-filebin"} {{ .BytesStorageToFilebin }} -data_transfer{direction="filebin-to-client"} {{ .BytesFilebinToClient }} +data_transfer{instance="{{ .Id }}", direction="client-to-filebin"} {{ .BytesClientToFilebin }} + +HELP data_transfer Approximate data transfer from filebin to the storage in bytes, measured by file size +TYPE data_transfer counter +data_transfer{instance="{{ .Id }}", direction="filebin-to-storage"} {{ .BytesFilebinToStorage }} + +HELP data_transfer Approximate data transfer from the storage to the clients in bytes, measured by file size assuming that all file downloads are complete +TYPE data_transfer counter +data_transfer{instance="{{ .Id }}", direction="storage-to-client"} {{ .BytesStorageToClient }} + +HELP data_transfer Approximate data transfer from the storage to the filebin in bytes, measured by file size of files in archive downloads +TYPE data_transfer counter +data_transfer{instance="{{ .Id }}", direction="storage-to-filebin"} {{ .BytesStorageToFilebin }} + +HELP data_transfer Approximate data transfer from filebin to clients in bytes, measured by file size of files in archive downloads +TYPE data_transfer counter +data_transfer{instance="{{ .Id }}", direction="filebin-to-client"} {{ .BytesFilebinToClient }} HELP file_operations Number of file operations TYPE file_operations counter -file_operations{operation="upload"} {{ .FileUploadCount }} -file_operations{operation="download"} {{ .FileDownloadCount }} -file_operations{operation="delete" {{ .FileDeleteCount }} +file_operations{instance="{{ .Id }}", operation="upload"} {{ .FileUploadCount }} +file_operations{instance="{{ .Id }}", operation="download"} {{ .FileDownloadCount }} +file_operations{instance="{{ .Id }}", operation="delete" {{ .FileDeleteCount }} HELP bin_operations Number of bin operations TYPE bin_operations counter -bin_operations{operation="delete"} {{ .BinDeleteCount }} -bin_operations{operation="create"} {{ .NewBinCount }} +bin_operations{instance="{{ .Id }}", operation="delete"} {{ .BinDeleteCount }} +bin_operations{instance="{{ .Id }}", operation="create"} {{ .NewBinCount }} HELP archive_downloads Number of archive downloads TYPE archive_downloads counter -archive_downloads{format="tar"} {{ .TarArchiveDownloadCount }} -archive_downloads{format="zip"} {{ .ZipArchiveDownloadCount }} +archive_downloads{instance="{{ .Id }}", format="tar"} {{ .TarArchiveDownloadCount }} +archive_downloads{instance="{{ .Id }}", format="zip"} {{ .ZipArchiveDownloadCount }} HELP page_views Number of page views TYPE page_views counter -page_views{page="front"} {{ .FrontPageViewCount }} -page_views{page="bin"} {{ .BinPageViewCount }} +page_views{instance="{{ .Id }}", page="front"} {{ .FrontPageViewCount }} +page_views{instance="{{ .Id }}", page="bin"} {{ .BinPageViewCount }} + +HELP operations_in_progress Number of file uploads from clients to filebin currently in progress +TYPE operations_in_progress gauge +operations_in_progress{instance="{{ .Id }}", operation="file-upload"} {{ .FileUploadInProgress }} + +HELP operations_in_progress Number of file uploads from filebin to storage currently in progress +TYPE operations_in_progress gauge +operations_in_progress{instance="{{ .Id }}", operation="storage-upload"} {{ .StorageUploadInProgress }} -HELP operations_in_progress Number of operations currently in progress +HELP operations_in_progress Number of archive downloads from filebin to clients currently in progress TYPE operations_in_progress gauge -operations_in_progress{operation="file-upload"} {{ .FileUploadInProgress }} -operations_in_progress{operation="storage-upload"} {{ .StorageUploadInProgress }} -operations_in_progress{operation="archive-download"} {{ .ArchiveDownloadInProgress }} +operations_in_progress{instance="{{ .Id }}", operation="archive-download"} {{ .ArchiveDownloadInProgress }} HELP transactions Number of transactions logged in the database TYPE transactions gauge -transactions{} {{ .CurrentLogEntries }} +transactions{instance="{{ .Id }}"} {{ .CurrentLogEntries }} HELP storage_used The number of bytes consumed by the files in storage TYPE storage_used gauge -storage_used{} {{ .CurrentBytes }} +storage_used{instance="{{ .Id }}"} {{ .CurrentBytes }} HELP file_count The number of files in storage TYPE file_count gauge -file_count{} {{ .CurrentFiles }} +file_count{instance="{{ .Id }}"} {{ .CurrentFiles }} HELP bin_count The number of bins active TYPE bin_count gauge -bin_count{} {{ .CurrentBins }} +bin_count{instance="{{ .Id }}"} {{ .CurrentBins }} {{ end }}