Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export OpenCensus metrics to Stackdriver #118

Merged
merged 1 commit into from
Apr 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 32 additions & 9 deletions cmd/stackdriver-prometheus-sidecar/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"time"

md "cloud.google.com/go/compute/metadata"
oc_stackdriver "contrib.go.opencensus.io/exporter/stackdriver"
"github.com/Stackdriver/stackdriver-prometheus-sidecar/metadata"
"github.com/Stackdriver/stackdriver-prometheus-sidecar/retrieval"
"github.com/Stackdriver/stackdriver-prometheus-sidecar/stackdriver"
Expand Down Expand Up @@ -184,6 +185,7 @@ func main() {
filters []string
metricRenames map[string]string
staticMetadata []scrape.MetricMetadata
monitoringBackends []string

logLevel promlog.AllowedLevel
}{}
Expand Down Expand Up @@ -228,6 +230,9 @@ func main() {
a.Flag("prometheus.api-address", "Address to listen on for UI, API, and telemetry.").
Default("http://127.0.0.1:9090/").URLVar(&cfg.prometheusURL)

a.Flag("monitoring.backend", "Monitoring backend(s) for internal metrics").Default("prometheus").
EnumsVar(&cfg.monitoringBackends, "prometheus", "stackdriver")

a.Flag("web.listen-address", "Address to listen on for UI, API, and telemetry.").
Default("0.0.0.0:9091").StringVar(&cfg.listenAddress)

Expand Down Expand Up @@ -258,20 +263,38 @@ func main() {
level.Info(logger).Log("host_details", Uname())
level.Info(logger).Log("fd_limits", FdLimits())

promExporter, err := oc_prometheus.NewExporter(oc_prometheus.Options{
Registry: prometheus.DefaultRegisterer.(*prometheus.Registry),
})
if err != nil {
level.Error(logger).Log("msg", "Creating Prometheus exporter failed", "err", err)
os.Exit(1)
}
view.RegisterExporter(promExporter)

httpClient := &http.Client{Transport: &ochttp.Transport{}}

if *projectId == "" {
*projectId = getGCEProjectID()
}

for _, backend := range cfg.monitoringBackends {
switch backend {
case "prometheus":
promExporter, err := oc_prometheus.NewExporter(oc_prometheus.Options{
Registry: prometheus.DefaultRegisterer.(*prometheus.Registry),
})
if err != nil {
level.Error(logger).Log("msg", "Creating Prometheus exporter failed", "err", err)
os.Exit(1)
}
view.RegisterExporter(promExporter)
case "stackdriver":
sd, err := oc_stackdriver.NewExporter(oc_stackdriver.Options{ProjectID: *projectId})
if err != nil {
level.Error(logger).Log("msg", "Creating Stackdriver exporter failed", "err", err)
os.Exit(1)
}
defer sd.Flush()
view.RegisterExporter(sd)
view.SetReportingPeriod(60 * time.Second)
default:
level.Error(logger).Log("msg", "Unknown monitoring backend", "backend", backend)
os.Exit(1)
}
jkohen marked this conversation as resolved.
Show resolved Hide resolved
}

var staticLabels = map[string]string{
retrieval.ProjectIDLabel: *projectId,
retrieval.KubernetesLocationLabel: cfg.kubernetesLabels.location,
Expand Down
30 changes: 20 additions & 10 deletions vendor/cloud.google.com/go/compute/metadata/metadata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading