This is a CF CLI plugin. See here for more details.
This plugin hits your app's metrics endpoint across all your app instances and displays human readable output.
# To add the CF-Community plugin repo (if not already added)
cf add-plugin-repo CF-Community https://plugins.cloudfoundry.org
# To install latest release
cf install-plugin -r CF-Community app-metrics
# To install a dev build of the plugin
./scripts/install.shThis plugin provides two commands.
app-metrics command allows you to obtain metrics from apps instrumented with expvar.
NAME:
app-metrics - Hits the expvar metrics endpoint across all your app instances
USAGE:
cf app-metrics APP_NAME
OPTIONS:
-template path of the template files to render metrics
-endpoint path of the metrics endpoint
-raw prints raw json output
app-metrics-prometheus command allows you to obtain metrics from apps instrumented with prometheus.
NAME:
app-metrics-prometheus - Hits the prometheus metrics endpoint across all your app instances
USAGE:
cf app-metrics-prometheus APP_NAME
OPTIONS:
-endpoint path of the metrics endpoint
cf uninstall-plugin app-metricsInstrumenting applications with various metrics to provide insight into its operation is an important practice for modern day developers. I shouldn't have to explain this further.
The purpose of this plugin is to be able hit the metrics endpoint across all your application instances. There are many ways to instrument your applications including Dropwizard, Prometheus and go-metrics.
For golang applications, there is a package called Expvar available as part of the standard library which makes your metrics available via a HTTP endpoint
So if you have an app deployed on Cloudfoundry at myapp.domain.cf-app.com you can GET its metrics by hitting
http://myapp.domain.cf-app.com/metrics.
However, if you scale up the application to greater than one instance, Cloudfoundry's router will load balance your requests across your app instances. This means that you will be getting metrics from a random instance every time.
This plugin will hit your metrics endpoint (defaults to /debug/metrics) across all your app instances and display the
output in a human readable fashion.
By default it hides the properties cmdline and memstats as they tend to clutter up the output.
Uses functionality in the prom2json to display prometheus metrics in json format.
./scripts/test.sh# Default Template
$ cf app-metrics expvar-sample -endpoint /debug/vars
Instance: 0
Metrics:
metric.float: 123.345
metric.int: 10
metric.map: map[metric1:10 metric2:11]
metric.string: expvarApp
Instance: 1
Metrics:
metric.float: 123.345
metric.int: 10
metric.map: map[metric1:10 metric2:11]
metric.string: expvarApp# Raw output
$ cf app-metrics expvar-sample -endpoint /debug/vars -raw | jq .
[
{
"Instance": 0,
"Error": "",
"Metrics": {
"metric.float": 123.345,
"metric.int": 10,
"metric.map": {
"metric1": 10,
"metric2": 11
},
"metric.string": "expvarApp"
}
}
]
See the project for what is in the To Do list.
In order to create a new release, follow these steps
- Create local tag and binaries
./scripts/build-all.sh release VERSION_NUMBER #(e.g. 0.7.0)
- Copy the output of the previous command from the first line (should be '- name: AppsMetrics Plugin' to the last checksum line (should be something like checksum: fde5fd52c40ea4c34330426c09c143a76a77a8db)
- Push the tag
git push --follow-tags - On github, create new release based on new tag here
- Upload the three binaries from the ./bin folders to the release (Linux, OSX and Win64)
- Fork this repo and clone it locally
- Edit the
repo-index.ymlto override the existing section about the plugin with the text previously copied in Step 2 - Run
go run sort/main.go repo-index.ymlin the cli-plugin-repo to alphabetize the properties - Run
BINARY_VALIDATION=true go test - Push the change to your fork
- Create a PR against the original repo