Spaces:
Running
Running
File size: 3,984 Bytes
43cd37c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# metrics_logger.py
#
# Imports
from datetime import datetime, timezone
#
# Third-party Imports
#
# Local Imports
from App_Function_Libraries.Metrics.logger_config import logger
#
############################################################################################################
#
# Functions:
def log_counter(metric_name, labels=None, value=1):
log_entry = {
"event": metric_name,
"type": "counter",
"value": value,
"labels": labels or {},
# datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
# FIXME
"timestamp": datetime.now(timezone.utc).isoformat() + "Z"
}
logger.info("metric", extra=log_entry)
def log_histogram(metric_name, value, labels=None):
log_entry = {
"event": metric_name,
"type": "histogram",
"value": value,
"labels": labels or {},
# datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
# FIXME
"timestamp": datetime.now(timezone.utc).isoformat() + "Z"
}
logger.info("metric", extra=log_entry)
#
# End of Functions
############################################################################################################
# # Prometheus
# # metrics_logger.py (Prometheus version)
# from prometheus_client import Counter, Histogram, start_http_server
# import logging
# from functools import wraps
# import time
#
# # Initialize Prometheus metrics
# VIDEOS_PROCESSED = Counter('videos_processed_total', 'Total number of videos processed', ['whisper_model', 'api_name'])
# VIDEOS_FAILED = Counter('videos_failed_total', 'Total number of videos failed to process', ['whisper_model', 'api_name'])
# TRANSCRIPTIONS_GENERATED = Counter('transcriptions_generated_total', 'Total number of transcriptions generated', ['whisper_model'])
# SUMMARIES_GENERATED = Counter('summaries_generated_total', 'Total number of summaries generated', ['whisper_model'])
# VIDEO_PROCESSING_TIME = Histogram('video_processing_time_seconds', 'Time spent processing videos', ['whisper_model', 'api_name'])
# TOTAL_PROCESSING_TIME = Histogram('total_processing_time_seconds', 'Total time spent processing all videos', ['whisper_model', 'api_name'])
#
# def init_metrics_server(port=8000):
# start_http_server(port)
#
# def log_counter(metric_name, labels=None, value=1):
# if metric_name == "videos_processed_total":
# VIDEOS_PROCESSED.labels(**(labels or {})).inc(value)
# elif metric_name == "videos_failed_total":
# VIDEOS_FAILED.labels(**(labels or {})).inc(value)
# elif metric_name == "transcriptions_generated_total":
# TRANSCRIPTIONS_GENERATED.labels(**(labels or {})).inc(value)
# elif metric_name == "summaries_generated_total":
# SUMMARIES_GENERATED.labels(**(labels or {})).inc(value)
#
# def log_histogram(metric_name, value, labels=None):
# if metric_name == "video_processing_time_seconds":
# VIDEO_PROCESSING_TIME.labels(**(labels or {})).observe(value)
# elif metric_name == "total_processing_time_seconds":
# TOTAL_PROCESSING_TIME.labels(**(labels or {})).observe(value)
# # main.py or equivalent entry point
# from metrics_logger import init_metrics_server
#
#
# def main():
# # Start Prometheus metrics server on port 8000
# init_metrics_server(port=8000)
#
# # Initialize and launch your Gradio app
# create_video_transcription_tab()
#
#
# if __name__ == "__main__":
# main()
# prometheus.yml
# scrape_configs:
# - job_name: 'video_transcription_app'
# static_configs:
# - targets: ['localhost:8000'] # Replace with your application's host and port
|