mirror of
				https://github.com/datarhei/core.git
				synced 2025-10-31 19:32:56 +08:00 
			
		
		
		
	 eb1cc37456
			
		
	
	eb1cc37456
	
	
	
		
			
			Commits (Ingo Oppermann): - Add experimental SRT connection stats and logs - Hide /config/reload endpoint in reade-only mode - Add SRT server - Create v16 in go.mod - Fix data races, tests, lint, and update dependencies - Add trailing slash for routed directories (datarhei/restreamer#340) - Allow relative URLs in content in static routes Co-Authored-By: Ingo Oppermann <57445+ioppermann@users.noreply.github.com>
		
			
				
	
	
		
			51 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			51 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package prometheus
 | |
| 
 | |
| import (
 | |
| 	"github.com/datarhei/core/v16/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"))
 | |
| 	}
 | |
| }
 |