mirror of
https://github.com/datarhei/core.git
synced 2025-09-26 20:11:29 +08:00
Add v16.7.2
This commit is contained in:
61
prometheus/cpu.go
Normal file
61
prometheus/cpu.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package prometheus
|
||||
|
||||
import (
|
||||
"github.com/datarhei/core/monitor/metric"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
type cpuCollector struct {
|
||||
core string
|
||||
collector metric.Reader
|
||||
|
||||
cpuSystemTimeDesc *prometheus.Desc
|
||||
cpuUserTimeDesc *prometheus.Desc
|
||||
cpuIdleTimeDesc *prometheus.Desc
|
||||
cpuOtherTimeDesc *prometheus.Desc
|
||||
}
|
||||
|
||||
func NewCPUCollector(core string, c metric.Reader) prometheus.Collector {
|
||||
return &cpuCollector{
|
||||
core: core,
|
||||
collector: c,
|
||||
cpuSystemTimeDesc: prometheus.NewDesc(
|
||||
"cpu_system_time_percent",
|
||||
"CPU system time in percent",
|
||||
[]string{"core"}, nil),
|
||||
cpuUserTimeDesc: prometheus.NewDesc(
|
||||
"cpu_user_time_percent",
|
||||
"CPU user time in percent",
|
||||
[]string{"core"}, nil),
|
||||
cpuIdleTimeDesc: prometheus.NewDesc(
|
||||
"cpu_idle_time_percent",
|
||||
"CPU idle time in percent",
|
||||
[]string{"core"}, nil),
|
||||
cpuOtherTimeDesc: prometheus.NewDesc(
|
||||
"cpu_other_time_percent",
|
||||
"CPU other time in percent",
|
||||
[]string{"core"}, nil),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *cpuCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||
ch <- c.cpuSystemTimeDesc
|
||||
ch <- c.cpuUserTimeDesc
|
||||
ch <- c.cpuIdleTimeDesc
|
||||
ch <- c.cpuOtherTimeDesc
|
||||
}
|
||||
|
||||
func (c *cpuCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
metrics := c.collector.Collect([]metric.Pattern{
|
||||
metric.NewPattern("cpu_system"),
|
||||
metric.NewPattern("cpu_user"),
|
||||
metric.NewPattern("cpu_idle"),
|
||||
metric.NewPattern("cpu_other"),
|
||||
})
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(c.cpuSystemTimeDesc, prometheus.GaugeValue, metrics.Value("cpu_system").Val(), c.core)
|
||||
ch <- prometheus.MustNewConstMetric(c.cpuUserTimeDesc, prometheus.GaugeValue, metrics.Value("cpu_user").Val(), c.core)
|
||||
ch <- prometheus.MustNewConstMetric(c.cpuIdleTimeDesc, prometheus.GaugeValue, metrics.Value("cpu_idle").Val(), c.core)
|
||||
ch <- prometheus.MustNewConstMetric(c.cpuOtherTimeDesc, prometheus.GaugeValue, metrics.Value("cpu_other").Val(), c.core)
|
||||
}
|
50
prometheus/disk.go
Normal file
50
prometheus/disk.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package prometheus
|
||||
|
||||
import (
|
||||
"github.com/datarhei/core/monitor/metric"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
type diskCollector struct {
|
||||
core string
|
||||
collector metric.Reader
|
||||
|
||||
diskTotalDesc *prometheus.Desc
|
||||
diskUsageDesc *prometheus.Desc
|
||||
}
|
||||
|
||||
func NewDiskCollector(core string, c metric.Reader) prometheus.Collector {
|
||||
return &diskCollector{
|
||||
core: core,
|
||||
collector: c,
|
||||
diskTotalDesc: prometheus.NewDesc(
|
||||
"disk_total_bytes",
|
||||
"disk_total_bytes",
|
||||
[]string{"core", "path"}, nil),
|
||||
diskUsageDesc: prometheus.NewDesc(
|
||||
"disk_usage_bytes",
|
||||
"disk_usage_bytes",
|
||||
[]string{"core", "path"}, nil),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *diskCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||
ch <- c.diskTotalDesc
|
||||
ch <- c.diskUsageDesc
|
||||
}
|
||||
|
||||
func (c *diskCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
metrics := c.collector.Collect([]metric.Pattern{
|
||||
metric.NewPattern("disk_total"),
|
||||
metric.NewPattern("disk_usage"),
|
||||
})
|
||||
|
||||
for _, m := range metrics.Values("disk_total") {
|
||||
ch <- prometheus.MustNewConstMetric(c.diskTotalDesc, prometheus.GaugeValue, m.Val(), c.core, m.L("path"))
|
||||
}
|
||||
|
||||
for _, m := range metrics.Values("disk_usage") {
|
||||
ch <- prometheus.MustNewConstMetric(c.diskUsageDesc, prometheus.GaugeValue, m.Val(), c.core, m.L("path"))
|
||||
}
|
||||
}
|
61
prometheus/filesystem.go
Normal file
61
prometheus/filesystem.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package prometheus
|
||||
|
||||
import (
|
||||
"github.com/datarhei/core/monitor/metric"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
type filesystemCollector struct {
|
||||
core string
|
||||
collector metric.Reader
|
||||
|
||||
fsLimitDesc *prometheus.Desc
|
||||
fsUsageDesc *prometheus.Desc
|
||||
fsFilesDesc *prometheus.Desc
|
||||
}
|
||||
|
||||
func NewFilesystemCollector(core string, c metric.Reader) prometheus.Collector {
|
||||
return &filesystemCollector{
|
||||
core: core,
|
||||
collector: c,
|
||||
fsLimitDesc: prometheus.NewDesc(
|
||||
"filesystem_limit_bytes",
|
||||
"filesystem_limit_bytes",
|
||||
[]string{"core", "name"}, nil),
|
||||
fsUsageDesc: prometheus.NewDesc(
|
||||
"filesystem_usage_bytes",
|
||||
"filesystem_usage_bytes",
|
||||
[]string{"core", "name"}, nil),
|
||||
fsFilesDesc: prometheus.NewDesc(
|
||||
"filesystem_files",
|
||||
"filesystem_files",
|
||||
[]string{"core", "name"}, nil),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *filesystemCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||
ch <- c.fsLimitDesc
|
||||
ch <- c.fsUsageDesc
|
||||
ch <- c.fsFilesDesc
|
||||
}
|
||||
|
||||
func (c *filesystemCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
metrics := c.collector.Collect([]metric.Pattern{
|
||||
metric.NewPattern("filesystem_limit"),
|
||||
metric.NewPattern("filesystem_usage"),
|
||||
metric.NewPattern("filesystem_files"),
|
||||
})
|
||||
|
||||
for _, m := range metrics.Values("filesystem_limit") {
|
||||
ch <- prometheus.MustNewConstMetric(c.fsLimitDesc, prometheus.GaugeValue, m.Val(), c.core, m.L("name"))
|
||||
}
|
||||
|
||||
for _, m := range metrics.Values("filesystem_usage") {
|
||||
ch <- prometheus.MustNewConstMetric(c.fsUsageDesc, prometheus.GaugeValue, m.Val(), c.core, m.L("name"))
|
||||
}
|
||||
|
||||
for _, m := range metrics.Values("filesystem_files") {
|
||||
ch <- prometheus.MustNewConstMetric(c.fsFilesDesc, prometheus.GaugeValue, m.Val(), c.core, m.L("name"))
|
||||
}
|
||||
}
|
50
prometheus/mem.go
Normal file
50
prometheus/mem.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package prometheus
|
||||
|
||||
import (
|
||||
"github.com/datarhei/core/monitor/metric"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
type memCollector struct {
|
||||
core string
|
||||
collector metric.Reader
|
||||
|
||||
memLimitDesc *prometheus.Desc
|
||||
memFreeDesc *prometheus.Desc
|
||||
}
|
||||
|
||||
func NewMemCollector(core string, c metric.Reader) prometheus.Collector {
|
||||
return &memCollector{
|
||||
core: core,
|
||||
collector: c,
|
||||
memLimitDesc: prometheus.NewDesc(
|
||||
"mem_total_bytes",
|
||||
"Total available memory in bytes",
|
||||
[]string{"core"}, nil),
|
||||
memFreeDesc: prometheus.NewDesc(
|
||||
"mem_free_bytes",
|
||||
"Free memory in bytes",
|
||||
[]string{"core"}, nil),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *memCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||
ch <- c.memLimitDesc
|
||||
ch <- c.memFreeDesc
|
||||
}
|
||||
|
||||
func (c *memCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
metrics := c.collector.Collect([]metric.Pattern{
|
||||
metric.NewPattern("mem_total"),
|
||||
metric.NewPattern("mem_free"),
|
||||
})
|
||||
|
||||
for _, m := range metrics.Values("mem_total") {
|
||||
ch <- prometheus.MustNewConstMetric(c.memLimitDesc, prometheus.GaugeValue, m.Val(), c.core)
|
||||
}
|
||||
|
||||
for _, m := range metrics.Values("mem_free") {
|
||||
ch <- prometheus.MustNewConstMetric(c.memFreeDesc, prometheus.GaugeValue, m.Val(), c.core)
|
||||
}
|
||||
}
|
50
prometheus/net.go
Normal file
50
prometheus/net.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package prometheus
|
||||
|
||||
import (
|
||||
"github.com/datarhei/core/monitor/metric"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
type netCollector struct {
|
||||
core string
|
||||
collector metric.Reader
|
||||
|
||||
netRxDesc *prometheus.Desc
|
||||
netTxDesc *prometheus.Desc
|
||||
}
|
||||
|
||||
func NewNetCollector(core string, c metric.Reader) prometheus.Collector {
|
||||
return &netCollector{
|
||||
core: core,
|
||||
collector: c,
|
||||
netRxDesc: prometheus.NewDesc(
|
||||
"net_rx_bytes",
|
||||
"Number of received bytes by interface",
|
||||
[]string{"core", "interface"}, nil),
|
||||
netTxDesc: prometheus.NewDesc(
|
||||
"net_tx_bytes",
|
||||
"Number of sent bytes by interface",
|
||||
[]string{"core", "interface"}, nil),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *netCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||
ch <- c.netRxDesc
|
||||
ch <- c.netTxDesc
|
||||
}
|
||||
|
||||
func (c *netCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
metrics := c.collector.Collect([]metric.Pattern{
|
||||
metric.NewPattern("net_rx"),
|
||||
metric.NewPattern("net_tx"),
|
||||
})
|
||||
|
||||
for _, m := range metrics.Values("net_rx") {
|
||||
ch <- prometheus.MustNewConstMetric(c.netRxDesc, prometheus.GaugeValue, m.Val(), c.core, m.L("interface"))
|
||||
}
|
||||
|
||||
for _, m := range metrics.Values("net_tx") {
|
||||
ch <- prometheus.MustNewConstMetric(c.netTxDesc, prometheus.GaugeValue, m.Val(), c.core, m.L("interface"))
|
||||
}
|
||||
}
|
51
prometheus/prometheus.go
Normal file
51
prometheus/prometheus.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package prometheus
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
)
|
||||
|
||||
type Metrics interface {
|
||||
Register(cs prometheus.Collector) error
|
||||
UnregisterAll()
|
||||
Reader
|
||||
}
|
||||
|
||||
type Reader interface {
|
||||
HTTPHandler() http.Handler
|
||||
}
|
||||
|
||||
type metrics struct {
|
||||
registry *prometheus.Registry
|
||||
collectors []prometheus.Collector
|
||||
}
|
||||
|
||||
func New() Metrics {
|
||||
m := &metrics{
|
||||
registry: prometheus.NewRegistry(),
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *metrics) Register(cs prometheus.Collector) error {
|
||||
if err := m.registry.Register(cs); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
m.collectors = append(m.collectors, cs)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *metrics) UnregisterAll() {
|
||||
for _, cs := range m.collectors {
|
||||
m.registry.Unregister(cs)
|
||||
}
|
||||
}
|
||||
|
||||
func (m *metrics) HTTPHandler() http.Handler {
|
||||
return promhttp.InstrumentMetricHandler(m.registry, promhttp.HandlerFor(m.registry, promhttp.HandlerOpts{}))
|
||||
}
|
101
prometheus/restream.go
Normal file
101
prometheus/restream.go
Normal file
@@ -0,0 +1,101 @@
|
||||
package prometheus
|
||||
|
||||
import (
|
||||
"github.com/datarhei/core/monitor/metric"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
type restreamCollector struct {
|
||||
core string
|
||||
collector metric.Reader
|
||||
|
||||
ffmpegProcessDesc *prometheus.Desc
|
||||
ffmpegProcessStatesDesc *prometheus.Desc
|
||||
ffmpegProcessIODesc *prometheus.Desc
|
||||
ffmpegStatesDesc *prometheus.Desc
|
||||
ffmpegStatesTotalDesc *prometheus.Desc
|
||||
}
|
||||
|
||||
func NewRestreamCollector(core string, c metric.Reader) prometheus.Collector {
|
||||
return &restreamCollector{
|
||||
core: core,
|
||||
collector: c,
|
||||
ffmpegProcessDesc: prometheus.NewDesc(
|
||||
"ffmpeg_process",
|
||||
"General stats per process",
|
||||
[]string{"core", "process", "state", "order", "name"}, nil),
|
||||
ffmpegProcessStatesDesc: prometheus.NewDesc(
|
||||
"ffmpeg_process_states",
|
||||
"Accumulated states per process",
|
||||
[]string{"core", "process", "state"}, nil),
|
||||
ffmpegProcessIODesc: prometheus.NewDesc(
|
||||
"ffmpeg_process_io",
|
||||
"Stats per input and output of a process",
|
||||
[]string{"core", "process", "type", "id", "index", "stream", "media", "name"}, nil),
|
||||
ffmpegStatesDesc: prometheus.NewDesc(
|
||||
"ffmpeg_states",
|
||||
"Current process states",
|
||||
[]string{"core", "state"}, nil),
|
||||
ffmpegStatesTotalDesc: prometheus.NewDesc(
|
||||
"ffmpeg_states_total",
|
||||
"Accumulated process states",
|
||||
[]string{"core", "state"}, nil),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *restreamCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||
ch <- c.ffmpegProcessDesc
|
||||
ch <- c.ffmpegProcessStatesDesc
|
||||
ch <- c.ffmpegProcessIODesc
|
||||
ch <- c.ffmpegStatesDesc
|
||||
ch <- c.ffmpegStatesTotalDesc
|
||||
}
|
||||
|
||||
func (c *restreamCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
metrics := c.collector.Collect([]metric.Pattern{
|
||||
metric.NewPattern("restream_process"),
|
||||
metric.NewPattern("restream_process_states"),
|
||||
metric.NewPattern("restream_io"),
|
||||
metric.NewPattern("ffmpeg_process"),
|
||||
})
|
||||
|
||||
for _, m := range metrics.Values("restream_process") {
|
||||
ch <- prometheus.MustNewConstMetric(c.ffmpegProcessDesc, prometheus.GaugeValue, m.Val(), c.core, m.L("processid"), m.L("state"), m.L("order"), m.L("name"))
|
||||
}
|
||||
|
||||
for _, m := range metrics.Values("restream_process_states") {
|
||||
ch <- prometheus.MustNewConstMetric(c.ffmpegProcessStatesDesc, prometheus.GaugeValue, m.Val(), c.core, m.L("processid"), m.L("state"))
|
||||
}
|
||||
|
||||
for _, m := range metrics.Values("restream_io") {
|
||||
ch <- prometheus.MustNewConstMetric(c.ffmpegProcessIODesc, prometheus.GaugeValue, m.Val(), c.core, m.L("processid"), m.L("type"), m.L("id"), m.L("index"), m.L("stream"), m.L("media"), m.L("name"))
|
||||
}
|
||||
|
||||
states := map[string]float64{
|
||||
"failed": 0,
|
||||
"finished": 0,
|
||||
"finishing": 0,
|
||||
"killed": 0,
|
||||
"running": 0,
|
||||
"starting": 0,
|
||||
}
|
||||
|
||||
for _, processid := range metrics.Labels("restream_process", "processid") {
|
||||
s := metrics.Value("restream_process", "processid", "^"+processid+"$").L("state")
|
||||
|
||||
if _, ok := states[s]; !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
states[s]++
|
||||
}
|
||||
|
||||
for state, value := range states {
|
||||
ch <- prometheus.MustNewConstMetric(c.ffmpegStatesDesc, prometheus.GaugeValue, value, c.core, state)
|
||||
}
|
||||
|
||||
for _, m := range metrics.Values("ffmpeg_process") {
|
||||
ch <- prometheus.MustNewConstMetric(c.ffmpegStatesTotalDesc, prometheus.CounterValue, m.Val(), c.core, m.L("state"))
|
||||
}
|
||||
}
|
72
prometheus/session.go
Normal file
72
prometheus/session.go
Normal file
@@ -0,0 +1,72 @@
|
||||
package prometheus
|
||||
|
||||
import (
|
||||
"github.com/datarhei/core/monitor/metric"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
type sessionCollector struct {
|
||||
core string
|
||||
collector metric.Reader
|
||||
|
||||
totalDesc *prometheus.Desc
|
||||
activeDesc *prometheus.Desc
|
||||
rxDesc *prometheus.Desc
|
||||
txDesc *prometheus.Desc
|
||||
}
|
||||
|
||||
func NewSessionCollector(core string, c metric.Reader) prometheus.Collector {
|
||||
return &sessionCollector{
|
||||
core: core,
|
||||
collector: c,
|
||||
totalDesc: prometheus.NewDesc(
|
||||
"session_total",
|
||||
"Total number of sessions by collector",
|
||||
[]string{"core", "collector"}, nil),
|
||||
activeDesc: prometheus.NewDesc(
|
||||
"session_active",
|
||||
"Current number of active sessions by collector",
|
||||
[]string{"core", "collector"}, nil),
|
||||
rxDesc: prometheus.NewDesc(
|
||||
"session_rx_bytes",
|
||||
"Total received bytes by collector",
|
||||
[]string{"core", "collector"}, nil),
|
||||
txDesc: prometheus.NewDesc(
|
||||
"session_tx_bytes",
|
||||
"Total sent bytes by collector",
|
||||
[]string{"core", "collector"}, nil),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *sessionCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||
ch <- c.totalDesc
|
||||
ch <- c.activeDesc
|
||||
ch <- c.rxDesc
|
||||
ch <- c.txDesc
|
||||
}
|
||||
|
||||
func (c *sessionCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
metrics := c.collector.Collect([]metric.Pattern{
|
||||
metric.NewPattern("session_total"),
|
||||
metric.NewPattern("session_active"),
|
||||
metric.NewPattern("session_rxbytes"),
|
||||
metric.NewPattern("session_txbytes"),
|
||||
})
|
||||
|
||||
for _, m := range metrics.Values("session_total") {
|
||||
ch <- prometheus.MustNewConstMetric(c.totalDesc, prometheus.CounterValue, m.Val(), c.core, m.L("collector"))
|
||||
}
|
||||
|
||||
for _, m := range metrics.Values("session_active") {
|
||||
ch <- prometheus.MustNewConstMetric(c.activeDesc, prometheus.GaugeValue, m.Val(), c.core, m.L("collector"))
|
||||
}
|
||||
|
||||
for _, m := range metrics.Values("session_rxbytes") {
|
||||
ch <- prometheus.MustNewConstMetric(c.rxDesc, prometheus.CounterValue, m.Val(), c.core, m.L("collector"))
|
||||
}
|
||||
|
||||
for _, m := range metrics.Values("session_txbytes") {
|
||||
ch <- prometheus.MustNewConstMetric(c.txDesc, prometheus.CounterValue, m.Val(), c.core, m.L("collector"))
|
||||
}
|
||||
}
|
39
prometheus/uptime.go
Normal file
39
prometheus/uptime.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package prometheus
|
||||
|
||||
import (
|
||||
"github.com/datarhei/core/monitor/metric"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
type uptimeCollector struct {
|
||||
core string
|
||||
collector metric.Reader
|
||||
|
||||
uptimeDesc *prometheus.Desc
|
||||
}
|
||||
|
||||
func NewUptimeCollector(core string, c metric.Reader) prometheus.Collector {
|
||||
return &uptimeCollector{
|
||||
core: core,
|
||||
collector: c,
|
||||
uptimeDesc: prometheus.NewDesc(
|
||||
"uptime_seconds",
|
||||
"Number of seconds the core is up",
|
||||
[]string{"core"}, nil),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *uptimeCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||
ch <- c.uptimeDesc
|
||||
}
|
||||
|
||||
func (c *uptimeCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
metrics := c.collector.Collect([]metric.Pattern{
|
||||
metric.NewPattern("uptime_uptime"),
|
||||
})
|
||||
|
||||
for _, m := range metrics.Values("uptime_uptime") {
|
||||
ch <- prometheus.MustNewConstMetric(c.uptimeDesc, prometheus.CounterValue, m.Val(), c.core)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user