hashgraph / hedera-sourcify

Tools for verifying Hedera smart contracts using standard open source libraries.
Apache License 2.0
6 stars 7 forks source link

feat: include support for metrics #131

Closed acuarica closed 4 months ago

acuarica commented 4 months ago

Description:

This PR adds another endpoint, /metrics, where you can fetch service metrics to be ingested by Prometheus/Grafana.

Using for instance the NodeJS Application Dashboard you can see NodeJS metrics

image

It also exports requests and events (response) triggered during verification. All requests made to the service (e.g. https://server-verify.hashscan.io/api-docs) will be included, for example

sourcify_http_request_duration_seconds_bucket{le="0.003",status_code="200",method="POST",path="/verify"} 3
sourcify_http_request_duration_seconds_bucket{le="0.03",status_code="200",method="POST",path="/verify"} 4
sourcify_http_request_duration_seconds_bucket{le="0.1",status_code="200",method="POST",path="/verify"} 5
sourcify_http_request_duration_seconds_bucket{le="0.3",status_code="200",method="POST",path="/verify"} 5
sourcify_http_request_duration_seconds_bucket{le="1.5",status_code="200",method="POST",path="/verify"} 6
sourcify_http_request_duration_seconds_bucket{le="10",status_code="200",method="POST",path="/verify"} 6
sourcify_http_request_duration_seconds_bucket{le="+Inf",status_code="200",method="POST",path="/verify"} 6
sourcify_http_request_duration_seconds_sum{status_code="200",method="POST",path="/verify"} 0.632749876
sourcify_http_request_duration_seconds_count{status_code="200",method="POST",path="/verify"} 6

# HELP sourcify_up 1 = up, 0 = not up
# TYPE sourcify_up gauge
sourcify_up 1

# HELP sourcify_event_count events that happened during verification labeled with: event and chainId
# TYPE sourcify_event_count counter
sourcify_event_count{event="Verification.MatchStored",chainId="298"} 2

Note that the sourcify_ prefix is used all metrics to easily differentiate in Grafana.

The events exported are

  "Verification.MatchStored": [],
  "Server.SourcifyChains.Warn": [],
  // [...]
  "SourceFetcher.UsingFallback": [],
  "SourceFetcher.NewSubscription": [],
  "SourceFetcher.Cleanup": [],
  "SourceFetcher.FetchFailed": [],
  "SourceFetcher.FetchingSuccessful": [],

(the ones omitted [...] are Monitor.* related not used at the moment)

Related issue(s):

Fixes #

Notes for reviewer:

Checklist