-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Arshi Aggarwal <arshiagg@users.noreply.github.com>
- Loading branch information
0 parents
commit 70a83cb
Showing
6 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM ruby:2.4.1-slim | ||
|
||
# Install gems | ||
RUN gem install bundler | ||
COPY Gemfile . | ||
RUN bundle | ||
|
||
# Upload exporter | ||
COPY exporter.rb . | ||
|
||
ENTRYPOINT ["ruby", "exporter.rb"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
source "https://rubygems.org" | ||
|
||
#this works with ruby 2.4.1 | ||
|
||
gem "sinatra", "2.0.0" | ||
gem "httparty", "0.15.5" | ||
gem "json", "2.0.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# Gives Prometheus permission to share the cluster | ||
apiVersion: rbac.authorization.k8s.io/v1beta1 | ||
kind: ClusterRole | ||
metadata: | ||
name: prometheus | ||
namespace: kube-system | ||
rules: | ||
- apiGroups: [""] | ||
resources: | ||
- nodes | ||
- nodes/proxy | ||
- services | ||
- endpoints | ||
- pods | ||
verbs: ["get", "list", "watch"] | ||
- nonResourceURLs: ["/metrics"] | ||
verbs: ["get"] | ||
--- | ||
# Prometheus is a process and hence needs service account access | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: prometheus | ||
namespace: kube-system | ||
# Binds Prometheus to the kube-system namespace | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1beta1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: prometheus | ||
namespace: kube-system | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: prometheus | ||
subjects: | ||
- kind: ServiceAccount | ||
name: prometheus | ||
namespace: kube-system | ||
# Deploy prometheus as a replicaset with one container | ||
--- | ||
apiVersion: extensions/v1beta1 | ||
kind: ReplicaSet | ||
metadata: | ||
name: contiv-prometheus | ||
namespace: kube-system | ||
labels: | ||
k8s-app: contiv-prometheus | ||
spec: | ||
replicas: 1 | ||
template: | ||
metadata: | ||
name: contiv-prometheus | ||
labels: | ||
k8s-app: contiv-prometheus | ||
annotations: | ||
scheduler.alpha.kubernetes.io/critical-pod: '' | ||
spec: | ||
tolerations: | ||
- key: node-role.kubernetes.io/master | ||
effect: NoSchedule | ||
nodeSelector: | ||
node-role.kubernetes.io/master: "" | ||
containers: | ||
- name: contiv-prometheus | ||
image: prom/prometheus | ||
volumeMounts: | ||
- mountPath: /etc/prometheus | ||
name: var-contiv | ||
volumes: | ||
- name: var-contiv | ||
hostPath: | ||
path: /var/contiv | ||
serviceAccountName: prometheus | ||
# Expose prometheus as a service | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: prometheus | ||
namespace: kube-system | ||
spec: | ||
type: NodePort | ||
selector: | ||
k8s-app: contiv-prometheus | ||
ports: | ||
- protocol: TCP | ||
port: 9090 | ||
nodePort: 30000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require "httparty" | ||
require "json" | ||
require "sinatra" | ||
|
||
set :bind, '0.0.0.0' | ||
|
||
get '/metrics' do | ||
url = "http://localhost:9090/svcstats" | ||
|
||
records = [] | ||
|
||
# do HTTParty.get | ||
resp = HTTParty.get(url) | ||
|
||
# parse result as json | ||
data = JSON.parse(resp.body) | ||
|
||
# convert JSON to prometheus format | ||
data.keys.each do |ip| | ||
x = "ip_#{ip}_" | ||
svcstats = data[ip]["SvcStats"] | ||
|
||
svcstats.keys.each do |svc_ip| | ||
y = x + "svcip_#{svc_ip}_" | ||
provstats = svcstats[svc_ip]["ProvStats"] | ||
|
||
provstats.keys.each do |prov_ip| | ||
z = y + "provip_#{prov_ip}" | ||
z = z.gsub(".", "_") | ||
records << "#{z}_bytes_in #{provstats[prov_ip]["BytesIn"]}" | ||
records << "#{z}_bytes_out #{provstats[prov_ip]["BytesOut"]}" | ||
records << "#{z}_packets_in #{provstats[prov_ip]["PacketsIn"]}" | ||
records << "#{z}_packets_out #{provstats[prov_ip]["PacketsOut"]}" | ||
end | ||
end | ||
end | ||
|
||
# return prometheus formatted string | ||
records.join("\n") + "\n" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Prometheus configuration to scrape all netplugin endpoints every 5 seconds | ||
scrape_configs: | ||
- job_name: 'kubernetes-pods' | ||
|
||
kubernetes_sd_configs: | ||
- role: pod | ||
|
||
relabel_configs: | ||
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape] | ||
action: keep | ||
regex: true | ||
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path] | ||
action: replace | ||
target_label: __metrics_path__ | ||
regex: (.+) | ||
- source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port] | ||
action: replace | ||
regex: ([^:]+)(?::\d+)?;(\d+) | ||
replacement: $1:$2 | ||
target_label: __address__ | ||
- action: labelmap | ||
regex: __meta_kubernetes_pod_label_(.+) | ||
- source_labels: [__meta_kubernetes_namespace] | ||
action: replace | ||
target_label: kubernetes_namespace | ||
- source_labels: [__meta_kubernetes_pod_name] | ||
action: replace | ||
target_label: kubernetes_pod_name |