Skip to content

Commit

Permalink
Add metrics to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
corny committed Jan 2, 2019
1 parent fd3ee3a commit a3c882e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ ENV HOS_USER root
ENV HOS_TIMEOUT 10s
ENV HOS_KEY_DIR /data
ENV HOS_LISTEN :8080
ENV HOS_METRICS 1
EXPOSE 8080

WORKDIR /data
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ To restrict an SSH key to only forward connections to `localhost:9100`, append t
restrict,port-forwarding,permitopen="localhost:9100" ssh-ed25519 <the-key> [email protected]
```
### Metrics
Prometheus metrics can be retrieved via `/metrics`.
## Installation
Expand Down
11 changes: 6 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ var sshKeys = []string{

// command line flags
var (
listen = or(os.Getenv("HOS_LISTEN"), "[::1]:8080")
sshUser = or(os.Getenv("HOS_USER"), "root")
sshTimeout = func() time.Duration {
listen = or(os.Getenv("HOS_LISTEN"), "[::1]:8080")
enableMetrics = os.Getenv("HOS_METRICS") != "0"
sshUser = or(os.Getenv("HOS_USER"), "root")
sshTimeout = func() time.Duration {
dur := os.Getenv("HOS_TIMEOUT")
if dur != "" {
if d, err := time.ParseDuration(dur); err != nil {
Expand All @@ -56,7 +57,7 @@ var (
func main() {
fmt.Printf("%s %v, commit %v, built at %v\n", os.Args[0], version, commit, date)

enableMetrics := flag.Bool("metrics", true, "enable metrics")
flag.BoolVar(&enableMetrics, "metrics", enableMetrics, "enable metrics")
flag.StringVar(&listen, "listen", listen, "listen on")
flag.StringVar(&sshUser, "user", sshUser, "default SSH username")
flag.DurationVar(&sshTimeout, "timeout", sshTimeout, "SSH connection timeout")
Expand All @@ -80,7 +81,7 @@ func main() {
},
}

if *enableMetrics {
if enableMetrics {
prometheus.MustRegister(&metrics)
http.Handle("/metrics", promhttp.Handler())
}
Expand Down

0 comments on commit a3c882e

Please sign in to comment.