func NewMetricCounter(name string, help string, method string, labels ...string) Metric {
	return Metric{
		prometheus.CounterValue,
		name,
		help,
		method,
	}
}
NewMetricCounter is a helper function to create a counter.
package main
import (
	"errors"
	"fmt"
	"log"
	"net"
	"net/url"
	"regexp"
	"sort"
	"strconv"
	"strings"
	"sync"
	"time"
	binrpc "github.com/florentchauveau/go-kamailio-binrpc/v3"
	"github.com/prometheus/client_golang/prometheus"
)
type Collector struct {
	URI     string
	Timeout time.Duration
	Methods []string
	url   *url.URL
	mutex sync.Mutex
	conn  net.Conn
	up            prometheus.Gauge
	failedScrapes prometheus.Counter
	totalScrapes  prometheus.Counter
}
type Metric struct {
	Kind   prometheus.ValueType
	Name   string
	Help   string
	Method string  
}
type MetricValue struct {
	Value  float64
	Labels map[string]string
}
type DispatcherTarget struct {
	URI   string
	Flags string
	SetID int
}
const (
	namespace = "kamailio"
)
var (
	codeRegex = regexp.MustCompile("^[0-9x]{3}$")
	availableMethods = []string{
		"tm.stats",
		"sl.stats",
		"core.shmmem",
		"core.uptime",
		"core.tcp_info",
		"dispatcher.list",
		"tls.info",
		"dlg.stats_active",
	}
	metricsList = map[string][]Metric{
		"tm.stats": {
			NewMetricGauge("current", "Current transactions.", "tm.stats"),
			NewMetricGauge("waiting", "Waiting transactions.", "tm.stats"),
			NewMetricCounter("total", "Total transactions.", "tm.stats"),
			NewMetricCounter("total_local", "Total local transactions.", "tm.stats"),
			NewMetricCounter("rpl_received", "Number of reply received.", "tm.stats"),
			NewMetricCounter("rpl_generated", "Number of reply generated.", "tm.stats"),
			NewMetricCounter("rpl_sent", "Number of reply sent.", "tm.stats"),
			NewMetricCounter("created", "Created transactions.", "tm.stats"),
			NewMetricCounter("freed", "Freed transactions.", "tm.stats"),
			NewMetricCounter("delayed_free", "Delayed free transactions.", "tm.stats"),
			NewMetricCounter("codes", "Per-code counters.", "tm.stats"),
		},
		"sl.stats": {
			NewMetricCounter("codes", "Per-code counters.", "sl.stats"),
		},
		"core.shmmem": {
			NewMetricGauge("total", "Total shared memory.", "core.shmmem"),
			NewMetricGauge("free", "Free shared memory.", "core.shmmem"),
			NewMetricGauge("used", "Used shared memory.", "core.shmmem"),
			NewMetricGauge("real_used", "Real used shared memory.", "core.shmmem"),
			NewMetricGauge("max_used", "Max used shared memory.", "core.shmmem"),
			NewMetricGauge("fragments", "Number of fragments in shared memory.", "core.shmmem"),
		},
		"core.uptime": {
			NewMetricCounter("uptime", "Uptime in seconds.", "core.uptime"),
		},
		"core.tcp_info": {
			NewMetricGauge("readers", "Total TCP readers.", "core.tcp_info"),
			NewMetricGauge("max_connections", "Maximum TCP connections", "core.tcp_info"),
			NewMetricGauge("max_tls_connections", "Maximum TLS connections.", "core.tcp_info"),
			NewMetricGauge("opened_connections", "Opened TCP connections.", "core.tcp_info"),
			NewMetricGauge("opened_tls_connections", "Opened TLS connections.", "core.tcp_info"),
			NewMetricGauge("write_queued_bytes", "Write queued bytes.", "core.tcp_info"),
		},
		"dispatcher.list": {
			NewMetricGauge("target", "Target status.", "dispatcher.list"),
		},
		"tls.info": {
			NewMetricGauge("opened_connections", "TLS Opened Connections.", "tls.info"),
			NewMetricGauge("max_connections", "TLS Max Connections.", "tls.info"),
		},
		"dlg.stats_active": {
			NewMetricGauge("starting", "Dialogs starting.", "dlg.stats_active"),
			NewMetricGauge("connecting", "Dialogs connecting.", "dlg.stats_active"),
			NewMetricGauge("answering", "Dialogs answering.", "dlg.stats_active"),
			NewMetricGauge("ongoing", "Dialogs ongoing.", "dlg.stats_active"),
			NewMetricGauge("all", "Dialogs all.", "dlg.stats_active"),
		},
	}
)
func NewMetricGauge(name string, help string, method string, labels ...string) Metric {
	return Metric{
		prometheus.GaugeValue,
		name,
		help,
		method,
	}
}