gpt4 book ai didi

python - 尝试查询 Log Analytics 工作区表时出现 "Requested Path Does Not Exist"

转载 作者:行者123 更新时间:2023-12-03 06:08:04 25 4
gpt4 key购买 nike

我正在做一个实验,其中使用 Azure Python SDK 创建一个资源组,其中包含:aks 集群、日志分析工作区和应用程序见解(基于工作区)。然后我运行另一个服务来为其创建可用性测试。第三步是使用 Flask 应用程序查询工作区日志中的“AppAvailabilityResults”表,该应用程序具有发出 GET 请求的路由。直到最后一步为止的所有内容都有效,并且我已经对其进行了调试,因此我知道凭据/LA 信息正在正确地通过我的代码,但是当我运行请求时,我收到此错误:

raise HttpResponseError(message=error.message, response=error.response, model=model)azure.core.exceptions.HttpResponseError: (PathNotFoundError) The requested path does not existCode: PathNotFoundErrorMessage: The requested path does not existINFO:werkzeug:127.0.0.1 - - [14/Sep/2023 14:34:02] "GET /checks HTTP/1.1" 500 -

代码如下:

# Check Log Analytics and return results
def query_availability_results():
try:
query_client = LogsQueryClient(credentials)

query = """
AppAvailabilityResults
"""

# Use timespan in query
response = query_client.query_workspace(workspace_id=LOG_ANALYTICS_WORKSPACE.id, query=query, timespan=timespan)
result_tables = LogsQueryResult.tables(response)

return result_tables

except Exception as e:
app.logger.error(f"Error querying Log Analytics: {str(e)}")
return None

# API route to check uptime
@app.route("/checks")
def get_checks():
app.logger.info("Received request for /checks")
# Execute the query and handle errors
availability_results = query_availability_results()

if availability_results is None:
return jsonify({"error": "Error querying Log Analytics"}), 500

checks = []
try:
for row in availability_results[0]:
check = {
"timeGenerated": row.get("timeGenerated", ""),
"name": row.get("name", ""),
"duration": row.get("durationMs", ""),
"success": row.get("success", ""),
"location": row.get("location", ""),
}
checks.append(check)
except Exception as e:
app.logger.error(f"Error parsing Log Analytics results: {str(e)}")
return jsonify({"error": "Error parsing Log Analytics results"}), 500

return jsonify(checks)

有什么想法吗?提前致谢。

最佳答案

请求的路径不存在”通常表示您尝试对 Log Analytics 工作区执行的查询未在工作区中找到指定的表或数据源。

  • 使用了以下代码 MSDOC在 flask 应用程序中并能够跟踪日志。
app = Flask(__name__)

# Configure logging to print logs to the console
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')

# Define the LOG_WORKSPACE_ID as a string
LOG_WORKSPACE_ID = " "

credential = DefaultAzureCredential()
client = LogsQueryClient(credential)

@app.route('/')
def query_and_print_logs():
try:
requests = [
LogsBatchQuery(
query=" ",
timespan=timedelta(hours=1),
workspace_id=LOG_WORKSPACE_ID
),
LogsBatchQuery(
query=" ", # Replace with a valid log query
timespan=timedelta(days=1),
workspace_id=LOG_WORKSPACE_ID
),
LogsBatchQuery(
query= """let Weight = 92233720368547758;
range x from 1 to 3 step 1
| summarize percentilesw(x, Weight * 100, 50)""",
workspace_id=LOG_WORKSPACE_ID,
timespan=(datetime(2021, 6, 2, tzinfo=timezone.utc), datetime(2021, 6, 5, tzinfo=timezone.utc)), # (start, end)
include_statistics=True
),
]
results = client.query_batch(requests)

for res in results:
if res.status == LogsQueryStatus.FAILURE:
# this will be a LogsQueryError
logging.error(res.message)
elif res.status == LogsQueryStatus.PARTIAL:
## this will be a LogsQueryPartialResult
logging.warning(res.partial_error)
for table in res.partial_data:
df = pd.DataFrame(table.rows, columns=table.columns)
logging.info(df)
elif res.status == LogsQueryStatus.SUCCESS:
## this will be a LogsQueryResult
table = res.tables[0]
df = pd.DataFrame(table.rows, columns=table.columns)
logging.info(df.to_string())

return "Check console logs for output."

except Exception as e:
logging.error(str(e))
return "An error occurred. Check console logs for details."

if __name__ == '__main__':
app.run()

输出:

enter image description here

enter image description here

关于python - 尝试查询 Log Analytics 工作区表时出现 "Requested Path Does Not Exist",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77108302/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com