Skip to content

Commit

Permalink
add slack and improve hpa
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrie30 committed Apr 15, 2018
1 parent c221efe commit 71ad73c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
21 changes: 21 additions & 0 deletions alerts/slack.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package alerts

import (
"os"

"github.com/bluele/slack"
)

var (
token = os.Getenv("SLACK_API_TOKEN")
channelName = os.Getenv("SLACK_CHANNEL")
)

func main() {

api := slack.New(token)
err := api.ChatPostMessage(channelName, "Hello, world!", nil)
if err != nil {
panic(err)
}
}
16 changes: 12 additions & 4 deletions checks/hpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"k8s.io/api/autoscaling/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
)
Expand All @@ -29,17 +30,24 @@ func HPA() {

hpaWatch, _ := clientset.AutoscalingV1().HorizontalPodAutoscalers("").Watch(metav1.ListOptions{})

data := <-hpaWatch.ResultChan()
for {
select {
case event := <-hpaWatch.ResultChan():
handleEventz(event)
}
}
}

hpa := data.Object.(*v1.HorizontalPodAutoscaler)
func handleEventz(event watch.Event) {
hpa := event.Object.(*v1.HorizontalPodAutoscaler)

if hpa.Status.CurrentReplicas > hpa.Status.DesiredReplicas {
fmt.Println(hpa.ObjectMeta.Namespace + " is scaling DOWN")
fmt.Println("Current VS Desired Replicas: ", hpa.Status.CurrentReplicas, hpa.Status.DesiredReplicas)
fmt.Println("Current CPU utilization: ", hpa.Status.CurrentCPUUtilizationPercentage)
fmt.Println("Current CPU utilization: ", *hpa.Status.CurrentCPUUtilizationPercentage)
} else if hpa.Status.CurrentReplicas < hpa.Status.DesiredReplicas {
fmt.Println(hpa.ObjectMeta.Namespace + " is scaling up")
fmt.Println("Current VS Desired Replicas: ", hpa.Status.CurrentReplicas, hpa.Status.DesiredReplicas)
fmt.Println("Current CPU utilization: ", hpa.Status.CurrentCPUUtilizationPercentage)
fmt.Println("Current CPU utilization: ", *hpa.Status.CurrentCPUUtilizationPercentage)
}
}
12 changes: 6 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ func main() {
fmt.Println("starting kubieous...")

// How often should the checks be performed
podCheckTimer := time.NewTicker(30 * time.Second)
nodeCheckTimer := time.NewTicker(60 * time.Second)
hpaCheckTimer := time.NewTicker(5 * time.Second)
podCheckTimer := time.NewTicker(99999 * time.Second)
nodeCheckTimer := time.NewTicker(99999 * time.Second)

checks.PodEventStream()
// checks.PodEventStream()
go checks.HPA()

// Montoring Loop
for {
Expand All @@ -25,8 +25,8 @@ func main() {
go checks.Pods()
case _ = <-nodeCheckTimer.C:
go checks.Nodes()
case _ = <-hpaCheckTimer.C:
go checks.HPA()
}
}

fmt.Println("stopping kubieous")
}

0 comments on commit 71ad73c

Please sign in to comment.