Skip to content

Commit 5570a59

Browse files
committed
first commit
0 parents  commit 5570a59

19 files changed

Lines changed: 530 additions & 0 deletions

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FLASK_APP_SECRET=
2+
FLASK_APP=server.py
3+
FLASK_ENV=

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
__pycache__/
2+
venv/
3+
.venv/
4+
.env
5+
*.pyc
6+
.coverage
7+
.vscode/
8+
.DS_Store
9+
.idea/
10+
.pytest_cache/
11+

Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# use an official python runtime as the base image
2+
FROM python:3.10
3+
4+
# set the (container) working directory
5+
WORKDIR /app
6+
7+
8+
# install netcat
9+
RUN apt-get update && \
10+
apt-get install netcat-traditional -y
11+
12+
COPY requirements.txt /app/requirements.txt
13+
14+
15+
# install dependencies
16+
RUN pip install -r requirements.txt
17+
18+
# copy current (local) directory contents into the container
19+
COPY . /app
20+
21+
22+
# make port available to the world outside this container
23+
EXPOSE 50000
24+
25+
# connect to start script when db is being used
26+
CMD ["flask", "run", "--host=0.0.0.0", "--port=50000"]

api_docs.yml

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
---
2+
basepath: "/"
3+
4+
paths:
5+
"/projects/{project_id}/metrics/cpu":
6+
post:
7+
tags:
8+
- projects
9+
consumes:
10+
- application/json
11+
produces:
12+
- application/json
13+
parameters:
14+
- in: header
15+
name: Authorization
16+
required: true
17+
description: "Bearer [token]"
18+
type: string
19+
- in: path
20+
name: project_id
21+
required: true
22+
type: string
23+
- in: body
24+
name: project metrics
25+
schema:
26+
properties:
27+
start:
28+
type: integer
29+
format: float
30+
end:
31+
type: integer
32+
format: float
33+
step:
34+
type: string
35+
36+
responses:
37+
200:
38+
description: "Cpu metrics for a Project"
39+
404:
40+
description: "metrics not found"
41+
400:
42+
description: "Bad request"
43+
500:
44+
description: "Internal Server Error"
45+
46+
"/projects/{project_id}/metrics/memory":
47+
post:
48+
tags:
49+
- projects
50+
consumes:
51+
- application/json
52+
produces:
53+
- application/json
54+
parameters:
55+
- in: header
56+
name: Authorization
57+
required: true
58+
description: "Bearer [token]"
59+
type: string
60+
- in: path
61+
name: project_id
62+
required: true
63+
type: string
64+
- in: body
65+
name: project metrics
66+
schema:
67+
properties:
68+
start:
69+
type: number
70+
format: float
71+
end:
72+
type: number
73+
format: float
74+
step:
75+
type: string
76+
77+
responses:
78+
200:
79+
description: "Metrics for a single Project"
80+
404:
81+
description: "Project metrics not found"
82+
400:
83+
description: "Bad request"
84+
500:
85+
description: "Internal Server Error"
86+
87+
"/projects/{project_id}/apps/{app_id}/metrics/memory":
88+
post:
89+
tags:
90+
- apps
91+
consumes:
92+
- application/json
93+
produces:
94+
- application/json
95+
parameters:
96+
- in: header
97+
name: Authorization
98+
required: true
99+
description: "Bearer [token]"
100+
type: string
101+
- in: path
102+
name: project_id
103+
required: true
104+
type: string
105+
- in: path
106+
name: app_id
107+
required: true
108+
type: string
109+
- in: body
110+
name: app metrics
111+
schema:
112+
properties:
113+
start:
114+
type: number
115+
format: float
116+
end:
117+
type: number
118+
format: float
119+
step:
120+
type: string
121+
122+
responses:
123+
200:
124+
description: "Memory Usage metrics for an Application"
125+
404:
126+
description: "Application metrics not found"
127+
400:
128+
description: "Bad request"
129+
500:
130+
description: "Internal Server Error"
131+
132+
"/projects/{project_id}/metrics/network":
133+
post:
134+
tags:
135+
- projects
136+
consumes:
137+
- application/json
138+
produces:
139+
- application/json
140+
parameters:
141+
- in: header
142+
name: Authorization
143+
required: true
144+
description: "Bearer [token]"
145+
type: string
146+
- in: path
147+
name: project_id
148+
required: true
149+
type: string
150+
- in: body
151+
name: project metrics
152+
schema:
153+
properties:
154+
start:
155+
type: number
156+
format: float
157+
end:
158+
type: number
159+
format: float
160+
step:
161+
type: string
162+
163+
responses:
164+
200:
165+
description: "Network metrics for a single Project"
166+
404:
167+
description: "Project metrics not found"
168+
400:
169+
description: "Bad request"
170+
500:
171+
description: "Internal Server Error"

app/__init__.py

Whitespace-only changes.

app/controllers/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .project import (ProjectCPUView, ProjectMemoryUsageView,
2+
ProjectNetworkRequestView, ProjectStorageUsageView)
3+
from .index import (IndexView)

app/controllers/index.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from flask_restful import Resource
2+
3+
4+
class IndexView(Resource):
5+
6+
def get(self):
7+
return dict(status="success", message="Welcome to Crane Cloud Monitoring API")

app/controllers/project.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import os
2+
import datetime
3+
import json
4+
from types import SimpleNamespace
5+
6+
7+
import datetime
8+
from prometheus_http_client import Prometheus
9+
from flask_restful import Resource, request
10+
from flask import current_app, render_template
11+
12+
# Todo: figure out a way to connect to projects and get projects
13+
14+
15+
class ProjectMemoryUsageView(Resource):
16+
17+
# @jwt_required
18+
def post(self, project_id):
19+
return dict(status='success', data=dict()), 200
20+
21+
22+
class ProjectCPUView(Resource):
23+
# @jwt_required
24+
def post(self, project_id):
25+
return dict(status='success', data=dict()), 200
26+
27+
28+
class ProjectNetworkRequestView(Resource):
29+
# @jwt_required
30+
def post(self, project_id):
31+
return dict(status='success', data=dict()), 200
32+
33+
34+
class ProjectStorageUsageView(Resource):
35+
# @jwt_required
36+
def post(self, project_id):
37+
return dict(status='success', data=dict()), 200

app/helpers/__init__.py

Whitespace-only changes.

app/models/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)