. . .

Counting Requests for ApiOmat App Backends

With the new request count feature, you can easily count the requests for App-Backends in ApiOmat. The feature is available since ApiOmat Dispatcher 1.9.0

The dispatcher service will collect the data that are necessary to get an overview over the usage of your app backends. If configured, it will periodically push the request statistics for a specific timeframe to the InfluxDB. The database will contain information about the requested app backend, the response code and the number of requests for that app backend and response code within the specified timeframe.


Additional Requirements

Aside from the general setup for ApiOmat, including especially the Dispatcher and Yambas, you'll need the following additional components:

  • InfluxDB (required, to store the metrics data)

  • Grafana (optionally, to visualize the data; if you use Influx DB v2 you can also use this UI to visualize your data)

Configuration

Now lets set up each component.

Dispatcher Configuration

In the application.yml of Dispatcher you need to configure:

application.yaml of Dispatcher
# enable metrics collection in dispatcher
dispatcher:
  metrics:
    appcount:
      enable: true
# configure InfluxDB connection
management:
  metrics:
    enable:
# disable the metrics that are pushed by default (omit this part or set values to true if you want to publish and use them )
      jvm: false
      processor: false
      process: false
      system: false
      logback: false
      http: false
      spring: false
    export:
      influx:
        step: 15s
        uri: https://localhost:8086
# InfluxDB v1 configuration
        db: appcount
        userName: myuser
        password: my-password
# InfluxDB v2 configuration
        bucket: appcount
        org: myorg
        token: 


Grafana with InfluxDB 1.x

Configure the data source

Now you can log in to the admin dashboard of Grafana and set up the dashboard.

  1. Go to the configuration panel and select "Data sources"

  2. Choose "Add Data source" and select "InfluxDB"

  3. Select "InfluxQL" as Query Language and configure the connection to the database, it should be nearly the same as in your application.yml

Your datasource configuration should look like this:

images/download/thumbnails/118033191/Bildschirmfoto-2021-11-12-um-14.50.35.png

Configure a dashboard

  1. Log in to the Grafana Dashboard, you can see the "Create your first dashboard" panel. Click it to create a new dashboard.

  2. Give your dashboard a nice name over the dashboard settings and then click the "Add an empty panel" button.

  3. Enter a name for the panel by setting a Title in the Panel options and switch to the raw query mode by clicking on the pencil button in the query area at the left bottom to enter an InfluxQL Query
    An example for a InfluxQL Query is the following one. The result will show you a table with entries representing the sum of requests over the selected time frame, grouped by the names of your app backend, which can be easily visualised as Bar chart:

    SELECT sum("value") as request_count FROM "aom_appcount" WHERE $timeFilter GROUP BY "appName"

    The resulting chart could look like this:

    images/download/attachments/118033191/InfluxDB1_Grafana_Dashboard_Example.png

Grafana with InfluxDB 2.x

Configure the data source

A description for the configuration can be found in the InfluxDB 2.0 Documentation. It shows the steps for the configuration with "Flux" as well as "InfluxQL" as query language.

Basically the steps for the configuration with "Flux" as query language are:

  1. Go to the configuration panel and select "Data sources"

  2. Choose "Add Data source" and select "InfluxDB"

  3. Select "Flux" as Query Language and configure the connection to the database, it should be nearly the same as in your application.yml, you'll need to disable the Basic authentication and configure a custom "authentication" header with "Token " + <your API token> as value. (See here how you can create an API token in your InfluxDB)

Your datasource configuration should look like this:

images/download/thumbnails/118033191/Bildschirmfoto-2021-11-12-um-14.53.58.png


For a setup with InfluxQL you'll need to configure InfluxDBv1 authorizations and DBRP mappings over the influx command line tool. Take a look at the documentation for setup.

Configure a dashboard

  1. Log in to the Grafana Dashboard, you can see the "Create your first dashboard" panel. Click it to create a new dashboard.

  2. Give your dashboard a nice name over the dashboard settings and then click the "Add an empty panel" button.

  3. Enter a name for the panel by setting a Title in the Panel options and switch to the raw query mode by clicking on the pencil button in the query area at the left bottom to enter an InfluxQL Query
    An example for a InfluxQL Query is the following one. The result will show you a table with entries representing the sum of requests over the selected time frame, grouped by the names of your app backend, which can be visualised as Bar chart:

    SELECT sum("value") as request_count FROM "aom_appcount" WHERE $timeFilter GROUP BY "appName"

Influx DB 2.x UI

Configure a dashboard

  1. Log in to the Influx DB UI, you can see the "Build a Dashboard" button. Click it and select "Create Dashboard" → "New Dashboard" to create a new dashboard.

  2. Give your dashboard a nice name and then click the "Add Cell" button.

  3. Enter a name for the cell and switch to the "Script Editor" to enter a Flux Query (note: you may need to adjust the bucket name to the one you specified within the application.yml)
    An example for a Flux Query is the following one. The result will show you a table with entries representing the number of requests in hourly ranges and grouped by the names of your app backend, which can be easily visualised as Scatter plot:

    Flux Query
    from(bucket: "appcount")
    |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
    |> group(columns: ["appName"])
    |> window(every: 1h)
    |> sum(column: "_value")
    |> map(fn: (r) => ({ r with requests: r._value }))

    The resulting chart could look like this:
    images/download/attachments/118033191/InfluxDBv2_UI_Example.png