1 files changed, 33 insertions, 0 deletions
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..b1a6edb
--- /dev/null
+++ b/main.go
@@ -0,0 +1,33 @@
+package main
+
+import (
+ "fmt"
+ "net/http"
+ "log"
+)
+
+var(
+ metrics_num_urls int
+)
+
+func main() {
+ log.Println("Starting HTTP listener")
+
+ http.HandleFunc("/", httpHandler)
+ http.HandleFunc("/metrics", metricsHandler)
+ listenErr := http.ListenAndServe(":80", nil) // set listen port
+ if listenErr != nil {
+ log.Fatalln(listenErr.Error())
+ }
+}
+
+// Handling incoming HTTP connections
+func httpHandler(w http.ResponseWriter, r *http.Request) {
+ metrics_num_urls++
+ log.Printf("(%s) %s %s", r.Method, r.RemoteAddr, r.URL.Path)
+}
+
+// Handle HTTP /metrics requests
+func metricsHandler(w http.ResponseWriter, req *http.Request) {
+ fmt.Fprintf(w, "num_urls %d\n", metrics_num_urls)
+}
|