For REST APIs, the following methods can be used to enable and disable application metrics at runtime.
Method Description Status Code
POST /app/metrics Enable instrumentation metrics
collection 200 - If successfully enabled
409 - If the metrics collection is already enabled
DELETE /app/metrics Disable metrics collection 200 - If successfully disabled 404 - If metrics collection is not enabled
GET /app/metrics/flows Retrieve metrics for all flows 200 - Successfully returned metrics data
404 - If the metrics collection is not enabled
404 - If the metrics collection is not enabled
500 - If there is an issue returning metrics data GET /app/metrics/flow/
<flowname>/activities Retrieve metrics for all
activities in a given flow 200 - Successfully returned metrics data
400 - If the flow name is incorrect
404 - If the metrics collection is not enabled
500 - If there is an issue returning the metrics data
Enabling Application Metrics
Set the FLOGO_HTTP_SERVICE_PORT environment variable to point to the port number of the HTTP service that provides APIs for collecting application metrics. This enables the runtime HTTP service.
Procedure
1. Run the following:
FLOGO_HTTP_SERVICE_PORT=<port> ./<application-binary>
2. Run the curl command for the appropriate REST method. Refer to Application Statistics for details on each method. Some examples are:
curl -X POST http://localhost:7777/app/metrics curl -X GET http://localhost:7777/app/metrics/flows curl -X DELETE http://localhost:7777/app/metrics
Enabling statistics collection using environment variables
To enable metrics collection through environment variable, do the following:
Procedure
1. Run the following:
FLOGO_HTTP_SERVICE_PORT=<port> FLOGO_APP_METRICS=true ./<appname>
2. Run the curl command for the appropriate REST method. Refer to Application Statistics for details on each method. Some examples are:
curl -X GET http://localhost:7777/app/metrics/flows curl -X DELETE http://localhost:7777/app/metrics/flows
Example: retrieve specific metrics for an app
The following is an example of how you would run the above steps for a fictitious app named REST_Echo.
FLOGO_HTTP_SERVICE_PORT=7777 FLOGO_APP_METRICS=true ./REST_Echo-darwin-amd64
curl -X GET http://localhost:7777/app/metrics/flows {"app_name":"REST_Echo","app_version":"1.0.0","flows":
[{"started":127639,"completed":126784,"failed":0,"avg_exec_time":0,"min_exec_t ime":0,"max_exec_time":4,"flow_name":"PostBooks"}]}
curl -X GET http://localhost:7777/app/metrics/flow/PostBooks/activities {"app_name":"REST_Echo","app_version":"1.0.0","tasks":
[{"started":127389,"completed":126908,"failed":0,"avg_exec_time":0,"min_exec_t ime":0,"max_exec_time":4,"flow_name":"PostBooks","task_name":"Return"}]}
Logging Application Metrics
You can record application metrics of flows and activities to the console logs. To enable the logging of application metrics, use the following environment variables:
Environment Variable
Name Default Values Description
FLOGO_APP_METRICS_
LOG_EMITTER_ENABLE False This property can be set to either True or
False:
● True: App metrics are displayed in the logs with the values set in
FLOGO_APP_METRICS_LOG_EMMITTER _CONFIG.
● False: App metrics are not displayed in the logs.
If this variable is not provided, the default values are used.
FLOGO_APP_METRICS_
LOG_EMITTER_CONFIG Both flow and
activity This property can be set to either flow level or
activity level. The format for setting the property is:
{"interval":"<interval_in_seconds>","t ype":["flow","activity"]}
where:
● interval is the time interval (in seconds) after which the app metrics are displayed on the console.
● type is the level at which the app metrics are to be displayed - flow or activity. Depending on which level you set, the app metrics are displayed only for that level.
For example:
{"interval":"1s","type":
["flow","activity"]}
For a list of list of fields or application metrics returned in the response, refer to Fields returned in the response.
Fields returned in the response
The following table describes the fields that can be returned in the response.
Flow
Name Description
app_name Name of the application app_version Version of the application flow_name Name of the flow
started Total number of times a given flow is started
Name Description
completed Total number of times a given flow is completed failed Total number of times a given flow has failed
avg_exec_time Average execution time of a given flow for successfully completed executions min_exec_time Minimum execution time for a given flow
max_exec_time Maximum execution time for a given flow
Activity
Name Description
app_name Name of the application
app_version Version of the application
flow_name Name of the flow
activity_name Name of the activity
started Total number of times a given activity is started completed Total number of times a given activity is completed failed Total number of times a given activity has failed
avg_exec_time Average execution time of a given activity for successfully completed executions
min_exec_time Minimum execution time for a given activity max_exec_time Maximum execution time for a given activity
Prometheus
Flogo Enterprise supports integration with Prometheus for app metrics monitoring. Prometheus is a monitoring tool which helps in analyzing the app metrics for flows and activities.
Prometheus servers scrape data from the HTTP /metrics endpoint of the apps.
Prometheus integrates with Grafana which provides better visual anlytics.
Flogo apps expose the following flow and activity metrics to Prometheus. These metrics are measured in milliseconds:
Labels Description
flogo_flow_metrics: Used for flow-level queries ApplicationName Name of application
Labels Description
ApplicationVersion Version of application
FlowName Name of flow
Started Total number of times flow is started Completed Total number of times flow is completed Failed Total number of times flow is failed flogo_activity_metrics: Used for activity-level queries
ApplicationName Name of application ApplicationVersion Version of application
FlowName Name of flow
ActivityName Name of Activity
Started Total number of times activity is started in given flow Completed Total number of times activity is completed in given flow Failed Total number of times activity is failed in given flow
For a list of some often-used flow-level queries, refer to the section, Often-Used Queries.
Using Prometheus to Analyze Flogo App Metrics
To enable Prometheus monitoring of Flogo apps, run the following:
FLOGO_HTTP_SERVICE_PORT=7779 FLOGO_APP_METRICS_PROMETHEUS=true ./<app-binary>
Setting FLOGO_APP_METRICS_PROMETHEUS variable to true enables Prometheus monitoring of Flogo apps. The variable, FLOGO_HTTP_SERVICE_PORT, is used to set the port number on which the Prometheus endpoint is available.
Use the following endpoint URL in Prometheus server configuration: http://
<APP_HOST_IP>:<FLOGO_HTTP_SERVICE_PORT>/metrics
for example, http:// 192.0.2.0:7779/metrics
Often-Used Queries
Prometheus uses the PromQL query language. This section lists some of the most commonly and often-used queries at the flow-level.
Flow-level Queries
To Get this Metric Use this Query Total number of flows that got
successfully executed per application
count(flogo_flow_metrics{Failed="0"}) by (ApplicationName)
Total number of flows that failed per
application count(flogo_flow_metrics{Failed!="0"}) by
Total time taken by flows which got
executed successfully sum(flogo_flow_metrics{Failed="0"}) by by a flow from amongst the flows that executed successfully)
Activity-level Queries
To Get this Metric Use this Query Total number of activities that got
failed per app and flow sum(flogo_activity_metrics{Failed!="0"}) by (ApplicationName, FlowName)
activity within a given flow and app min(flogo_activity_metrics{Failed!="0"}) by (ApplicationName, FlowName,ActivityName) which failed within a given flow and app which failed within a given flow and app
avg(flogo_activity_metrics{Failed!="0"}) by (ApplicationName, FlowName,ActivityName)