All skills

merchmix-ai-usage-dashboard

current

A small Flask dashboard that queries Azure Monitor metrics for an Azure OpenAI resource and presents recent daily token usage by model deployment. It uses configured per-million-token prices to support usage and cost reporting, with an in-process cache to reduce repeated Azure Monitor queries. The application is packaged as a single-worker Gunicorn container and deployed to Azure Container Apps.

master·bc88e68c459a·generated by gpt-5.6-luna·9/4/2026, 1:19:08 PM View as Markdown

This internal dashboard helps Merchmix staff see how much AI usage the product has generated over recent days. It breaks usage down by AI model and distinguishes input from output tokens, helping teams monitor consumption and estimate costs without manually reviewing Azure monitoring data.

3
AI Usage ReportingproductionreadReportinguser facingagent facing96%

Shows recent daily AI token consumption, separated by model deployment and by input versus output usage.

Queries Azure Monitor metrics named InputTokens and OutputTokens for the configured Azure OpenAI resource, using daily aggregation and a configurable lookback period. The results are assembled into daily, per-model rows and exposed through the dashboard API.

AI Cost EstimationproductionreadReportinguser facingagent facing84%

Estimates AI consumption cost using configured list prices for supported model deployments.

Contains an in-code pricing table with separate input and output prices per one million tokens for gpt-5.4, gpt-5.4-mini, and gpt-5.6-luna. The source constructs usage rows after collecting token metrics; the complete cost response formatting is not present in the supplied source excerpt.

Usage Dashboard Health MonitoringproductionreadReportinginternal90%

Provides a lightweight health check so the deployed dashboard can be monitored by its hosting platform.

Exposes a dedicated GET /healthz endpoint. The exact response body is not included in the supplied source excerpt.

2
View AI usage report

A user opens the dashboard and retrieves aggregated Azure OpenAI usage data.

  1. 1.Load the dashboard at GET /.
  2. 2.Request usage data from GET /api/usage.
  3. 3.Reuse the in-process cached result when it is within the configured cache period.
  4. 4.Otherwise query Azure Monitor for daily InputTokens and OutputTokens metrics.
  5. 5.Group metric values by date and model deployment and return the report to the dashboard.
Deploy dashboard

The master branch pipeline builds and deploys the dashboard as an Azure Container Apps image.

  1. 1.Authenticate the Bitbucket pipeline to Azure using secured pipeline variables.
  2. 2.Build the Docker image in Azure Container Registry.
  3. 3.Tag the image with the Bitbucket commit.
  4. 4.Update the pre-provisioned Azure Container App to use the new image.

A single-process Flask web application serves a static dashboard and a JSON usage endpoint. It queries Azure Monitor directly through the Azure SDK, performs aggregation and pricing calculations in memory, and caches the resulting report in an in-process dictionary protected by a thread lock.

Components
Flask application in app.pyStatic dashboard at static/index.htmlAzure Monitor MetricsQueryClient integrationDefaultAzureCredential integration using the hosting Container App identityIn-process usage cache with configurable expirationGunicorn container runtimeBitbucket Pipelines deployment to Azure Container Apps
Patterns
Single service applicationRead-only reporting APIDirect cloud metrics queryIn-memory cachingManaged identity authenticationSingle Gunicorn worker with multiple threads
3
KindIdentifierDescription
httpGET /Serves the dashboard entry point, backed by the static file in static/index.html.
httpGET /api/usageReturns the computed Azure OpenAI usage report, including daily and model-level token data and, based on the configured pricing table, cost-related calculations.
httpGET /healthzHealth-check endpoint for the deployed application.
1
RouteNamePurpose
/AI Usage DashboardDisplays recent Azure OpenAI usage information retrieved from the usage API.
4
EntityOwnershipDescription
Azure OpenAI token metricsreadsDaily InputTokens and OutputTokens metrics queried from Azure Monitor for the configured Azure OpenAI resource.
Model deployment usageownsTransient report data grouped by model deployment name, date, input tokens, and output tokens.
Model pricing configurationownsHardcoded per-one-million-token input and output prices for the supported model deployments.
Usage report cacheownsIn-process cached report data and its fetch timestamp; it is not persisted in an external database.
9
NameKindRelationshipCriticality
Azure Monitorexternal servicereadscritical
Azure OpenAI resourceexternal servicereadscritical
Azure managed identityotherauthenticates_throughcritical
Flasklibraryusescritical
Gunicornlibraryusesrequired
azure-identitylibraryusescritical
azure-monitor-querylibraryusescritical
Azure Container Registryexternal servicewritesrequired
Azure Container Appsexternal servicewritesrequired
PythonFlask 3.0.3Gunicorn 22.0.0Azure Identity 1.17.1Azure Monitor Query 1.4.0DockerAzure Container AppsAzure Container RegistryBitbucket Pipelines
6
  • The supplied app.py source is truncated after the initial usage-row construction, so the exact JSON schema, cost calculation implementation, error handling, and cache response behavior cannot be fully verified.
  • No persistent database, queue, or write-oriented business API is present in the scanner evidence.
  • Pricing is hardcoded in app.py and is not fetched dynamically; estimates may become stale when Azure pricing or deployments change.
  • The scanner lists several environment variable names, while the source explicitly reads OPENAI_RESOURCE_ID, USAGE_DAYS_BACK, and USAGE_CACHE_SECONDS. The effective deployment configuration should be verified separately.
  • The dashboard is an internal reporting tool, not an AI inference service and not a general-purpose Azure OpenAI administration interface.
  • The single-worker cache is process-local; the deployment deliberately uses one worker so multiple independent cache copies are not created.

Use this repository for questions about internal Azure OpenAI usage, token consumption, model-level reporting, and configured cost estimates. Do not route product planning, assortment, inventory, allocation, or transactional retail operations to it.

  • For current usage, call GET /api/usage rather than relying on previously cached values.
  • Interpret results as Azure Monitor-derived metrics over the configured USAGE_DAYS_BACK period, aggregated daily.
  • Treat pricing and cost figures as estimates based on the in-code PRICING table.
  • Do not assume the service can modify Azure OpenAI resources or usage data; the evidenced interfaces are read-only reporting endpoints.
  • Use GET /healthz for service availability checks.
  • When debugging missing or stale data, check OPENAI_RESOURCE_ID, Azure Monitor access through the Container App managed identity, the configured lookback and cache periods, and Azure Monitor metric availability.
  • Do not search this repository for API keys or credentials; authentication is intended to come from Azure managed identity and deployment configuration.