Skip to content

Commit 10fb5b7

Browse files
author
gmarek
committed
SLO monitor first commit
1 parent 1a3af80 commit 10fb5b7

13 files changed

+891
-0
lines changed

slo-monitor/Dockerfile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
# Copyright 2017 Google Inc. All rights reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
FROM alpine:3.5
17+
MAINTAINER Marek Grabowski <[email protected]>
18+
ADD build/slo-monitor slo-monitor
19+
20+
CMD ["/slo-monitor"]

slo-monitor/Makefile

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright 2017 The Kubernetes Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
PACKAGE = k8s.io/perf-tests/slo-monitor
16+
TAG = 0.9
17+
REPOSITORY = google-containers
18+
19+
all: build
20+
21+
deps:
22+
go get -u github.com/tools/godep
23+
24+
build: src/monitors/pod_monitor.go src/monitors/util.go src/monitors/store.go src/monitors/watcher.go src/main/slo-monitor.go deps
25+
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 godep go build -a -o build/slo-monitor src/main/slo-monitor.go
26+
27+
push:
28+
sudo docker build . -t gcr.io/$(REPOSITORY)/slo-monitor:$(TAG)
29+
gcloud docker push gcr.io/$(REPOSITORY)/slo-monitor:$(TAG)
30+
31+
test: src
32+
godep go test ${PACKAGE}/src -v
33+
34+
clean:
35+
rm -f build/slo-monitor

slo-monitor/OWNERS

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
approvers:
2+
- gmarek
3+
- wojtek-t
4+
reviewers:
5+
- gmarek
6+
- wojtek-t
7+

slo-monitor/README.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Kubernetes Performance SLO monitor
2+
3+
This tool monitors Performance SLOs that are unavailable from the API server and exposes Prometheus metrics for them.
4+
5+
It can be run anywhere and only requirement is that it needs to be able to talk to the API server.
6+
7+
# Usage
8+
9+
SLO monitor is a simple pod that needs to be able to read Pods and Events. On top of that it should work as long as it can communicate with the API server.
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Deployment config for performance monitor. To be used when deploying in on the cluster.
2+
# RBAC: requires view access to Pods and Events.
3+
apiVersion: extensions/v1beta1
4+
kind: Deployment
5+
metadata:
6+
name: slo-monitor
7+
namespace: kube-system
8+
labels:
9+
app: slo-monitor
10+
spec:
11+
selector:
12+
matchLabels:
13+
app: slo-monitor
14+
template:
15+
metadata:
16+
labels:
17+
app: slo-monitor
18+
spec:
19+
containers:
20+
- name: slo-monitor
21+
image: gcr.io/google-containers/slo-monitor:0.9
22+
command:
23+
- /slo-monitor
24+
- --alsologtostderr=true
25+
imagePullPolicy: Always
26+
ports:
27+
- name: metrics
28+
containerPort: 8080
29+
resources:
30+
requests:
31+
cpu: 300m
32+
memory: 100Mi
33+
limits:
34+
cpu: 300m
35+
memory: 100Mi
36+
restartPolicy: Always

slo-monitor/slo-monitor-pod.yaml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Deployment config for performance monitor. To be used when deploying from manifest on the master machine.
2+
# RBAC: uses insecure port :8080
3+
apiVersion: v1
4+
kind: Pod
5+
metadata:
6+
name: slo-monitor
7+
namespace: kube-system
8+
labels:
9+
app: slo-monitor
10+
spec:
11+
hostNetwork: true
12+
containers:
13+
- name: slo-monitor
14+
image: gcr.io/google-containers/slo-monitor:0.9
15+
command:
16+
- /slo-monitor
17+
- --alsologtostderr=true
18+
- --listen-url=:8081
19+
- --kubernetes-url=http://127.0.0.1:8080?inClusterConfig=0&useServiceAccount=0
20+
imagePullPolicy: Always
21+
ports:
22+
- name: metrics
23+
containerPort: 8081
24+
resources:
25+
requests:
26+
cpu: 300m
27+
memory: 100Mi
28+
limits:
29+
cpu: 300m
30+
memory: 100Mi
31+
restartPolicy: Always

slo-monitor/slo-monitor-service.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Service that exposes slo-monitor to the external world using ingress.
2+
# Use only if you need to access it from outside of the cluster.
3+
apiVersion: v1
4+
kind: Service
5+
metadata:
6+
name: slo-monitor
7+
namespace: kube-system
8+
labels:
9+
app: slo-monitor
10+
spec:
11+
selector:
12+
app: slo-monitor
13+
ports:
14+
- name: metrics
15+
port: 80
16+
targetPort: metrics
17+
type: LoadBalancer

slo-monitor/src/main/slo-monitor.go

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
Copyright 2017 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package main
18+
19+
import (
20+
"flag"
21+
"net/http"
22+
"net/url"
23+
"time"
24+
25+
"k8s.io/perf-tests/slo-monitor/src/monitors"
26+
27+
clientset "k8s.io/client-go/kubernetes"
28+
29+
"k8s.io/contrib/cluster-autoscaler/config"
30+
31+
"github.com/golang/glog"
32+
"github.com/prometheus/client_golang/prometheus"
33+
"github.com/spf13/pflag"
34+
)
35+
36+
var (
37+
kubernetesURL string
38+
listenURL string
39+
purgeAfterSeconds int32
40+
)
41+
42+
func registerFlags(fs *pflag.FlagSet) {
43+
fs.StringVar(&kubernetesURL, "kubernetes-url", "", "Kubernetes master location. Leave blank for default")
44+
fs.StringVar(&listenURL, "listen-url", ":8080", "URL on which monitor should serve metrics")
45+
fs.Int32Var(&purgeAfterSeconds, "purge-after-seconds", 120, "Time after which deleted entries are purged.")
46+
}
47+
48+
func createKubeClient() clientset.Interface {
49+
url, err := url.Parse(kubernetesURL)
50+
if err != nil {
51+
glog.Fatalf("Failed to parse Kuberentes url: %v", err)
52+
}
53+
54+
kubeConfig, err := config.GetKubeClientConfig(url)
55+
if err != nil {
56+
glog.Fatalf("Failed to build Kuberentes client configuration: %v", err)
57+
}
58+
kubeConfig.ContentType = "application/vnd.kubernetes.protobuf"
59+
60+
return clientset.NewForConfigOrDie(kubeConfig)
61+
}
62+
63+
func main() {
64+
registerFlags(pflag.CommandLine)
65+
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
66+
pflag.Parse()
67+
68+
glog.Infof("Starting Performance SLO monitor on port %v", listenURL)
69+
70+
monitors.Register()
71+
http.Handle("/metrics", prometheus.Handler())
72+
73+
kubeClient := createKubeClient()
74+
75+
stopCh := make(chan struct{})
76+
defer close(stopCh)
77+
78+
monitor := monitors.NewPodStartupLatencyDataMonitor(kubeClient, time.Duration(purgeAfterSeconds)*time.Second)
79+
go func() {
80+
if err := monitor.Run(stopCh); err != nil {
81+
panic(err)
82+
}
83+
}()
84+
85+
glog.Fatal(http.ListenAndServe(listenURL, nil))
86+
}

0 commit comments

Comments
 (0)