-
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.
chore: Added a data collection agent
- Loading branch information
Showing
8 changed files
with
128 additions
and
15 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,74 @@ | ||
from flask import Flask, request, jsonify | ||
from datetime import datetime | ||
import pymongo | ||
import os | ||
|
||
app = Flask(__name__) | ||
|
||
|
||
myclient = pymongo.MongoClient(os.getenv("MONGODB_URI")) | ||
mydb = myclient["metrics"] | ||
|
||
|
||
@app.route('/save', methods=['GET', 'POST']) | ||
def add_message(): | ||
content = request.json | ||
mycol = mydb[content['service']] | ||
x = mycol.insert_one({"data": content['data'], "time": datetime.now()}) | ||
return jsonify({"success": True}) | ||
|
||
if __name__ == '__main__': | ||
app.run(host= '0.0.0.0',debug=True) | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
# import grequests | ||
# import urllib.parse | ||
# import numpy as np | ||
|
||
# services = [ | ||
# "service-1-18f76028", | ||
# "service-10-18f76028", | ||
# "service-2-18f76028", | ||
# "service-3-18f76028", | ||
# "service-4-18f76028", | ||
# "service-5-18f76028", | ||
# "service-6-18f76028", | ||
# "service-7-18f76028", | ||
# "service-8-18f76028", | ||
# "service-9-18f76028", | ||
# ] | ||
|
||
# samples = ["1m", "5m", "15m"] | ||
|
||
# metrics = [ | ||
# 'rate(requests_sent_total{serviceName="SERVICE_NAME"}[SAMPLE])', | ||
# 'sum by (serviceName) (rate(requests_received_total{serviceName="SERVICE_NAME"}[SAMPLE]))', | ||
# 'rate(request_duration_seconds_sum{serviceName="SERVICE_NAME"}[SAMPLE])', | ||
# 'avg_over_time(cpu_seconds{serviceName="SERVICE_NAME"}[SAMPLE])', | ||
# 'avg_over_time(memory_usage_bytes{serviceName="SERVICE_NAME"}[SAMPLE])', | ||
# 'rate(acknowledged_bytes_sum{serviceName="SERVICE_NAME"}[SAMPLE])', | ||
# 'rate(transmitted_bytes_sum{serviceName="SERVICE_NAME"}[SAMPLE])', | ||
# 'avg_over_time(backlog{level="1",serviceName="SERVICE_NAME"}[SAMPLE])', | ||
# 'sum by (serviceName) (avg_over_time(backlog{level!="1",serviceName="SERVICE_NAME"}[SAMPLE]))', | ||
# ] | ||
|
||
# requests = [] | ||
|
||
# def chunks(l, n): | ||
# n = max(1, n) | ||
# return (l[i:i+n] for i in range(0, len(l), n)) | ||
|
||
# for service in services: | ||
# for sample in samples: | ||
# for metric in metrics: | ||
# query = metric.replace("SERVICE_NAME", service).replace("SAMPLE", sample) | ||
# url = "http://127.0.0.1:9090/api/v1/query?query="+urllib.parse.quote_plus(query) | ||
# requests.append(grequests.get(url)) | ||
# respon = grequests.map(requests) | ||
# f | ||
# break; |
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,7 @@ | ||
import json | ||
import random | ||
|
||
services = list(range(1,10)) | ||
services = list(range(1,11)) | ||
|
||
random.shuffle(services) | ||
|
||
|
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