Skip to content

Instantly share code, notes, and snippets.

@bahamat
Last active March 17, 2020 03:06
Show Gist options
  • Save bahamat/cbccf6cbd7371d66894c6c06381309ab to your computer and use it in GitHub Desktop.
Save bahamat/cbccf6cbd7371d66894c6c06381309ab to your computer and use it in GitHub Desktop.
CMON plugin to get gz zone count metrics
#!/bin/bash
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
# Copyright 2020 Joyent, Inc.
printf '# HELP plugin_zone_count Zone count by state\n'
printf '# TYPE plugin_zone_count gauge\n'
vmadm list -Ho state,zone_state | sort | uniq -c | awk '{printf("plugin_zone_count{state=\"%s\",zone_state=\"%s\"}\t%s\n", $2,$3,$1)}'

This plugin complies with documentation here: https://github.com/joyent/triton-cmon-agent/tree/master/docs#plugins

Place this in /opt/custom/cmon/gz on all CNs. The script must be executable.

Example output from plugin script:

[root@headnode (vt-coal-1) ~]# /opt/custom/cmon/gz-plugins/zone_count.prom 
# HELP plugin_zone_count Zone count by state
# TYPE plugin_zone_count gauge
plugin_zone_count{state="running",zone_state="running"}	27

Example output from cmon:

$ cmon -i -p vt-coal-1 metrics 18a6cf11-45d4-8884-a77c-f44d30663faf | grep zone_count
# HELP plugin_zone_count_metrics_available_boolean Whether plugin_zone_count metrics were available, 0 = false, 1 = true
# TYPE plugin_zone_count_metrics_available_boolean gauge
plugin_zone_count_metrics_available_boolean 1
# HELP plugin_zone_count_metrics_cached_boolean Whether plugin_zone_count metrics came from cache, 0 = false, 1 = true
# TYPE plugin_zone_count_metrics_cached_boolean gauge
plugin_zone_count_metrics_cached_boolean 1
# HELP plugin_zone_count_metrics_timer_seconds How long it took to gather the plugin_zone_count metrics
# TYPE plugin_zone_count_metrics_timer_seconds gauge
plugin_zone_count_metrics_timer_seconds 0.000025107
# HELP plugin_zone_count_plugin_zone_count Zone count by state
# TYPE plugin_zone_count_plugin_zone_count gauge
plugin_zone_count{state="running",zone_state="running"} 27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment