-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
280 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
prometheus: | ||
enabled: true | ||
prometheusSpec: | ||
additionalScrapeConfigs: | ||
- job_name: beam-pods | ||
metrics_path: /metrics | ||
scheme: http | ||
honor_labels: true | ||
scrape_timeout: 10s | ||
scrape_interval: 15s | ||
enable_http2: true | ||
follow_redirects: true | ||
kubernetes_sd_configs: | ||
- role: pod | ||
namespaces: | ||
names: | ||
- beam | ||
relabel_configs: | ||
- source_labels: [__meta_kubernetes_pod_label_prometheus_io_scrape] | ||
action: keep | ||
regex: true | ||
- source_labels: [__meta_kubernetes_pod_container_port_number] | ||
action: keep | ||
regex: 9090 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package repository | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"time" | ||
|
||
"github.com/labstack/echo/v4" | ||
"github.com/labstack/echo/v4/middleware" | ||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/collectors" | ||
"github.com/prometheus/client_golang/prometheus/promauto" | ||
"github.com/prometheus/client_golang/prometheus/promhttp" | ||
) | ||
|
||
var PrometheusMetricsAddress = "0.0.0.0:9090" | ||
|
||
type PrometheusRepository struct { | ||
registry *prometheus.Registry | ||
registeredMetrics map[string]prometheus.Collector | ||
ctx *context.Context | ||
enabled bool | ||
} | ||
|
||
func NewMetricsPrometheusRepository(enabled bool) *PrometheusRepository { | ||
if !enabled { | ||
return &PrometheusRepository{ | ||
enabled: false, | ||
} | ||
} | ||
|
||
reg := prometheus.NewRegistry() | ||
reg.MustRegister( | ||
collectors.NewGoCollector(), // Metrics from Go runtime. | ||
collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}), // Metrics about the current UNIX process. | ||
) | ||
|
||
return &PrometheusRepository{ | ||
registry: reg, | ||
registeredMetrics: map[string]prometheus.Collector{}, | ||
enabled: true, | ||
} | ||
} | ||
|
||
func (r *PrometheusRepository) Init() error { | ||
if !r.enabled { | ||
return nil | ||
} | ||
|
||
prometheusServer := echo.New() | ||
prometheusServer.HideBanner = true | ||
prometheusServer.HidePort = true | ||
|
||
prometheusServer.Use(middleware.Recover()) | ||
|
||
prometheusServer.GET("/metrics", echo.WrapHandler(promhttp.HandlerFor(r.registry, promhttp.HandlerOpts{ | ||
EnableOpenMetrics: true, | ||
}))) | ||
|
||
log.Printf("Starting Prometheus metrics server at %s\n", PrometheusMetricsAddress) | ||
|
||
return prometheusServer.Start(PrometheusMetricsAddress) | ||
} | ||
|
||
func (r *PrometheusRepository) ContainerDurationSeconds(containerId string, workerId string, duration time.Duration) { | ||
if !r.enabled { | ||
return | ||
} | ||
|
||
var metricName = "container_duration_seconds" | ||
var collector prometheus.Collector | ||
collector, exists := r.registeredMetrics[metricName] | ||
|
||
if !exists { | ||
collector = promauto.With(r.registry).NewGaugeVec( | ||
prometheus.GaugeOpts{ | ||
Name: metricName, | ||
}, | ||
[]string{"container_id", "worker_id"}, | ||
) | ||
|
||
r.registeredMetrics[metricName] = collector | ||
} | ||
|
||
handle := collector.(*prometheus.GaugeVec) | ||
handle.WithLabelValues(containerId, workerId).Add(duration.Seconds()) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.