Defining Your API (Methods And Metrics)
Metrics let you track the usage of your API in 3scale. Hits is the built-in metric, it exists in each API service and is used to track the hits made to your API. You can achieve finer granularity for the API usage tracking by defining Methods under the Hits metric. Reporting traffic to a method will increase counters for the method and for the Hits metric automatically. You can define separate methods for each endpoint of you API, or a combination of endpoint and HTTP method. See Mapping rules section to learn how to map the endpoints of your API to the methods defined here.
For measuring other, not hit-based usage of your API, you can define new Metrics and report the usage in different units. A unit can be anything meaningful: megabytes, CPU time, number of elements returned by the API etc.
Methods and metrics are also the scaffolding to package your API: each application plan lets you define different usage limits and pricing rules for each method and metric.
You will be able to see the the usage reported to metrics and methods in the Analytics section.
Manually add methods and metrics
- Navigate to the API > Definition section of the Admin Portal.
- Click on New method.
- Specify the parameters:
- Friendly name is a short description of the method, it appears in different sections of the 3scale admin portal. This name must be unique for the service.
- System name is the name of the method which will be used to report the usage through 3scale Service Management API. It also must be unique, and it should only contain alphanumeric characters, underscore
-and forward slash
/without spaces. Other than that, you are free to decide how the system name will look like, it can be exactly the same as the endpoint ("/status"), or for example can include the method and the path ("GET_/status").
- The Description field can be used for a more detailed description of the method, it is optional.
- Finally, click on Create Method button.
You can later change the definition of the method. Just click on the method name (in the column Method), update the fields and click on Update Method.
For creating a new metric, click on New metric and provide the required parameters. When specifying the unit, use singular noun (e.g. "hit"), as it will be pluralized automatically in the Analytics charts.
These new methods and metrics will be available in all your current and future plans. You can now edit limits and pricing rules for them on each plan going to API > Application plans > [Plan you want to edit].
Import your methods and metrics automatically
If your API has a lot of endpoints, we offer two additional ways of automatically creating your methods and metrics on 3scale: