zwoop commented on issue #11349:
URL: 
https://github.com/apache/trafficserver/issues/11349#issuecomment-2121360353

   The common use case, using these APIs rather than the old APIs in ts.h 
(which also uses the new Metrics under the hood) would be
   
   ```
   auto  id1  = ts::Metrics::Counter::create(name);
   auto  id2  = ts::Metrics::Gauge::create(name);
   ```
   
   If you want the pointer, you can get it from the id, e.g.
   
   ```
       auto ptr1 = ts::Metrics::Counter::lookup(id1, nullptr);
       auto ptr2 = ts::Metrics::Gauge::lookup(id2, nullptr);
   ```
   
   or, you can also create them directly with createPtr() as above, e.g.
   
   ```
   auto  ptr1 = ts::Metrics::Counter::createPtr(name);
   auto  ptr2  = ts::Metrics::Gauge::createPtr(name);
   ```
   
   Note that the lookup() functionalities requires locking around the lookup 
tables etc., so are not a good idea to do in critical code. The ID can be used 
to access the metric directly though, without locks, such as
   
   ```
       static auto &instance = ts::Metrics::instance();
   
       instance[id1].increment();
       instance[id2].decrement(5);
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to