Skip to content

Commit a3c882e

Browse files
committedJan 2, 2019
Add metrics to readme
1 parent fd3ee3a commit a3c882e

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed
 

‎Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ ENV HOS_USER root
1010
ENV HOS_TIMEOUT 10s
1111
ENV HOS_KEY_DIR /data
1212
ENV HOS_LISTEN :8080
13+
ENV HOS_METRICS 1
1314
EXPOSE 8080
1415

1516
WORKDIR /data

‎README.md

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ To restrict an SSH key to only forward connections to `localhost:9100`, append t
5757
restrict,port-forwarding,permitopen="localhost:9100" ssh-ed25519 <the-key> prometheus@example.com
5858
```
5959
60+
### Metrics
61+
62+
Prometheus metrics can be retrieved via `/metrics`.
6063
6164
## Installation
6265

‎main.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ var sshKeys = []string{
3333

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

59-
enableMetrics := flag.Bool("metrics", true, "enable metrics")
60+
flag.BoolVar(&enableMetrics, "metrics", enableMetrics, "enable metrics")
6061
flag.StringVar(&listen, "listen", listen, "listen on")
6162
flag.StringVar(&sshUser, "user", sshUser, "default SSH username")
6263
flag.DurationVar(&sshTimeout, "timeout", sshTimeout, "SSH connection timeout")
@@ -80,7 +81,7 @@ func main() {
8081
},
8182
}
8283

83-
if *enableMetrics {
84+
if enableMetrics {
8485
prometheus.MustRegister(&metrics)
8586
http.Handle("/metrics", promhttp.Handler())
8687
}

0 commit comments

Comments
 (0)
Please sign in to comment.