github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/website/content/tools/autoscaling/concepts/plugins/apm.mdx (about) 1 --- 2 layout: docs 3 page_title: APM Plugins 4 description: Learn how to author a Nomad Autoscaler APM plugin. 5 --- 6 7 # APM Plugins 8 9 APM plugins are used by the autoscaler to interact with an external APM system, 10 returning metrics that are used by the autoscaler to inform scaling actions. 11 12 For a real-world example of a Nomad APM plugin implementation, see the 13 [`prometheus` plugin](https://github.com/hashicorp/nomad-autoscaler/tree/main/plugins/builtin/apm/prometheus). 14 15 ## Authoring APM Plugins 16 17 Authoring an APM plugin in Go can be accomplished by implementing the 18 [`apm.APM`][apm_plugin] interface, alongside a `main` package to launch the plugin. 19 20 The [`no-op` APM plugin][noop_plugin] can be used as a starting point for new APM 21 plugins. 22 23 ## APM Plugin API 24 25 The [base plugin][base_plugin] interface must be implemented in addition to the 26 following functions. 27 28 #### `Query(query string, timeRange sdk.TimeRange) (sdk.TimestampedMetrics, error)` 29 30 The `Query` function is called by the agent during policy 31 evaluation. The `query` argument is the opaque string from the scaling policy, 32 and the `timeRange` indicates the period of time over which the query should be 33 made. The response is a series of timestamped metrics; as such, the query semantics 34 should be such that the backing APM will return a time series. An example is the 35 CPU utilization of a task group, averaged over all current allocations. 36 37 #### `QueryMultiple(query string, timeRange sdk.TimeRange) ([]sdk.TimestampedMetrics, error)` 38 39 The `QueryMultiple` method is similar to `Query`, except that the interface allows 40 multiple time series to be returned. This endpoint is currently only used for 41 [Dynamic Application Sizing][das]. 42 An example would be to return the CPU utilization for all allocations during 43 the time range. 44 45 [apm_plugin]: https://github.com/hashicorp/nomad-autoscaler/blob/v0.3.0/plugins/apm/apm.go#L11 46 [base_plugin]: /tools/autoscaling/internals/plugins/base 47 [noop_plugin]: https://github.com/hashicorp/nomad-autoscaler/tree/v0.3.0/plugins/test/noop-apm 48 [das]: /tools/autoscaling#dynamic-application-sizing