Refactoring.
This commit is contained in:
parent
f0113fc53b
commit
3dc656b6a2
@ -3,11 +3,6 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.insit.tech/psa/rtsp_reader-writer/writer/internal/metrics"
|
"git.insit.tech/psa/rtsp_reader-writer/writer/internal/metrics"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
|
||||||
"github.com/prometheus/client_golang/prometheus/collectors"
|
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.insit.tech/psa/rtsp_reader-writer/writer/internal/config"
|
"git.insit.tech/psa/rtsp_reader-writer/writer/internal/config"
|
||||||
@ -17,14 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Регистрируем стандартные метрики
|
go metrics.Metrics()
|
||||||
appRegistry := prometheus.NewRegistry()
|
|
||||||
appRegistry.MustRegister(collectors.NewGoCollector())
|
|
||||||
appRegistry.MustRegister(collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}))
|
|
||||||
appRegistry.MustRegister(metrics.ActiveCameras)
|
|
||||||
|
|
||||||
//// Эндпоинт для метрик
|
|
||||||
http.Handle("/metrics", promhttp.HandlerFor(appRegistry, promhttp.HandlerOpts{}))
|
|
||||||
|
|
||||||
config.LogsDirectory = log2.DirCreator(config.Local, "logs")
|
config.LogsDirectory = log2.DirCreator(config.Local, "logs")
|
||||||
logger.Log = log2.MainLogging(
|
logger.Log = log2.MainLogging(
|
||||||
@ -32,10 +20,5 @@ func main() {
|
|||||||
|
|
||||||
rtsp.StartWriter()
|
rtsp.StartWriter()
|
||||||
|
|
||||||
// Запуск сервера на порту 9110
|
|
||||||
err := http.ListenAndServe(":9110", nil)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
}
|
|
||||||
select {}
|
select {}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,32 @@
|
|||||||
package metrics
|
package metrics
|
||||||
|
|
||||||
import "github.com/prometheus/client_golang/prometheus"
|
import (
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/prometheus/client_golang/prometheus/collectors"
|
||||||
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
var ActiveCameras = prometheus.NewGauge(prometheus.GaugeOpts{
|
var ActiveCameras = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||||
Name: "active_rtsp_cameras_total",
|
Name: "active_rtsp_cameras_total",
|
||||||
Help: "Количество активных rtsp потоков (работающих горутин) для камер.",
|
Help: "Количество активных rtsp потоков (работающих горутин) для камер.",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Metrics establish metrics for an application.
|
||||||
|
func Metrics() {
|
||||||
|
// Register standart metrics.
|
||||||
|
appRegistry := prometheus.NewRegistry()
|
||||||
|
appRegistry.MustRegister(collectors.NewGoCollector())
|
||||||
|
appRegistry.MustRegister(collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}))
|
||||||
|
appRegistry.MustRegister(ActiveCameras)
|
||||||
|
|
||||||
|
//// Endpoint for metrics.
|
||||||
|
http.Handle("/metrics", promhttp.HandlerFor(appRegistry, promhttp.HandlerOpts{}))
|
||||||
|
|
||||||
|
// Start server.
|
||||||
|
err := http.ListenAndServe(":9110", nil)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user