Created
July 24, 2014 05:26
-
-
Save koemu/6040b298e452fd364328 to your computer and use it in GitHub Desktop.
Get KVM guest CPU Usage for Mackerel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import sys | |
import commands | |
import datetime | |
unix_time = datetime.datetime.today().strftime('%s') | |
retval = commands.getstatusoutput( "virt-top -b --stream -n 2 -d 1" ) | |
if retval[0] != 0: | |
sys.exit( -1 ) | |
top_count = 0 | |
top_list = retval[1].split( "\n" ) | |
for top_data in top_list: | |
if top_data.find( "virt-top time" ) >= 0: | |
top_count += 1 | |
continue | |
if top_count != 2: | |
continue | |
if top_data == "": | |
continue | |
top_data_list = top_data.strip().split() | |
if top_data_list[0] == "ID": | |
continue | |
print "%s.%s.%s\t%s\t%s" % ( "kvm.guest", "cpu", top_data_list[9], top_data_list[6], unix_time ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Please append this lines to your config file. | |
[plugin.metrics.kvm_guest_cpu] | |
command = "/usr/local/bin/kvm_guest_virttop.py" | |
type = "metric" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment