You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|**Best For**| Rapid development | Performance & efficiency | Enterprise apps | Modern APIs |
59
-
60
48
## Metrics
61
49
62
50
All applications expose Prometheus metrics at `/metrics` (port 2112). All metric names are prefixed with a configurable value set via the `METRICS_NAME_PREFIX` environment variable (default: `mymetrics_`).
@@ -209,17 +197,3 @@ metrics-examples/
209
197
├── load-test.sh # Load testing script
210
198
└── README.md # This file
211
199
```
212
-
213
-
## Contributing
214
-
215
-
When adding new features or metrics:
216
-
217
-
1. Implement the feature in all four languages
218
-
2. Use identical metric names across all implementations
219
-
3. Maintain consistent API endpoints
220
-
4. Update all language-specific README files
221
-
5. Test with the load-test.sh script
222
-
223
-
## License
224
-
225
-
See individual language directories for specific dependencies and licenses.
Copy file name to clipboardExpand all lines: metrics-examples/python/README.md
+84-54Lines changed: 84 additions & 54 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,29 @@
2
2
3
3
This application helps debug connectivity issues for IBM Cloud Services and provides comprehensive monitoring through Prometheus metrics. It includes outbound HTTP call simulation, database connectivity testing, and compute-intensive workload simulation.
4
4
5
+
## Architecture
6
+
7
+
```
8
+
┌─────────────────────────────────────┐
9
+
│ Container │
10
+
│ │
11
+
│ ┌────────────────────────────┐ │
12
+
│ │ Main Application Server │ │
13
+
│ │ Port: 8080 │ │
14
+
│ │ - / │ │
15
+
│ │ - /test-db │ │
16
+
│ │ - /outbound/* │ │
17
+
│ └────────────────────────────┘ │
18
+
│ │
19
+
│ ┌────────────────────────────┐ │
20
+
│ │ Metrics Server (Thread) │ │
21
+
│ │ Port: 2112 │ │
22
+
│ │ - /metrics │ │
23
+
│ └────────────────────────────┘ │
24
+
│ │
25
+
└─────────────────────────────────────┘
26
+
```
27
+
5
28
## Features
6
29
7
30
-**Outbound HTTP Calls**: Configurable endpoints that simulate delays and error responses to httpbin.org-compatible backends
@@ -46,32 +69,6 @@ ibmcloud ce application update \
- Interactive API docs: `http://localhost:8080/docs`
73
-
- Alternative API docs: `http://localhost:8080/redoc`
74
-
75
72
## Configuration
76
73
77
74
### Environment Variables
@@ -93,15 +90,14 @@ For database connectivity, create a Code Engine service binding between your pro
93
90
-`GET /outbound/get` - Simple outbound GET request
94
91
-`POST /outbound/post` - Outbound POST request
95
92
-`GET /outbound/status/{code}` - Request specific HTTP status code
96
-
-`GET /metrics` - Prometheus metrics endpoint
97
93
-`GET /docs` - Interactive API documentation (Swagger UI)
98
94
-`GET /redoc` - Alternative API documentation (ReDoc)
99
95
100
96
All outbound endpoints include simulated compute-intensive data processing (0-3s duration, 40-80% CPU intensity).
101
97
102
98
## Metrics
103
99
104
-
The application exposes Prometheus metrics at `/metrics`. All metric names are prefixed with a configurable value set via the `METRICS_NAME_PREFIX` environment variable (default: `mymetrics_`).
100
+
The application exposes Prometheus metrics on a **separate metrics server**at `http://localhost:2112/metrics`. This separation provides better security and performance isolation. All metric names are prefixed with a configurable value set via the `METRICS_NAME_PREFIX` environment variable (default: `mymetrics_`).
105
101
106
102
**Request Metrics**
107
103
-`mymetrics_requests_total`: Total requests by method and path
@@ -123,44 +119,65 @@ The application exposes Prometheus metrics at `/metrics`. All metric names are p
# Option 3: Use a process manager like supervisord or systemd to manage both processes
211
240
```
212
241
242
+
**Note**: When using gunicorn with multiple workers for the main app, the metrics server should run as a separate process. The default `python3 app.py` approach handles both servers automatically in a single process, which is simpler for most use cases.
243
+
213
244
## FastAPI Features
214
245
215
246
This implementation uses FastAPI, which provides:
216
247
217
248
-**Automatic API Documentation**: Visit `/docs` for Swagger UI or `/redoc` for ReDoc
218
-
-**Type Validation**: Automatic request/response validation using Pydantic
219
249
-**Async Support**: Native async/await for non-blocking I/O
220
250
-**High Performance**: One of the fastest Python frameworks available
221
251
-**Standards-based**: Based on OpenAPI and JSON Schema
0 commit comments