-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
223 additions
and
9 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
FROM python:alpine3.7 | ||
COPY . /app | ||
WORKDIR /app | ||
RUN pip install flask && pip3 install --no-cache-dir Flask flask_prometheus_metrics | ||
RUN pip install flask && pip3 install prometheus-flask-exporter | ||
EXPOSE 5000 | ||
CMD ["python", "./index.py"] |
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
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
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
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,81 @@ | ||
apiVersion: v1 | ||
kind: PersistentVolumeClaim | ||
metadata: | ||
name: grafana-pvc | ||
spec: | ||
accessModes: | ||
- ReadWriteOnce | ||
resources: | ||
requests: | ||
storage: 1Gi | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
labels: | ||
app: grafana | ||
name: grafana | ||
spec: | ||
selector: | ||
matchLabels: | ||
app: grafana | ||
template: | ||
metadata: | ||
labels: | ||
app: grafana | ||
spec: | ||
securityContext: | ||
fsGroup: 472 | ||
supplementalGroups: | ||
- 0 | ||
containers: | ||
- name: grafana | ||
image: grafana/grafana:9.1.0 | ||
imagePullPolicy: IfNotPresent | ||
ports: | ||
- containerPort: 3000 | ||
name: http-grafana | ||
protocol: TCP | ||
readinessProbe: | ||
failureThreshold: 3 | ||
httpGet: | ||
path: /robots.txt | ||
port: 3000 | ||
scheme: HTTP | ||
initialDelaySeconds: 10 | ||
periodSeconds: 30 | ||
successThreshold: 1 | ||
timeoutSeconds: 2 | ||
livenessProbe: | ||
failureThreshold: 3 | ||
initialDelaySeconds: 30 | ||
periodSeconds: 10 | ||
successThreshold: 1 | ||
tcpSocket: | ||
port: 3000 | ||
timeoutSeconds: 1 | ||
resources: | ||
requests: | ||
cpu: 250m | ||
memory: 750Mi | ||
volumeMounts: | ||
- mountPath: /var/lib/grafana | ||
name: grafana-pv | ||
volumes: | ||
- name: grafana-pv | ||
persistentVolumeClaim: | ||
claimName: grafana-pvc | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: grafana | ||
spec: | ||
ports: | ||
- port: 3000 | ||
protocol: TCP | ||
targetPort: http-grafana | ||
selector: | ||
app: grafana | ||
sessionAffinity: None | ||
type: LoadBalancer |
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 |
---|---|---|
@@ -1,7 +1,18 @@ | ||
from flask import Flask | ||
from prometheus_client import make_wsgi_app | ||
from werkzeug.middleware.dispatcher import DispatcherMiddleware | ||
from prometheus_flask_exporter import PrometheusMetrics | ||
|
||
|
||
app = Flask(__name__) | ||
metrics = PrometheusMetrics(app) | ||
|
||
@app.route("/") | ||
def hello(): | ||
return "Hello World!" | ||
if __name__ == "__main__": | ||
app.run(host="0.0.0.0", port=int("5000"), debug=True) | ||
|
||
|
||
# Plug metrics WSGI app to your main app with dispatcher | ||
dispatcher = DispatcherMiddleware(app.wsgi_app, {"/metrics": make_wsgi_app()}) | ||
|
||
app.run(host='0.0.0.0', port=5000) |
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
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,5 @@ | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
namespace: default | ||
name: prometheus |
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,17 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: discover | ||
rules: | ||
- apiGroups: [""] | ||
resources: | ||
- nodes | ||
- services | ||
- endpoints | ||
- pods | ||
verbs: ["get", "list", "watch"] | ||
- apiGroups: | ||
- extensions | ||
resources: | ||
- ingresses | ||
verbs: ["get", "list", "watch"] |
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,39 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: prometheus-server-conf | ||
namespace: default | ||
labels: | ||
name: prometheus-server-conf | ||
data: | ||
prometheus.yml: |- | ||
scrape_configs: | ||
- job_name: 'kubernetes-service-endpoints' | ||
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. | ||
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. | ||
# scrape_timeout is set to the global default (10s). | ||
# Alertmanager configuration | ||
alerting: | ||
alertmanagers: | ||
- static_configs: | ||
- targets: | ||
# - alertmanager:9093 | ||
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'. | ||
rule_files: | ||
# - "first_rules.yml" | ||
# - "second_rules.yml" | ||
# A scrape configuration containing exactly one endpoint to scrape: | ||
# Here it's Prometheus itself. | ||
scrape_configs: | ||
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config. | ||
- job_name: "scraping_pods" | ||
# metrics_path defaults to '/metrics' | ||
# scheme defaults to 'http'. | ||
static_configs: | ||
- targets: ["helloworldv2:8080"] |
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,30 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: prometheus | ||
namespace: default | ||
labels: | ||
app: prometheus | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: prometheus | ||
template: | ||
metadata: | ||
labels: | ||
app: prometheus | ||
spec: | ||
serviceAccountName: prometheus | ||
containers: | ||
- name: prometheus | ||
image: prom/prometheus:latest | ||
ports: | ||
- containerPort: 9090 | ||
volumeMounts: | ||
- name: config | ||
mountPath: /etc/prometheus | ||
volumes: | ||
- name: config | ||
configMap: | ||
name: prometheus-server-conf |
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 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: prometheus-discoverer | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: discoverer | ||
subjects: | ||
- kind: ServiceAccount | ||
name: prometheus | ||
namespace: default |
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,10 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: prometheus | ||
namespace: default | ||
spec: | ||
selector: | ||
app: prometheus | ||
ports: | ||
- port: 9090 |