Skip to content

Commit

Permalink
Implement MackerelPlugin interface
Browse files Browse the repository at this point in the history
  • Loading branch information
tomohiro committed Nov 14, 2019
1 parent 438a100 commit 5c5fe87
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
52 changes: 52 additions & 0 deletions lib/jitsi-videobridge.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,60 @@
package mpjitsivideobridge

import (
"flag"
"strings"

mp "github.com/mackerelio/go-mackerel-plugin"
)

// JitsiVideobridgePlugin as Mackerel agent plugin for Jitsi Videobridge
type JitsiVideobridgePlugin struct {
Prefix string
Host string
Port string
}

// MetricKeyPrefix returns prefix of Jitsi Videobridge metrics
func (p JitsiVideobridgePlugin) MetricKeyPrefix() string {
if p.Prefix == "" {
p.Prefix = "jitsi-videobridge"
}
return p.Prefix
}

// GraphDefinition returns graph definition
func (p JitsiVideobridgePlugin) GraphDefinition() map[string]mp.Graphs {
labelPrefix := strings.Title(p.MetricKeyPrefix())
return map[string]mp.Graphs{
"Audio Channels": {
Label: labelPrefix,
Unit: mp.UnitInteger,
Metrics: []mp.Metrics{
{Name: "audiochannels", Label: "Audio Channels"},
},
},
}
}

// FetchMetrics fetches metrics from Jitsi Videobridge Colibri REST interface
func (p JitsiVideobridgePlugin) FetchMetrics() (map[string]float64, error) {
return map[string]float64{"audiochannels": 0}, nil
}

// Do the plugin
func Do() {
optPrefix := flag.String("metric-key-prefix", "jitsi-videobridge", "Metric key prefix")
optHost := flag.String("host", "127.0.0.1", "Hostname or IP address of Jitsi Videobridge Colibri REST interface")
optPort := flag.String("port", "80", "Port of Jitsi Videobridge Colibri REST interface")
optTempfile := flag.String("tempfile", "", "Temp file name")
flag.Parse()

p := JitsiVideobridgePlugin{
Prefix: *optPrefix,
Host: *optHost,
Port: *optPort,
}
helper := mp.NewMackerelPlugin(p)
helper.Tempfile = *optTempfile
helper.Run()
}
16 changes: 16 additions & 0 deletions lib/jitsi-videobridge_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package mpjitsivideobridge

import (
"testing"
)

func TestMetricKeyPrefix(t *testing.T) {
var p JitsiVideobridgePlugin

expected := "jitsi-videobridge"
actual := p.MetricKeyPrefix()

if actual != expected {
t.Errorf("MetricKeyPrefix: %v should be %v", actual, expected)
}
}
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import "github.com/tomohiro/mackerel-plugin-jitsi-videobridge/lib"
import mpjitsivideobridge "github.com/tomohiro/mackerel-plugin-jitsi-videobridge/lib"

func main() {
mpjvb.Do()
mpjitsivideobridge.Do()
}

0 comments on commit 5c5fe87

Please sign in to comment.