-
Notifications
You must be signed in to change notification settings - Fork 214
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
5 changed files
with
102 additions
and
77 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
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 |
---|---|---|
@@ -1,34 +1,17 @@ | ||
package shell_operator | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"github.com/flant/shell-operator/pkg/app" | ||
"github.com/flant/shell-operator/pkg/metric_storage" | ||
) | ||
|
||
// defaultHookMetricStorage creates MetricStorage object | ||
// with new registry to scrape hook metrics on separate port. | ||
func defaultHookMetricStorage(ctx context.Context) *metric_storage.MetricStorage { | ||
metricStorage := metric_storage.NewMetricStorage(ctx, app.PrometheusMetricsPrefix, true) | ||
return metricStorage | ||
} | ||
func (op *ShellOperator) setupHookMetricStorage() { | ||
metricStorage := metric_storage.NewMetricStorage(op.ctx, app.PrometheusMetricsPrefix, true) | ||
|
||
func setupHookMetricStorageAndServer(ctx context.Context) (*metric_storage.MetricStorage, error) { | ||
if app.HookMetricsListenPort == "" || app.HookMetricsListenPort == app.ListenPort { | ||
// No separate metric storage required. | ||
return nil, nil | ||
} | ||
op.APIServer.RegisterRoute(http.MethodGet, "/metrics/hooks", metricStorage.Handler().ServeHTTP) | ||
// create new metric storage for hooks | ||
metricStorage := defaultHookMetricStorage(ctx) | ||
// Create new ServeMux, and serve on custom port. | ||
mux := http.NewServeMux() | ||
err := startHttpServer(app.ListenAddress, app.HookMetricsListenPort, mux) | ||
if err != nil { | ||
return nil, err | ||
} | ||
// register scrape handler | ||
mux.Handle("/metrics", metricStorage.Handler()) | ||
return metricStorage, nil | ||
op.MetricStorage = metricStorage | ||
} |
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