jakewatson91 commited on
Commit
958dc04
·
unverified ·
2 Parent(s): ce8e0daf0c2309

Merge pull request #31 from jakewatson91/jake/prometheus1

Browse files
Grafana/Dockerfile ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ FROM grafana/grafana:latest
2
+
3
+ EXPOSE 3000
Prometheus/Dockerfile ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ FROM prom/prometheus:latest
2
+
3
+ WORKDIR /etc/prometheus
4
+
5
+ COPY prometheus.yml /etc/prometheus/prometheus.yml
6
+
7
+ EXPOSE 9090
8
+
9
+ CMD ["--config.file=/etc/prometheus/prometheus.yml"]
Prometheus/prometheus.yml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ global:
2
+ scrape_interval: 15s
3
+
4
+ scrape_configs:
5
+ - job_name: 'gradio_app'
6
+ static_configs:
7
+ - targets: ['172.17.0.6:8000'] # Gradio metrics
8
+
9
+ - job_name: 'node_exporter_gradio'
10
+ static_configs:
11
+ - targets: ['172.17.0.6:9100'] # Node Exporter
app.py CHANGED
@@ -2,6 +2,13 @@ import gradio as gr
2
  from huggingface_hub import InferenceClient
3
  import torch
4
  from transformers import pipeline
 
 
 
 
 
 
 
5
 
6
  # Set up the local model (Phi-3-mini-4k-instruct) for text generation
7
  local_pipe = pipeline("text-generation", model="microsoft/Phi-3-mini-4k-instruct", torch_dtype=torch.bfloat16, device_map="auto")
@@ -33,6 +40,8 @@ def respond(
33
  ):
34
  global stop_inference
35
  stop_inference = False # Reset cancellation flag
 
 
36
 
37
  # Initialize history if it's None
38
  if history is None:
@@ -70,6 +79,15 @@ def respond(
70
 
71
  # Append the user message and model response to history
72
  history.append((message, response_text))
 
 
 
 
 
 
 
 
 
73
  return history
74
 
75
  def cancel_inference():
@@ -141,4 +159,5 @@ with gr.Blocks(css=custom_css) as demo:
141
  cancel_button.click(cancel_inference)
142
 
143
  if __name__ == "__main__":
 
144
  demo.launch(share=False)
 
2
  from huggingface_hub import InferenceClient
3
  import torch
4
  from transformers import pipeline
5
+ from prometheus_client import start_http_server, Counter, Summary
6
+
7
+ # Prometheus metrics
8
+ REQUEST_COUNTER = Counter('app_requests_total', 'Total number of requests')
9
+ SUCCESSFUL_REQUESTS = Counter('app_successful_requests_total', 'Total number of successful requests')
10
+ FAILED_REQUESTS = Counter('app_failed_requests_total', 'Total number of failed requests')
11
+ REQUEST_DURATION = Summary('app_request_duration_seconds', 'Time spent processing request')
12
 
13
  # Set up the local model (Phi-3-mini-4k-instruct) for text generation
14
  local_pipe = pipeline("text-generation", model="microsoft/Phi-3-mini-4k-instruct", torch_dtype=torch.bfloat16, device_map="auto")
 
40
  ):
41
  global stop_inference
42
  stop_inference = False # Reset cancellation flag
43
+ REQUEST_COUNTER.inc() # Increment request counter
44
+ request_timer = REQUEST_DURATION.time() # Start timing the request
45
 
46
  # Initialize history if it's None
47
  if history is None:
 
79
 
80
  # Append the user message and model response to history
81
  history.append((message, response_text))
82
+
83
+ try:
84
+ SUCCESSFUL_REQUESTS.inc() # Increment successful request counter
85
+ except Exception as e:
86
+ FAILED_REQUESTS.inc() # Increment failed request counter
87
+ yield history + [(message, f"Error: {str(e)}")]
88
+ finally:
89
+ request_timer.observe_duration() # Stop timing the request
90
+
91
  return history
92
 
93
  def cancel_inference():
 
159
  cancel_button.click(cancel_inference)
160
 
161
  if __name__ == "__main__":
162
+ start_http_server(8000) # Expose metrics on port 8000
163
  demo.launch(share=False)