我正在为我的 Flask 应用程序使用 python 3,该应用程序在端口 5000 中运行。它有一个示例 API。我需要在从 REST 或浏览器访问此 API 时分析内存、CPU 使用情况。
请帮助我找到更好的解决方案。
import logging
from flask import Flask, jsonify
from flask_cors import CORS
logger = logging.getLogger()
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - "
"%(name)s:%(lineno)d [-] %(funcName)s- %(message)s")
logger.setLevel(logging.INFO)
app = Flask(__name__)
app.url_map.strict_slashes = False
CORS(app)
def health_check():
return jsonify({"message": "success"})
app.add_url_rule(rule='/health', endpoint='health-check',
view_func=health_check, methods=['GET'])
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=5000)
Run Code Online (Sandbox Code Playgroud) 我有 AWS S3 访问权限,并且存储桶内有近 300 个文件。我需要通过模式匹配或搜索从该存储桶下载单个文件,因为我不知道确切的文件名(假设文件以 .csv 格式结尾)。
这是我的示例代码,显示了存储桶内的所有文件
def s3connection(credentialsdict):
"""
:param access_key: Access key for AWS to establish S3 connection
:param secret_key: Secret key for AWS to establish S3 connection
:param file_name: file name of the billing file(csv file)
:param bucket_name: Name of the bucket which consists of billing files
:return: status, billing_bucket, billing_key
"""
os.environ['S3_USE_SIGV4'] = 'True'
conn = S3Connection(credentialsdict["access_key"], credentialsdict["secret_key"], host='s3.amazonaws.com')
billing_bucket = conn.get_bucket(credentialsdict["bucket_name"], validate=False)
try:
billing_bucket.get_location()
except S3ResponseError as e:
if e.status == 400 and …Run Code Online (Sandbox Code Playgroud)