Skip to content
This repository has been archived by the owner on Jun 12, 2020. It is now read-only.

Commit

Permalink
fix: refactoring and fix of dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
stebenz committed Jan 8, 2020
1 parent e85baef commit e6069ca
Show file tree
Hide file tree
Showing 12 changed files with 365 additions and 307 deletions.
18 changes: 18 additions & 0 deletions internal/app/v1beta1/crd/ambassador/servicemonitor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ambassador

import "github.com/caos/boom/internal/app/v1beta1/crd/prometheus/servicemonitor"

func GetServicemonitor(monitorlabels map[string]string) *servicemonitor.Config {
endpoint := &servicemonitor.ConfigEndpoint{
Port: "admin",
Path: "/metrics",
}
labels := map[string]string{"app.kubernetes.io/name": "ambassador"}

return &servicemonitor.Config{
Name: "ambassador-servicemonitor",
Endpoints: []*servicemonitor.ConfigEndpoint{endpoint},
MonitorMatchingLabels: monitorlabels,
ServiceMatchingLabels: labels,
}
}
40 changes: 40 additions & 0 deletions internal/app/v1beta1/crd/apiserver/servicemonitor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package apiserver

import "github.com/caos/boom/internal/app/v1beta1/crd/prometheus/servicemonitor"

func GetServicemonitor(monitorlabels map[string]string) *servicemonitor.Config {
metricsRelabelings := make([]*servicemonitor.ConfigMetricRelabeling, 0)
relabeling := &servicemonitor.ConfigMetricRelabeling{
Action: "keep",
Regex: "default;kubernetes;https",
SourceLabels: []string{"__meta_kubernetes_namespace", "__meta_kubernetes_service_name", "__meta_kubernetes_endpoint_port_name"},
}
metricsRelabelings = append(metricsRelabelings, relabeling)

endpoints := make([]*servicemonitor.ConfigEndpoint, 0)
endpoint := &servicemonitor.ConfigEndpoint{
Scheme: "https",
BearerTokenFile: "/var/run/secrets/kubernetes.io/serviceaccount/token",
Port: "https",
Path: "/metrics",
TLSConfig: &servicemonitor.ConfigTLSConfig{
CaFile: "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt",
},
MetricsRelabelings: metricsRelabelings,
}
endpoints = append(endpoints, endpoint)

labels := map[string]string{
"component": "apiserver",
"provider": "kubernetes",
}

return &servicemonitor.Config{
Name: "kubernetes-apiservers-servicemonitor",
Endpoints: endpoints,
MonitorMatchingLabels: monitorlabels,
ServiceMatchingLabels: labels,
NamespaceSelector: []string{"default"},
JobName: "kubernetes-apiservers",
}
}
66 changes: 66 additions & 0 deletions internal/app/v1beta1/crd/argocd/servicemonitor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package argocd

import "github.com/caos/boom/internal/app/v1beta1/crd/prometheus/servicemonitor"

func GetServicemonitors(monitorlabels map[string]string) []*servicemonitor.Config {

servicemonitors := make([]*servicemonitor.Config, 0)

//argocd-application-controller
endpoint := &servicemonitor.ConfigEndpoint{
Port: "metrics",
Path: "/metrics",
}

labels := map[string]string{
"app.kubernetes.io/part-of": "argocd",
"app.kubernetes.io/component": "application-controller",
}

smconfig := &servicemonitor.Config{
Name: "application-controller-servicemonitor",
Endpoints: []*servicemonitor.ConfigEndpoint{endpoint},
MonitorMatchingLabels: monitorlabels,
ServiceMatchingLabels: labels,
JobName: "application-controller",
}
servicemonitors = append(servicemonitors, smconfig)
// argocd-repo-server
endpoint = &servicemonitor.ConfigEndpoint{
Port: "metrics",
Path: "/metrics",
}

labels = map[string]string{
"app.kubernetes.io/part-of": "argocd",
"app.kubernetes.io/component": "repo-server",
}

smconfig = &servicemonitor.Config{
Name: "argocd-repo-server-servicemonitor",
Endpoints: []*servicemonitor.ConfigEndpoint{endpoint},
MonitorMatchingLabels: monitorlabels,
ServiceMatchingLabels: labels,
JobName: "argocd-repo-server",
}
servicemonitors = append(servicemonitors, smconfig)
// argocd-server
endpoint = &servicemonitor.ConfigEndpoint{
Port: "metrics",
Path: "/metrics",
}

labels = map[string]string{
"app.kubernetes.io/part-of": "argocd",
"app.kubernetes.io/component": "server",
}

smconfig = &servicemonitor.Config{
Name: "argocd-server-servicemonitor",
Endpoints: []*servicemonitor.ConfigEndpoint{endpoint},
MonitorMatchingLabels: monitorlabels,
ServiceMatchingLabels: labels,
JobName: "argocd-server",
}
return servicemonitors
}
18 changes: 18 additions & 0 deletions internal/app/v1beta1/crd/certmanager/servicemonitor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package certmanager

import "github.com/caos/boom/internal/app/v1beta1/crd/prometheus/servicemonitor"

func GetServicemonitor(monitorlabels map[string]string) *servicemonitor.Config {
endpoint := &servicemonitor.ConfigEndpoint{
TargetPort: "http",
Path: "/metrics",
}
labels := map[string]string{"app": "cert-manager"}

return &servicemonitor.Config{
Name: "cert-manager-servicemonitor",
Endpoints: []*servicemonitor.ConfigEndpoint{endpoint},
MonitorMatchingLabels: monitorlabels,
ServiceMatchingLabels: labels,
}
}
85 changes: 85 additions & 0 deletions internal/app/v1beta1/crd/kubelet/scrapeconfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package kubelet

import "github.com/caos/boom/internal/app/v1beta1/crd/prometheus"

func GetScrapeConfigs() []*prometheus.AdditionalScrapeConfig {

adconfigs := make([]*prometheus.AdditionalScrapeConfig, 0)

adconfigs = append(adconfigs, getNodes())
adconfigs = append(adconfigs, getCadvisor())

return adconfigs
}

func getNodes() *prometheus.AdditionalScrapeConfig {
relabelings := make([]*prometheus.RelabelConfig, 0)
relabeling := &prometheus.RelabelConfig{
Action: "labelmap",
Regex: "__meta_kubernetes_node_label_(.+)",
}
relabelings = append(relabelings, relabeling)
relabeling = &prometheus.RelabelConfig{
TargetLabel: "__address__",
Replacement: "kubernetes.default.svc:443",
}
relabelings = append(relabelings, relabeling)
relabeling = &prometheus.RelabelConfig{
SourceLabels: []string{"__meta_kubernetes_node_name"},
Regex: "(.+)",
TargetLabel: "__metrics_path__",
Replacement: "/api/v1/nodes/${1}/proxy/metrics",
}
relabelings = append(relabelings, relabeling)

sdconfig := &prometheus.KubernetesSdConfig{
Role: "node",
}

return &prometheus.AdditionalScrapeConfig{
JobName: "kubernetes-nodes",
Scheme: "https",
KubernetesSdConfigs: []*prometheus.KubernetesSdConfig{sdconfig},
BearerTokenFile: "/var/run/secrets/kubernetes.io/serviceaccount/token",
TLSConfig: &prometheus.TLSConfig{
CaFile: "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt",
},
RelabelConfigs: relabelings,
}
}

func getCadvisor() *prometheus.AdditionalScrapeConfig {
relabelings := make([]*prometheus.RelabelConfig, 0)
relabeling := &prometheus.RelabelConfig{
Action: "labelmap",
Regex: "__meta_kubernetes_node_label_(.+)",
}
relabelings = append(relabelings, relabeling)
relabeling = &prometheus.RelabelConfig{
TargetLabel: "__address__",
Replacement: "kubernetes.default.svc:443",
}
relabelings = append(relabelings, relabeling)
relabeling = &prometheus.RelabelConfig{
SourceLabels: []string{"__meta_kubernetes_node_name"},
Regex: "(.+)",
TargetLabel: "__metrics_path__",
Replacement: "/api/v1/nodes/${1}/proxy/metrics/cadvisor",
}
relabelings = append(relabelings, relabeling)

sdconfig := &prometheus.KubernetesSdConfig{
Role: "node",
}

return &prometheus.AdditionalScrapeConfig{
JobName: "kubelet",
Scheme: "https",
KubernetesSdConfigs: []*prometheus.KubernetesSdConfig{sdconfig},
BearerTokenFile: "/var/run/secrets/kubernetes.io/serviceaccount/token",
TLSConfig: &prometheus.TLSConfig{
CaFile: "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt",
},
RelabelConfigs: relabelings,
}
}
32 changes: 32 additions & 0 deletions internal/app/v1beta1/crd/kubestatemetrics/servicemonitor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package kubestatemetrics

import "github.com/caos/boom/internal/app/v1beta1/crd/prometheus/servicemonitor"

func GetServicemonitor(monitorlabels map[string]string) *servicemonitor.Config {

relabelings := make([]*servicemonitor.ConfigRelabeling, 0)
relabeling := &servicemonitor.ConfigRelabeling{
Action: "labeldrop",
Regex: "(pod|service|endpoint|namespace)",
}
relabelings = append(relabelings, relabeling)

endpoint := &servicemonitor.ConfigEndpoint{
Port: "http",
Path: "/metrics",
HonorLabels: true,
Relabelings: relabelings,
}

labels := map[string]string{
"app.kubernetes.io/name": "kube-state-metrics",
}

return &servicemonitor.Config{
Name: "kube-state-metrics-servicemonitor",
Endpoints: []*servicemonitor.ConfigEndpoint{endpoint},
MonitorMatchingLabels: monitorlabels,
ServiceMatchingLabels: labels,
JobName: "kube-state-metrics",
}
}
Loading

0 comments on commit e6069ca

Please sign in to comment.