mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-06 22:30:56 +03:00
add build tag to disable metrics
This commit is contained in:
@@ -16,7 +16,7 @@ import (
|
|||||||
"github.com/drakkan/sftpgo/dataprovider"
|
"github.com/drakkan/sftpgo/dataprovider"
|
||||||
"github.com/drakkan/sftpgo/service"
|
"github.com/drakkan/sftpgo/service"
|
||||||
"github.com/drakkan/sftpgo/sftpd"
|
"github.com/drakkan/sftpgo/sftpd"
|
||||||
"github.com/drakkan/sftpgo/utils"
|
"github.com/drakkan/sftpgo/version"
|
||||||
"github.com/drakkan/sftpgo/vfs"
|
"github.com/drakkan/sftpgo/vfs"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -141,7 +141,7 @@ Please take a look at the usage below to customize the serving parameters`,
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
utils.AddFeature("+portable")
|
version.AddFeature("+portable")
|
||||||
|
|
||||||
portableCmd.Flags().StringVarP(&directoryToServe, "directory", "d", ".",
|
portableCmd.Flags().StringVarP(&directoryToServe, "directory", "d", ".",
|
||||||
"Path to the directory to serve. This can be an absolute path or a path relative to the current directory")
|
"Path to the directory to serve. This can be an absolute path or a path relative to the current directory")
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import "github.com/drakkan/sftpgo/utils"
|
import "github.com/drakkan/sftpgo/version"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
utils.AddFeature("-portable")
|
version.AddFeature("-portable")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
"github.com/drakkan/sftpgo/config"
|
"github.com/drakkan/sftpgo/config"
|
||||||
"github.com/drakkan/sftpgo/utils"
|
"github.com/drakkan/sftpgo/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -60,9 +60,8 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
version := utils.GetAppVersion()
|
|
||||||
rootCmd.Flags().BoolP("version", "v", false, "")
|
rootCmd.Flags().BoolP("version", "v", false, "")
|
||||||
rootCmd.Version = version.GetVersionAsString()
|
rootCmd.Version = version.GetAsString()
|
||||||
rootCmd.SetVersionTemplate(`{{printf "SFTPGo "}}{{printf "%s" .Version}}
|
rootCmd.SetVersionTemplate(`{{printf "SFTPGo "}}{{printf "%s" .Version}}
|
||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import (
|
|||||||
"github.com/drakkan/sftpgo/logger"
|
"github.com/drakkan/sftpgo/logger"
|
||||||
"github.com/drakkan/sftpgo/sftpd"
|
"github.com/drakkan/sftpgo/sftpd"
|
||||||
"github.com/drakkan/sftpgo/utils"
|
"github.com/drakkan/sftpgo/utils"
|
||||||
|
"github.com/drakkan/sftpgo/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -31,7 +32,7 @@ const (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
globalConf globalConfig
|
globalConf globalConfig
|
||||||
defaultBanner = fmt.Sprintf("SFTPGo_%v", utils.GetAppVersion().Version)
|
defaultBanner = fmt.Sprintf("SFTPGo_%v", version.Get().Version)
|
||||||
)
|
)
|
||||||
|
|
||||||
type globalConfig struct {
|
type globalConfig struct {
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
|
|
||||||
"github.com/drakkan/sftpgo/logger"
|
"github.com/drakkan/sftpgo/logger"
|
||||||
"github.com/drakkan/sftpgo/utils"
|
"github.com/drakkan/sftpgo/utils"
|
||||||
|
"github.com/drakkan/sftpgo/version"
|
||||||
"github.com/drakkan/sftpgo/vfs"
|
"github.com/drakkan/sftpgo/vfs"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -57,7 +58,7 @@ type compatUserV2 struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
utils.AddFeature("+bolt")
|
version.AddFeature("+bolt")
|
||||||
}
|
}
|
||||||
|
|
||||||
func initializeBoltProvider(basePath string) error {
|
func initializeBoltProvider(basePath string) error {
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ package dataprovider
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/drakkan/sftpgo/utils"
|
"github.com/drakkan/sftpgo/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
utils.AddFeature("-bolt")
|
version.AddFeature("-bolt")
|
||||||
}
|
}
|
||||||
|
|
||||||
func initializeBoltProvider(basePath string) error {
|
func initializeBoltProvider(basePath string) error {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import (
|
|||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
|
||||||
"github.com/drakkan/sftpgo/logger"
|
"github.com/drakkan/sftpgo/logger"
|
||||||
"github.com/drakkan/sftpgo/utils"
|
"github.com/drakkan/sftpgo/version"
|
||||||
"github.com/drakkan/sftpgo/vfs"
|
"github.com/drakkan/sftpgo/vfs"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ type MySQLProvider struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
utils.AddFeature("+mysql")
|
version.AddFeature("+mysql")
|
||||||
}
|
}
|
||||||
|
|
||||||
func initializeMySQLProvider() error {
|
func initializeMySQLProvider() error {
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ package dataprovider
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/drakkan/sftpgo/utils"
|
"github.com/drakkan/sftpgo/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
utils.AddFeature("-mysql")
|
version.AddFeature("-mysql")
|
||||||
}
|
}
|
||||||
|
|
||||||
func initializeMySQLProvider() error {
|
func initializeMySQLProvider() error {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
_ "github.com/lib/pq"
|
_ "github.com/lib/pq"
|
||||||
|
|
||||||
"github.com/drakkan/sftpgo/logger"
|
"github.com/drakkan/sftpgo/logger"
|
||||||
"github.com/drakkan/sftpgo/utils"
|
"github.com/drakkan/sftpgo/version"
|
||||||
"github.com/drakkan/sftpgo/vfs"
|
"github.com/drakkan/sftpgo/vfs"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ type PGSQLProvider struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
utils.AddFeature("+pgsql")
|
version.AddFeature("+pgsql")
|
||||||
}
|
}
|
||||||
|
|
||||||
func initializePGSQLProvider() error {
|
func initializePGSQLProvider() error {
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ package dataprovider
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/drakkan/sftpgo/utils"
|
"github.com/drakkan/sftpgo/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
utils.AddFeature("-pgsql")
|
version.AddFeature("-pgsql")
|
||||||
}
|
}
|
||||||
|
|
||||||
func initializePGSQLProvider() error {
|
func initializePGSQLProvider() error {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
|
|
||||||
"github.com/drakkan/sftpgo/logger"
|
"github.com/drakkan/sftpgo/logger"
|
||||||
"github.com/drakkan/sftpgo/utils"
|
"github.com/drakkan/sftpgo/utils"
|
||||||
|
"github.com/drakkan/sftpgo/version"
|
||||||
"github.com/drakkan/sftpgo/vfs"
|
"github.com/drakkan/sftpgo/vfs"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -69,7 +70,7 @@ type SQLiteProvider struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
utils.AddFeature("+sqlite")
|
version.AddFeature("+sqlite")
|
||||||
}
|
}
|
||||||
|
|
||||||
func initializeSQLiteProvider(basePath string) error {
|
func initializeSQLiteProvider(basePath string) error {
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ package dataprovider
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/drakkan/sftpgo/utils"
|
"github.com/drakkan/sftpgo/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
utils.AddFeature("-sqlite")
|
version.AddFeature("-sqlite")
|
||||||
}
|
}
|
||||||
|
|
||||||
func initializeSQLiteProvider(basePath string) error {
|
func initializeSQLiteProvider(basePath string) error {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ ARG TAG
|
|||||||
ARG FEATURES
|
ARG FEATURES
|
||||||
# Use --build-arg TAG=LATEST for latest tag. Use e.g. --build-arg TAG=0.9.6 for a specific tag/commit. Otherwise HEAD (master) is built.
|
# Use --build-arg TAG=LATEST for latest tag. Use e.g. --build-arg TAG=0.9.6 for a specific tag/commit. Otherwise HEAD (master) is built.
|
||||||
RUN git checkout $(if [ "${TAG}" = LATEST ]; then echo `git rev-list --tags --max-count=1`; elif [ -n "${TAG}" ]; then echo "${TAG}"; else echo HEAD; fi)
|
RUN git checkout $(if [ "${TAG}" = LATEST ]; then echo `git rev-list --tags --max-count=1`; elif [ -n "${TAG}" ]; then echo "${TAG}"; else echo HEAD; fi)
|
||||||
RUN go build -i $(if [ -n "${FEATURES}" ]; then echo "-tags ${FEATURES}"; fi) -ldflags "-s -w -X github.com/drakkan/sftpgo/utils.commit=`git describe --always --dirty` -X github.com/drakkan/sftpgo/utils.date=`date -u +%FT%TZ`" -o /go/bin/sftpgo
|
RUN go build -i $(if [ -n "${FEATURES}" ]; then echo "-tags ${FEATURES}"; fi) -ldflags "-s -w -X github.com/drakkan/sftpgo/version.commit=`git describe --always --dirty` -X github.com/drakkan/sftpgo/version.date=`date -u +%FT%TZ`" -o /go/bin/sftpgo
|
||||||
|
|
||||||
FROM alpine:latest
|
FROM alpine:latest
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ ARG TAG
|
|||||||
ARG FEATURES
|
ARG FEATURES
|
||||||
# Use --build-arg TAG=LATEST for latest tag. Use e.g. --build-arg TAG=0.9.6 for a specific tag/commit. Otherwise HEAD (master) is built.
|
# Use --build-arg TAG=LATEST for latest tag. Use e.g. --build-arg TAG=0.9.6 for a specific tag/commit. Otherwise HEAD (master) is built.
|
||||||
RUN git checkout $(if [ "${TAG}" = LATEST ]; then echo `git rev-list --tags --max-count=1`; elif [ -n "${TAG}" ]; then echo "${TAG}"; else echo HEAD; fi)
|
RUN git checkout $(if [ "${TAG}" = LATEST ]; then echo `git rev-list --tags --max-count=1`; elif [ -n "${TAG}" ]; then echo "${TAG}"; else echo HEAD; fi)
|
||||||
RUN go build -i $(if [ -n "${FEATURES}" ]; then echo "-tags ${FEATURES}"; fi) -ldflags "-s -w -X github.com/drakkan/sftpgo/utils.commit=`git describe --always --dirty` -X github.com/drakkan/sftpgo/utils.date=`date -u +%FT%TZ`" -o sftpgo
|
RUN go build -i $(if [ -n "${FEATURES}" ]; then echo "-tags ${FEATURES}"; fi) -ldflags "-s -w -X github.com/drakkan/sftpgo/version.commit=`git describe --always --dirty` -X github.com/drakkan/sftpgo/version.date=`date -u +%FT%TZ`" -o sftpgo
|
||||||
|
|
||||||
# now define the run environment
|
# now define the run environment
|
||||||
FROM debian:latest
|
FROM debian:latest
|
||||||
|
|||||||
@@ -11,12 +11,13 @@ Make sure [Git](https://git-scm.com/downloads) is installed on your machine and
|
|||||||
The following build tags are available:
|
The following build tags are available:
|
||||||
|
|
||||||
- `nogcs`, disable Google Cloud Storage backend, default enabled
|
- `nogcs`, disable Google Cloud Storage backend, default enabled
|
||||||
- `nos3`, disable S3 Compabible Object Storage backends, , default enabled
|
- `nos3`, disable S3 Compabible Object Storage backends, default enabled
|
||||||
- `nobolt`, disable Bolt data provider, , default enabled
|
- `nobolt`, disable Bolt data provider, default enabled
|
||||||
- `nomysql`, disable MySQL data provider, default enabled
|
- `nomysql`, disable MySQL data provider, default enabled
|
||||||
- `nopgsql`, disable PostgreSQL data provider, default enabled
|
- `nopgsql`, disable PostgreSQL data provider, default enabled
|
||||||
- `nosqlite`, disable SQLite data provider, default enabled
|
- `nosqlite`, disable SQLite data provider, default enabled
|
||||||
- `noportable`, disable portable mode, default enabled
|
- `noportable`, disable portable mode, default enabled
|
||||||
|
- `nometrics`, disable Prometheus metrics, default enabled
|
||||||
|
|
||||||
If no build tag is specified the build will include the default features.
|
If no build tag is specified the build will include the default features.
|
||||||
|
|
||||||
@@ -27,18 +28,18 @@ The compiler is a build time only dependency. It is not required at runtime.
|
|||||||
|
|
||||||
Version info, such as git commit and build date, can be embedded setting the following string variables at build time:
|
Version info, such as git commit and build date, can be embedded setting the following string variables at build time:
|
||||||
|
|
||||||
- `github.com/drakkan/sftpgo/utils.commit`
|
- `github.com/drakkan/sftpgo/version.commit`
|
||||||
- `github.com/drakkan/sftpgo/utils.date`
|
- `github.com/drakkan/sftpgo/version.date`
|
||||||
|
|
||||||
For example, you can build using the following command:
|
For example, you can build using the following command:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
go build -i -tags nogcs,nos3,nosqlite -ldflags "-s -w -X github.com/drakkan/sftpgo/utils.commit=`git describe --always --dirty` -X github.com/drakkan/sftpgo/utils.date=`date -u +%FT%TZ`" -o sftpgo
|
go build -i -tags nogcs,nos3,nosqlite -ldflags "-s -w -X github.com/drakkan/sftpgo/version.commit=`git describe --always --dirty` -X github.com/drakkan/sftpgo/version.date=`date -u +%FT%TZ`" -o sftpgo
|
||||||
```
|
```
|
||||||
|
|
||||||
You should get a version that includes git commit, build date and available features like this one:
|
You should get a version that includes git commit, build date and available features like this one:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ ./sftpgo -v
|
$ ./sftpgo -v
|
||||||
SFTPGo 0.9.6-dev-15298b0-dirty-2020-05-22T21:25:51Z -gcs -s3 +bolt +mysql +pgsql -sqlite +portable
|
SFTPGo 0.9.6-dev-b30614e-dirty-2020-06-19T11:04:56Z +metrics -gcs -s3 +bolt +mysql +pgsql -sqlite +portable
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import (
|
|||||||
"github.com/drakkan/sftpgo/httpclient"
|
"github.com/drakkan/sftpgo/httpclient"
|
||||||
"github.com/drakkan/sftpgo/sftpd"
|
"github.com/drakkan/sftpgo/sftpd"
|
||||||
"github.com/drakkan/sftpgo/utils"
|
"github.com/drakkan/sftpgo/utils"
|
||||||
|
"github.com/drakkan/sftpgo/version"
|
||||||
"github.com/drakkan/sftpgo/vfs"
|
"github.com/drakkan/sftpgo/vfs"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -370,21 +371,21 @@ func StartFolderQuotaScan(folder vfs.BaseVirtualFolder, expectedStatusCode int)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetVersion returns version details
|
// GetVersion returns version details
|
||||||
func GetVersion(expectedStatusCode int) (utils.VersionInfo, []byte, error) {
|
func GetVersion(expectedStatusCode int) (version.Info, []byte, error) {
|
||||||
var version utils.VersionInfo
|
var appVersion version.Info
|
||||||
var body []byte
|
var body []byte
|
||||||
resp, err := sendHTTPRequest(http.MethodGet, buildURLRelativeToBase(versionPath), nil, "")
|
resp, err := sendHTTPRequest(http.MethodGet, buildURLRelativeToBase(versionPath), nil, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return version, body, err
|
return appVersion, body, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
err = checkResponse(resp.StatusCode, expectedStatusCode)
|
err = checkResponse(resp.StatusCode, expectedStatusCode)
|
||||||
if err == nil && expectedStatusCode == http.StatusOK {
|
if err == nil && expectedStatusCode == http.StatusOK {
|
||||||
err = render.DecodeJSON(resp.Body, &version)
|
err = render.DecodeJSON(resp.Body, &appVersion)
|
||||||
} else {
|
} else {
|
||||||
body, _ = getResponseBody(resp)
|
body, _ = getResponseBody(resp)
|
||||||
}
|
}
|
||||||
return version, body, err
|
return appVersion, body, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetProviderStatus returns provider status
|
// GetProviderStatus returns provider status
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import (
|
|||||||
"github.com/drakkan/sftpgo/logger"
|
"github.com/drakkan/sftpgo/logger"
|
||||||
"github.com/drakkan/sftpgo/metrics"
|
"github.com/drakkan/sftpgo/metrics"
|
||||||
"github.com/drakkan/sftpgo/sftpd"
|
"github.com/drakkan/sftpgo/sftpd"
|
||||||
"github.com/drakkan/sftpgo/utils"
|
"github.com/drakkan/sftpgo/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetHTTPRouter returns the configured HTTP handler
|
// GetHTTPRouter returns the configured HTTP handler
|
||||||
@@ -55,7 +55,7 @@ func initializeRouter(staticFilesPath string, enableProfiler, enableWebAdmin boo
|
|||||||
metrics.AddMetricsEndpoint(metricsPath, router)
|
metrics.AddMetricsEndpoint(metricsPath, router)
|
||||||
|
|
||||||
router.Get(versionPath, func(w http.ResponseWriter, r *http.Request) {
|
router.Get(versionPath, func(w http.ResponseWriter, r *http.Request) {
|
||||||
render.JSON(w, r, utils.GetAppVersion())
|
render.JSON(w, r, version.Get())
|
||||||
})
|
})
|
||||||
|
|
||||||
router.Get(providerStatusPath, func(w http.ResponseWriter, r *http.Request) {
|
router.Get(providerStatusPath, func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import (
|
|||||||
"github.com/drakkan/sftpgo/dataprovider"
|
"github.com/drakkan/sftpgo/dataprovider"
|
||||||
"github.com/drakkan/sftpgo/sftpd"
|
"github.com/drakkan/sftpgo/sftpd"
|
||||||
"github.com/drakkan/sftpgo/utils"
|
"github.com/drakkan/sftpgo/utils"
|
||||||
|
"github.com/drakkan/sftpgo/version"
|
||||||
"github.com/drakkan/sftpgo/vfs"
|
"github.com/drakkan/sftpgo/vfs"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -143,7 +144,6 @@ func loadTemplates(templatesPath string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getBasePageData(title, currentURL string) basePage {
|
func getBasePageData(title, currentURL string) basePage {
|
||||||
version := utils.GetAppVersion()
|
|
||||||
return basePage{
|
return basePage{
|
||||||
Title: title,
|
Title: title,
|
||||||
CurrentURL: currentURL,
|
CurrentURL: currentURL,
|
||||||
@@ -160,7 +160,7 @@ func getBasePageData(title, currentURL string) basePage {
|
|||||||
UsersTitle: pageUsersTitle,
|
UsersTitle: pageUsersTitle,
|
||||||
ConnectionsTitle: pageConnectionsTitle,
|
ConnectionsTitle: pageConnectionsTitle,
|
||||||
FoldersTitle: pageFoldersTitle,
|
FoldersTitle: pageFoldersTitle,
|
||||||
Version: version.GetVersionAsString(),
|
Version: version.GetAsString(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// +build !nometrics
|
||||||
|
|
||||||
// Package metrics provides Prometheus metrics support
|
// Package metrics provides Prometheus metrics support
|
||||||
package metrics
|
package metrics
|
||||||
|
|
||||||
@@ -6,6 +8,8 @@ import (
|
|||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
|
|
||||||
|
"github.com/drakkan/sftpgo/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -15,9 +19,8 @@ const (
|
|||||||
loginMethodKeyAndKeyboardInt = "publickey+keyboard-interactive"
|
loginMethodKeyAndKeyboardInt = "publickey+keyboard-interactive"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AddMetricsEndpoint exposes metrics to the specified endpoint
|
func init() {
|
||||||
func AddMetricsEndpoint(metricsPath string, handler chi.Router) {
|
version.AddFeature("+metrics")
|
||||||
handler.Handle(metricsPath, promhttp.Handler())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -393,6 +396,11 @@ var (
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// AddMetricsEndpoint exposes metrics to the specified endpoint
|
||||||
|
func AddMetricsEndpoint(metricsPath string, handler chi.Router) {
|
||||||
|
handler.Handle(metricsPath, promhttp.Handler())
|
||||||
|
}
|
||||||
|
|
||||||
// TransferCompleted updates metrics after an upload or a download
|
// TransferCompleted updates metrics after an upload or a download
|
||||||
func TransferCompleted(bytesSent, bytesReceived int64, transferKind int, err error) {
|
func TransferCompleted(bytesSent, bytesReceived int64, transferKind int, err error) {
|
||||||
if transferKind == 0 {
|
if transferKind == 0 {
|
||||||
|
|||||||
67
metrics/metrics_disabled.go
Normal file
67
metrics/metrics_disabled.go
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
// +build nometrics
|
||||||
|
|
||||||
|
package metrics
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/go-chi/chi"
|
||||||
|
|
||||||
|
"github.com/drakkan/sftpgo/version"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
version.AddFeature("-metrics")
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddMetricsEndpoint exposes metrics to the specified endpoint
|
||||||
|
func AddMetricsEndpoint(metricsPath string, handler chi.Router) {}
|
||||||
|
|
||||||
|
// TransferCompleted updates metrics after an upload or a download
|
||||||
|
func TransferCompleted(bytesSent, bytesReceived int64, transferKind int, err error) {}
|
||||||
|
|
||||||
|
// S3TransferCompleted updates metrics after an S3 upload or a download
|
||||||
|
func S3TransferCompleted(bytes int64, transferKind int, err error) {}
|
||||||
|
|
||||||
|
// S3ListObjectsCompleted updates metrics after an S3 list objects request terminates
|
||||||
|
func S3ListObjectsCompleted(err error) {}
|
||||||
|
|
||||||
|
// S3CopyObjectCompleted updates metrics after an S3 copy object request terminates
|
||||||
|
func S3CopyObjectCompleted(err error) {}
|
||||||
|
|
||||||
|
// S3DeleteObjectCompleted updates metrics after an S3 delete object request terminates
|
||||||
|
func S3DeleteObjectCompleted(err error) {}
|
||||||
|
|
||||||
|
// S3HeadBucketCompleted updates metrics after an S3 head bucket request terminates
|
||||||
|
func S3HeadBucketCompleted(err error) {}
|
||||||
|
|
||||||
|
// GCSTransferCompleted updates metrics after a GCS upload or a download
|
||||||
|
func GCSTransferCompleted(bytes int64, transferKind int, err error) {}
|
||||||
|
|
||||||
|
// GCSListObjectsCompleted updates metrics after a GCS list objects request terminates
|
||||||
|
func GCSListObjectsCompleted(err error) {}
|
||||||
|
|
||||||
|
// GCSCopyObjectCompleted updates metrics after a GCS copy object request terminates
|
||||||
|
func GCSCopyObjectCompleted(err error) {}
|
||||||
|
|
||||||
|
// GCSDeleteObjectCompleted updates metrics after a GCS delete object request terminates
|
||||||
|
func GCSDeleteObjectCompleted(err error) {}
|
||||||
|
|
||||||
|
// GCSHeadBucketCompleted updates metrics after a GCS head bucket request terminates
|
||||||
|
func GCSHeadBucketCompleted(err error) {}
|
||||||
|
|
||||||
|
// SSHCommandCompleted update metrics after an SSH command terminates
|
||||||
|
func SSHCommandCompleted(err error) {}
|
||||||
|
|
||||||
|
// UpdateDataProviderAvailability updates the metric for the data provider availability
|
||||||
|
func UpdateDataProviderAvailability(err error) {}
|
||||||
|
|
||||||
|
// AddLoginAttempt increments the metrics for login attempts
|
||||||
|
func AddLoginAttempt(authMethod string) {}
|
||||||
|
|
||||||
|
// AddLoginResult increments the metrics for login results
|
||||||
|
func AddLoginResult(authMethod string, err error) {}
|
||||||
|
|
||||||
|
// HTTPRequestServed increments the metrics for HTTP requests
|
||||||
|
func HTTPRequestServed(status int) {}
|
||||||
|
|
||||||
|
// UpdateActiveConnectionsSize sets the metric for active connections
|
||||||
|
func UpdateActiveConnectionsSize(size int) {}
|
||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/drakkan/sftpgo/logger"
|
"github.com/drakkan/sftpgo/logger"
|
||||||
"github.com/drakkan/sftpgo/sftpd"
|
"github.com/drakkan/sftpgo/sftpd"
|
||||||
"github.com/drakkan/sftpgo/utils"
|
"github.com/drakkan/sftpgo/utils"
|
||||||
|
"github.com/drakkan/sftpgo/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -54,9 +55,8 @@ func (s *Service) Start() error {
|
|||||||
logger.DisableLogger()
|
logger.DisableLogger()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
version := utils.GetAppVersion()
|
|
||||||
logger.Info(logSender, "", "starting SFTPGo %v, config dir: %v, config file: %v, log max size: %v log max backups: %v "+
|
logger.Info(logSender, "", "starting SFTPGo %v, config dir: %v, config file: %v, log max size: %v log max backups: %v "+
|
||||||
"log max age: %v log verbose: %v, log compress: %v, profile: %v", version.GetVersionAsString(), s.ConfigDir, s.ConfigFile,
|
"log max age: %v log verbose: %v, log compress: %v, profile: %v", version.GetAsString(), s.ConfigDir, s.ConfigFile,
|
||||||
s.LogMaxSize, s.LogMaxBackups, s.LogMaxAge, s.LogVerbose, s.LogCompress, s.Profiler)
|
s.LogMaxSize, s.LogMaxBackups, s.LogMaxAge, s.LogVerbose, s.LogCompress, s.Profiler)
|
||||||
// in portable mode we don't read configuration from file
|
// in portable mode we don't read configuration from file
|
||||||
if s.PortableMode != 1 {
|
if s.PortableMode != 1 {
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/drakkan/sftpgo/logger"
|
"github.com/drakkan/sftpgo/logger"
|
||||||
"github.com/drakkan/sftpgo/sftpd"
|
"github.com/drakkan/sftpgo/sftpd"
|
||||||
"github.com/drakkan/sftpgo/utils"
|
"github.com/drakkan/sftpgo/utils"
|
||||||
|
"github.com/drakkan/sftpgo/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
// StartPortableMode starts the service in portable mode
|
// StartPortableMode starts the service in portable mode
|
||||||
@@ -67,9 +68,8 @@ func (s *Service) StartPortableMode(sftpdPort int, enabledSSHCommands []string,
|
|||||||
}
|
}
|
||||||
var mDNSService *zeroconf.Server
|
var mDNSService *zeroconf.Server
|
||||||
if advertiseService {
|
if advertiseService {
|
||||||
version := utils.GetAppVersion()
|
|
||||||
meta := []string{
|
meta := []string{
|
||||||
fmt.Sprintf("version=%v", version.GetVersionAsString()),
|
fmt.Sprintf("version=%v", version.GetAsString()),
|
||||||
}
|
}
|
||||||
if advertiseCredentials {
|
if advertiseCredentials {
|
||||||
logger.InfoToConsole("Advertising credentials via multicast DNS")
|
logger.InfoToConsole("Advertising credentials via multicast DNS")
|
||||||
|
|||||||
@@ -62,11 +62,6 @@ func GetTimeFromMsecSinceEpoch(msec int64) time.Time {
|
|||||||
return time.Unix(0, msec*1000000)
|
return time.Unix(0, msec*1000000)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAppVersion returns VersionInfo struct
|
|
||||||
func GetAppVersion() VersionInfo {
|
|
||||||
return versionInfo
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetDurationAsString returns a string representation for a time.Duration
|
// GetDurationAsString returns a string representation for a time.Duration
|
||||||
func GetDurationAsString(d time.Duration) string {
|
func GetDurationAsString(d time.Duration) string {
|
||||||
d = d.Round(time.Second)
|
d = d.Round(time.Second)
|
||||||
|
|||||||
@@ -1,51 +0,0 @@
|
|||||||
package utils
|
|
||||||
|
|
||||||
import "strings"
|
|
||||||
|
|
||||||
const version = "0.9.6-dev"
|
|
||||||
|
|
||||||
var (
|
|
||||||
commit = ""
|
|
||||||
date = ""
|
|
||||||
versionInfo VersionInfo
|
|
||||||
)
|
|
||||||
|
|
||||||
// VersionInfo defines version details
|
|
||||||
type VersionInfo struct {
|
|
||||||
Version string `json:"version"`
|
|
||||||
BuildDate string `json:"build_date"`
|
|
||||||
CommitHash string `json:"commit_hash"`
|
|
||||||
Features []string `json:"features"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetVersionAsString returns the string representation of the VersionInfo struct
|
|
||||||
func (v *VersionInfo) GetVersionAsString() string {
|
|
||||||
var sb strings.Builder
|
|
||||||
sb.WriteString(v.Version)
|
|
||||||
if len(v.CommitHash) > 0 {
|
|
||||||
sb.WriteString("-")
|
|
||||||
sb.WriteString(v.CommitHash)
|
|
||||||
}
|
|
||||||
if len(v.BuildDate) > 0 {
|
|
||||||
sb.WriteString("-")
|
|
||||||
sb.WriteString(v.BuildDate)
|
|
||||||
}
|
|
||||||
if len(v.Features) > 0 {
|
|
||||||
sb.WriteString(" ")
|
|
||||||
sb.WriteString(strings.Join(v.Features, " "))
|
|
||||||
}
|
|
||||||
return sb.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddFeature adds a feature description
|
|
||||||
func AddFeature(feature string) {
|
|
||||||
versionInfo.Features = append(versionInfo.Features, feature)
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
versionInfo = VersionInfo{
|
|
||||||
Version: version,
|
|
||||||
CommitHash: commit,
|
|
||||||
BuildDate: date,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
56
version/version.go
Normal file
56
version/version.go
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
package version
|
||||||
|
|
||||||
|
import "strings"
|
||||||
|
|
||||||
|
const version = "0.9.6-dev"
|
||||||
|
|
||||||
|
var (
|
||||||
|
commit = ""
|
||||||
|
date = ""
|
||||||
|
info Info
|
||||||
|
)
|
||||||
|
|
||||||
|
// Info defines version details
|
||||||
|
type Info struct {
|
||||||
|
Version string `json:"version"`
|
||||||
|
BuildDate string `json:"build_date"`
|
||||||
|
CommitHash string `json:"commit_hash"`
|
||||||
|
Features []string `json:"features"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAsString returns the string representation of the version
|
||||||
|
func GetAsString() string {
|
||||||
|
var sb strings.Builder
|
||||||
|
sb.WriteString(info.Version)
|
||||||
|
if len(info.CommitHash) > 0 {
|
||||||
|
sb.WriteString("-")
|
||||||
|
sb.WriteString(info.CommitHash)
|
||||||
|
}
|
||||||
|
if len(info.BuildDate) > 0 {
|
||||||
|
sb.WriteString("-")
|
||||||
|
sb.WriteString(info.BuildDate)
|
||||||
|
}
|
||||||
|
if len(info.Features) > 0 {
|
||||||
|
sb.WriteString(" ")
|
||||||
|
sb.WriteString(strings.Join(info.Features, " "))
|
||||||
|
}
|
||||||
|
return sb.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
info = Info{
|
||||||
|
Version: version,
|
||||||
|
CommitHash: commit,
|
||||||
|
BuildDate: date,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddFeature adds a feature description
|
||||||
|
func AddFeature(feature string) {
|
||||||
|
info.Features = append(info.Features, feature)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get returns the Info struct
|
||||||
|
func Get() Info {
|
||||||
|
return info
|
||||||
|
}
|
||||||
@@ -21,7 +21,7 @@ import (
|
|||||||
|
|
||||||
"github.com/drakkan/sftpgo/logger"
|
"github.com/drakkan/sftpgo/logger"
|
||||||
"github.com/drakkan/sftpgo/metrics"
|
"github.com/drakkan/sftpgo/metrics"
|
||||||
"github.com/drakkan/sftpgo/utils"
|
"github.com/drakkan/sftpgo/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -41,7 +41,7 @@ type GCSFs struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
utils.AddFeature("+gcs")
|
version.AddFeature("+gcs")
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewGCSFs returns an GCSFs object that allows to interact with Google Cloud Storage
|
// NewGCSFs returns an GCSFs object that allows to interact with Google Cloud Storage
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ package vfs
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/drakkan/sftpgo/utils"
|
"github.com/drakkan/sftpgo/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
utils.AddFeature("-gcs")
|
version.AddFeature("-gcs")
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewGCSFs returns an error, GCS is disabled
|
// NewGCSFs returns an error, GCS is disabled
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import (
|
|||||||
"github.com/drakkan/sftpgo/logger"
|
"github.com/drakkan/sftpgo/logger"
|
||||||
"github.com/drakkan/sftpgo/metrics"
|
"github.com/drakkan/sftpgo/metrics"
|
||||||
"github.com/drakkan/sftpgo/utils"
|
"github.com/drakkan/sftpgo/utils"
|
||||||
|
"github.com/drakkan/sftpgo/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
// S3Fs is a Fs implementation for Amazon S3 compatible object storage.
|
// S3Fs is a Fs implementation for Amazon S3 compatible object storage.
|
||||||
@@ -35,7 +36,7 @@ type S3Fs struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
utils.AddFeature("+s3")
|
version.AddFeature("+s3")
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewS3Fs returns an S3Fs object that allows to interact with an s3 compatible
|
// NewS3Fs returns an S3Fs object that allows to interact with an s3 compatible
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ package vfs
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/drakkan/sftpgo/utils"
|
"github.com/drakkan/sftpgo/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
utils.AddFeature("-s3")
|
version.AddFeature("-s3")
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewS3Fs returns an error, S3 is disabled
|
// NewS3Fs returns an error, S3 is disabled
|
||||||
|
|||||||
Reference in New Issue
Block a user