Skip to content

Commit

Permalink
adding prometheus
Browse files Browse the repository at this point in the history
  • Loading branch information
Surbhidongaonkar committed Nov 26, 2019
1 parent 638137a commit 2cbf531
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 8 deletions.
Binary file added botkube
Binary file not shown.
5 changes: 4 additions & 1 deletion cmd/botkube/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package main

import (
"fmt"

"github.com/infracloudio/botkube/pkg/bot"
"github.com/infracloudio/botkube/pkg/config"
"github.com/infracloudio/botkube/pkg/controller"
log "github.com/infracloudio/botkube/pkg/logging"
"github.com/infracloudio/botkube/pkg/metrics"
"github.com/infracloudio/botkube/pkg/notify"
"github.com/infracloudio/botkube/pkg/utils"
)
Expand All @@ -30,6 +30,9 @@ func main() {
go mb.Start()
}

//Prometheus metrics
go metrics.ServeMetrics()

// List notifiers
var notifiers []notify.Notifier
if Config.Communications.Slack.Enabled {
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ require (
github.com/onsi/ginkgo v1.10.2 // indirect
github.com/pborman/uuid v1.2.0 // indirect
github.com/pelletier/go-toml v1.5.0 // indirect
github.com/pkg/errors v0.8.1 // indirect
github.com/prometheus/client_golang v1.2.1
github.com/sirupsen/logrus v1.4.2
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.2.0 // indirect
Expand All @@ -42,7 +42,6 @@ require (
go.uber.org/zap v1.10.0 // indirect
golang.org/x/crypto v0.0.0-20191002192127-34f69633bfdc // indirect
golang.org/x/net v0.0.0-20191009170851-d66e71096ffb // indirect
golang.org/x/sys v0.0.0-20191009170203-06d7bd2c5f4f // indirect
golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0 // indirect
google.golang.org/appengine v1.6.5 // indirect
gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d // indirect
Expand Down
51 changes: 46 additions & 5 deletions go.sum

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions helm/botkube/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{{- if .Values.service }}
{{- range $port := .Values.service.ports }}
{{- $service_type := $port.type | default "ClusterIP" }}
---
apiVersion: v1
kind: Service
metadata:
name: {{ include "botkube.fullname" . }}
labels:
app.kubernetes.io/name: {{ include "botkube.name" . }}
helm.sh/chart: {{ include "botkube.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app: botkube
spec:
type: {{ $service_type }}
ports:
- name: {{ $port.name }}
port: {{ $port.port }}
targetPort: {{ $port.port }}
selector:
matchLabels:
component: controller
app: botkube
{{- end }}
{{- end }}
31 changes: 31 additions & 0 deletions helm/botkube/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{{- if .Values.serviceMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ template "botkube.fullname" . }}
labels:
app.kubernetes.io/name: {{ include "botkube.name" . }}
helm.sh/chart: {{ include "botkube.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
component: controller
app: botkube-sm
release: prom

spec:
endpoints:
- interval: {{ .Values.serviceMonitor.interval }}
port: {{ .Values.serviceMonitor.port }}
path: {{ .Values.serviceMonitor.path }}
selector:
matchLabels:
app.kubernetes.io/name: {{ include "botkube.name" . }}
helm.sh/chart: {{ include "botkube.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
component: controller
app: botkube
namespaceSelector:
matchNames:
- {{ .Release.Namespace }}
{{- end }}
17 changes: 17 additions & 0 deletions helm/botkube/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,23 @@ config:
# Set false to disable upgrade notification
upgradeNotifier: true

service: {}
# ports:
# - name: "metrics"
# type: ClusterIP
# port: 2112

serviceMonitor:
## If true, a ServiceMonitor CRD is created for a botkube
## https://github.com/infracloudio/botkube
##
enabled: false
interval: 10s
path: /metrics
port: 2112
labels: {}


resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
Expand Down
12 changes: 12 additions & 0 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package metrics

import (
"github.com/prometheus/client_golang/prometheus/promhttp"
"net/http"
)

// ServeMetrics expose metrics
func ServeMetrics() {
http.Handle("/metrics", promhttp.Handler())
http.ListenAndServe(":2112", nil)
}

0 comments on commit 2cbf531

Please sign in to comment.