Record a connection count change for a single state. Args: pool_name: Connection pool identifier connection_state: State to update (IDLE or USED) counter: Number to add (positive) or subtract (negative) Example: # New connection created (goes to IDLE fi
(
pool_name: str,
connection_state: ConnectionState,
counter: int = 1,
)
| 147 | |
| 148 | |
| 149 | def record_connection_count( |
| 150 | pool_name: str, |
| 151 | connection_state: ConnectionState, |
| 152 | counter: int = 1, |
| 153 | ) -> None: |
| 154 | """ |
| 155 | Record a connection count change for a single state. |
| 156 | |
| 157 | Args: |
| 158 | pool_name: Connection pool identifier |
| 159 | connection_state: State to update (IDLE or USED) |
| 160 | counter: Number to add (positive) or subtract (negative) |
| 161 | |
| 162 | Example: |
| 163 | # New connection created (goes to IDLE first) |
| 164 | >>> record_connection_count('pool_abc123', ConnectionState.IDLE, 1) |
| 165 | |
| 166 | # Acquire from pool (transition) |
| 167 | >>> record_connection_count('pool_abc123', ConnectionState.IDLE, -1) |
| 168 | >>> record_connection_count('pool_abc123', ConnectionState.USED, 1) |
| 169 | |
| 170 | # Release to pool (transition) |
| 171 | >>> record_connection_count('pool_abc123', ConnectionState.USED, -1) |
| 172 | >>> record_connection_count('pool_abc123', ConnectionState.IDLE, 1) |
| 173 | |
| 174 | # Pool disconnect 5 idle connections |
| 175 | >>> record_connection_count('pool_abc123', ConnectionState.IDLE, -5) |
| 176 | """ |
| 177 | global _metrics_collector |
| 178 | |
| 179 | if _metrics_collector is None: |
| 180 | _metrics_collector = _get_or_create_collector() |
| 181 | if _metrics_collector is None: |
| 182 | return |
| 183 | |
| 184 | try: |
| 185 | _metrics_collector.record_connection_count( |
| 186 | pool_name=pool_name, |
| 187 | connection_state=connection_state, |
| 188 | counter=counter, |
| 189 | ) |
| 190 | except Exception: |
| 191 | pass |
| 192 | |
| 193 | |
| 194 | @deprecated_function( |
no test coverage detected