---
# System prepended metadata

title: NET Conf 2020 - Lab-6
tags: [.NET Conf 2020, Event]

---

---
title: 'NET Conf 2020 - Lab-6'
disqus: hackmd
---

.NET Conf 2020 - Lab-6
===

## 快速部署Prometheus與Grafana


>1. 部署應用 metrics-demo-app
```
oc new-app quay.io/4n4nd/metrics-demo-app:workshop

oc expose svc/metrics-demo-app

oc get route/metrics-demo-app
```
>2. 取得相關部署檔
```gherkin=
git clone https://github.com/ChunPingWang/ocp_prometheus.git
```
>或是直接下載 zip 檔後解壓縮

>3. 部署Prometheus
```
oc process -f deploy-prometheus.yaml | oc apply -f -
```
>4. 為Prometheus設定config map
> 將 metrics-demo-app 的 url 放到 target那一行
```gherkin=
apiVersion: template.openshift.io/v1          # Click on 'Copy to Editor' --->
kind: Template
objects:
  - apiVersion: v1          
    kind: ConfigMap
    metadata:
      name: prometheus-demo
    data:     
      prometheus.yml: |     # Prometheus configuration starts below
        global:                   
          external_labels:
            monitor: prometheus
        scrape_configs:
          - job_name: 'prometheus'

            static_configs:
              - targets: ['localhost:9090'] # Configure Prometheus to scrape itself
                labels:
                  group: 'prometheus'
              - targets: ['metrics-demo-app-metrics-demo.2886795278-80-rhsummit1.environments.katacoda.com'] # replace this url
                labels:
                  group: 'pad'
```
>5.為Prometheus重新設設定config map
```
oc process -f prometheus-configmap.yaml | oc apply -f -
oc rollout latest dc/prometheus-demo
```
>6.部署 Grafana
```
oc new-app grafana/grafana:6.6.1
oc expose svc/grafana
```
>7. 在 Grafana上設定 PrometheusQL
>8.設定 Grafana 的 PrometheusQL
```
flask_http_request_total
#兩分鐘 http request平均每秒訊息
rate(flask_http_request_total[2m])
```
>9.
```gherkin=
oc delete all --selector app=metrics-demo-app

```
###### tags: `Event` `.NET Conf 2020`
