-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
75 lines (64 loc) · 1.88 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"fmt"
"log"
"net/http"
"strconv"
"time"
"github.com/docopt/docopt-go"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var version = "1.0.1"
var usage = `nightwatchjs_exporter
Usage:
nightwatchjs_exporter --nightwatch=<path> --testdir=<path> [options]
nightwatchjs_exporter --help
nightwatchjs_exporter --version
Options:
-n, --nightwatch=<path> REQUIRED: Path to your nightwatch executable.
-t, --testdir=<path> REQUIRED: Directory containing your 'nightwatch.json' file and 'tests' directory.
--delay=<secs> Delay in seconds between test executions [default: 30].
--listen=<host:port> HTTP listen address [default: :9355].
Example:
nightwatchjs_exporter --nightwatch=/usr/bin/nightwatch --testdir=/home/my_test_dir
`
type Config struct {
NightwatchjsDir string
NightwatchjsCmd string
ListenAddr string
DelayTime time.Duration
}
func main() {
cfg, err := getConfig()
if err != nil {
log.Fatalf("Config error: %s", err)
}
go start_nightwatch_runner(cfg)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>Nightwatch.js Exporter</title></head>
<body>
<h1>Nightwatch.js Exporter</h1>
<p><a href="/metrics">Metrics</a></p>
</body>
</html>`))
})
http.Handle("/metrics", promhttp.Handler())
log.Fatal(http.ListenAndServe(cfg.ListenAddr, nil))
}
func getConfig() (Config, error) {
c := Config{}
args, err := docopt.Parse(usage, nil, true, version, false)
if err != nil {
return c, err
}
c.NightwatchjsDir = args["--testdir"].(string)
c.NightwatchjsCmd = args["--nightwatch"].(string)
c.ListenAddr = args["--listen"].(string)
val, err := strconv.Atoi(args["--delay"].(string))
if err != nil {
return c, fmt.Errorf("Invalid --delay, expecting a number of seconds")
}
c.DelayTime = time.Duration(val) * time.Second
return c, nil
}