Web Request
You can configure MetricsHub to send HTTP request against a Web service and analyze the responses.
In the example below, we configured MetricsHub to:
- send an HTTP GET request to the health endpoint of the
grafana-service - parse the JSON response and extract key information such as the service version and database status
- translate the health state into a numerical metric (
grafana.db.state).
Procedure
To achieve this use case, we:
-
Declare the resource to be monitored (
grafana-service) and its attributes (service.name,host.name)resources:
grafana-service:
attributes:
service.name: Grafana
host.name: hws-demo.sentrysoftware.com -
Configure the
HTTPprotocolprotocols:
http:
https: true
port: 443 -
Configure the monitor job targeting the desired service
monitors:
grafana:
simple: # simple job. Creates monitors and collects associated metrics. -
Send an HTTP request to the Grafana service
sources:
grafanaHealth:
type: http
path: /api/health
method: get
header: 'Accept: application/json'
# {
# "commit": "838218ba20",
# "database": "ok",
# "version": "10.1.0"
# } -
Process the JSON response using the
json2Csvandtranslatetransformation stepscomputes:
- type: json2Csv
entryKey: /
properties: commit;database;version
separator: ;
- type: translate
column: 3
translationTable:
ok: 1
default: 0 -
Map the extracted data to resource attributes and metrics
mapping:
source: ${source::grafanaHealth}
attributes:
id: $2
service.instance.id: $2
service.version: $4 -
Extract and expose the
grafana.db.statemetricmetrics:
grafana.db.state: $3
Here is the complete YAML configuration:
resources:
grafana-service:
attributes:
service.name: Grafana
host.name: hws-demo.sentrysoftware.com
protocols:
http:
https: true
port: 443
monitors:
grafana:
simple: # simple job. Creates monitors and collects associated metrics.
sources:
grafanaHealth:
type: http
path: /api/health
method: get
header: 'Accept: application/json'
# {
# "commit": "838218ba20",
# "database": "ok",
# "version": "10.1.0"
# }
computes:
- type: json2Csv
entryKey: /
properties: commit;database;version
separator: ;
- type: translate
column: 3
translationTable:
ok: 1
default: 0
mapping:
source: ${source::grafanaHealth}
attributes:
id: $2
service.instance.id: $2
service.version: $4
metrics:
grafana.db.state: $3