Browse Source

initial commit

master
f0x 1 year ago
commit
d1b50a4b68
1 changed files with 53 additions and 0 deletions
  1. +53
    -0
      mumble.go

+ 53
- 0
mumble.go View File

@@ -0,0 +1,53 @@
package main

import (
"fmt"
"github.com/hpcloud/tail"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
"net/http"
"strings"
)

var (
Connections = promauto.NewGauge(prometheus.GaugeOpts{
Name: "mumble_connections",
Help: "Number of connected Mumble clients",
})
counter = 0
)

func metrics() {
fmt.Println("Watching mumble log")
go func() {
t, err := tail.TailFile("/var/log/mumble-server/mumble-server.log", tail.Config{Follow: true})
if err != nil {
fmt.Println(err)
}

for line := range t.Lines {
if strings.Contains(line.Text, "onnection") {
fmt.Println(line)
if strings.Contains(line.Text, "New connection") {
fmt.Println("new connection")
Connections.Inc()
counter++
}

if counter > 0 && strings.Contains(line.Text, "Connection closed") {
fmt.Println("lost a connection")
Connections.Dec()
counter--
}
fmt.Println(counter)
}
}
}()
}

func main() {
metrics()
http.Handle("/metrics", promhttp.Handler())
http.ListenAndServe(":2112", nil)
}

Loading…
Cancel
Save