Skip to content

Commit aa387a4

Browse files
committed
feat(grafana): add mysql and mimir
1 parent 38d36f6 commit aa387a4

File tree

14 files changed

+206
-17
lines changed

14 files changed

+206
-17
lines changed

app/media/MyGrafana/loki.yml

Lines changed: 0 additions & 12 deletions
This file was deleted.

app/media/MyGrafana/mysql.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: 1
2+
datasources:
3+
- name: MySQL
4+
type: mysql
5+
url: ' localhost:3306'
6+
user: grafana
7+
editable: true
8+
jsonData:
9+
tlsAuth: true
10+
tlsSkipVerify: true
11+
database: grafana
12+
maxOpenConns: 100
13+
maxIdleConns: 100
14+
maxIdleConnsAuto: true
15+
connMaxLifetime: 14400
16+
secureJsonData:
17+
password: ${GRAFANA_MYSQL_PASSWORD}
18+
tlsClientCert: ${GRAFANA_TLS_CLIENT_CERT}
19+
tlsCACert: ${GRAFANA_TLS_CA_CERT}

app/models/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,9 @@
99
from .gitlab_models import *
1010
from app.models.grafana.alert_managers_models import *
1111
from app.models.grafana.elastcsearch_models import *
12-
from app.models.grafana.loki_models import *
12+
from app.models.grafana.loki_models import *
13+
from app.models.grafana.mimir_models import *
14+
from app.models.grafana.mysql_models import *
15+
from app.models.grafana.postgresql_models import *
16+
from app.models.grafana.prometheus_models import *
17+
from app.models.grafana.tempo_models import *

app/models/grafana/mimir_models.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from typing import List, Optional
2+
from pydantic import BaseModel, validator, ValidationError
3+
4+
5+
6+
7+
class MimirInput(BaseModel):
8+
name:str = "Mimir"
9+
uid:str = "mimir"
10+
url:str = "http://mimir-nginx.mimir.svc.cluster.local/prometheus"
11+
editable: bool = True
12+
httpHeaderName1:str = "X-Scope-OrgID"
13+
alertmanagerUid:str = "alertmanager"
14+
httpHeaderValue1:str = "pods"
15+
16+

app/models/grafana/mysql_models.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from typing import List, Optional
2+
from pydantic import BaseModel, validator, ValidationError
3+
4+
5+
6+
class TLS(BaseModel):
7+
tlsClientCert:str = "${GRAFANA_TLS_CLIENT_CERT}"
8+
tlsCACert:str = "${GRAFANA_TLS_CA_CERT}"
9+
tlsAuth:bool = True
10+
tlsSkipVerify:bool = True
11+
12+
class MysqlInput(BaseModel):
13+
name:str = "MySQL"
14+
url:str = " localhost:3306"
15+
user:str = "grafana"
16+
editable: bool = True
17+
database:str = "grafana"
18+
maxOpenConns:int = 100
19+
maxIdleConns:int = 100
20+
maxIdleConnsAuto:bool = True
21+
connMaxLifetime:int = 14400
22+
password:str = "${GRAFANA_MYSQL_PASSWORD}"
23+
tls :Optional[TLS]
24+
25+

app/models/grafana/postgresql_models.py

Whitespace-only changes.

app/models/grafana/prometheus_models.py

Whitespace-only changes.

app/models/grafana/tempo_models.py

Whitespace-only changes.

app/routes/grafana_data_sources.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
from app.app_instance import app
2-
from app.models import (AlertManagerInput,Output,ElasticSearchInput,LokiInput)
2+
from app.models import (AlertManagerInput,Output,ElasticSearchInput,LokiInput,MimirInput,MysqlInput)
33
from app.template_generators.grafana_data_sources.alertmanager import alert_manager_template
44
from app.template_generators.grafana_data_sources.elasticsearch import elasticsearch_template
55
from app.template_generators.grafana_data_sources.loki import loki_template
6+
from app.template_generators.grafana_data_sources.mimir import mimir_template
7+
from app.template_generators.grafana_data_sources.mysql import mysql_template
68
import shutil
79
import os
810

911
@app.post("/api/grafana/alertmanager")
10-
async def alertmanager_template(request:AlertManagerInput) -> Output:
12+
async def alertmanager_template_route(request:AlertManagerInput) -> Output:
1113

1214
dir = 'app/media/MyGrafana'
1315
if os.path.exists(dir):
@@ -18,7 +20,7 @@ async def alertmanager_template(request:AlertManagerInput) -> Output:
1820
return Output(output='output')
1921

2022
@app.post("/api/grafana/elasticsearch")
21-
async def elastic_template(request:ElasticSearchInput) -> Output:
23+
async def elastic_template_route(request:ElasticSearchInput) -> Output:
2224

2325
dir = 'app/media/MyGrafana'
2426
if os.path.exists(dir):
@@ -29,12 +31,35 @@ async def elastic_template(request:ElasticSearchInput) -> Output:
2931
return Output(output='output')
3032

3133
@app.post("/api/grafana/loki")
32-
async def elastic_template(request:LokiInput) -> Output:
34+
async def loki_template_route(request:LokiInput) -> Output:
3335

3436
dir = 'app/media/MyGrafana'
3537
if os.path.exists(dir):
3638
shutil.rmtree(dir)
3739

3840
loki_template(request)
3941

42+
return Output(output='output')
43+
44+
45+
@app.post("/api/grafana/mimir")
46+
async def mimir_template_route(request:MimirInput) -> Output:
47+
48+
dir = 'app/media/MyGrafana'
49+
if os.path.exists(dir):
50+
shutil.rmtree(dir)
51+
52+
mimir_template(request)
53+
54+
return Output(output='output')
55+
56+
@app.post("/api/grafana/mysql")
57+
async def mysql_template_route(request:MysqlInput) -> Output:
58+
59+
dir = 'app/media/MyGrafana'
60+
if os.path.exists(dir):
61+
shutil.rmtree(dir)
62+
63+
mysql_template(request)
64+
4065
return Output(output='output')
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import yaml
2+
import os
3+
4+
def mimir_template(input):
5+
6+
json_template = {
7+
"apiVersion": 1,
8+
"datasources": [
9+
{
10+
"name": input.name,
11+
"uid": input.uid,
12+
"type": "prometheus",
13+
"access": "proxy",
14+
"orgId": 1,
15+
"url": input.url,
16+
"editable": input.editable,
17+
"version": 1,
18+
"jsonData": {
19+
"httpHeaderName1": input.httpHeaderName1,
20+
"alertmanagerUid": input.alertmanagerUid
21+
},
22+
"secureJsonData": {
23+
"httpHeaderValue1": input.httpHeaderValue1
24+
}
25+
}
26+
]
27+
}
28+
29+
dir = "app/media/MyGrafana"
30+
os.makedirs(dir)
31+
os.path.join(dir, 'mimir.yml')
32+
33+
file=open("app/media/MyGrafana/mimir.yml","w")
34+
yaml.dump(json_template,file,default_flow_style=False,sort_keys=False)
35+
36+

0 commit comments

Comments
 (0)