add licence to change_metric_collection_level

This commit is contained in:
Adrian Todorov 2017-10-26 23:15:29 +02:00
parent 88e1f00b8d
commit 3bed073385
4 changed files with 104 additions and 4 deletions

View File

@ -41,8 +41,8 @@ If you set a domain, it will be automaticaly removed from the names of the found
Metrics collected are defined by associating ObjectType groups with Metric groups. Metrics collected are defined by associating ObjectType groups with Metric groups.
To see all available metrics, check out [this](http://www.virten.net/2015/05/vsphere-6-0-performance-counter-description/) page. To see all available metrics, check out [this](http://www.virten.net/2015/05/vsphere-6-0-performance-counter-description/) page.
Note: Not all metrics are available directly, you might need to change your metric collection level. **Note: Not all metrics are available directly, you might need to change your metric collection level.**
A table with the level needed for each metric is availble [here](http://www.virten.net/2015/05/which-performance-counters-are-available-in-each-statistic-level/), and you can find a PowerCLI script that changes the collect level [here](http://www.valcolabs.com/2012/02/06/modify-historical-statistics-level-using-powercli/) A table with the level needed for each metric is availble [here](http://www.virten.net/2015/05/which-performance-counters-are-available-in-each-statistic-level/), and you can find a pyVmomi script that cahanges to collect level in the [tools folder of the project](./tools/).
An example of configuration file is [here](./vsphere-influxdb.json.sample). An example of configuration file is [here](./vsphere-influxdb.json.sample).
@ -57,8 +57,11 @@ Create a crontab to run it every X minutes(one minute is fine - in our case, ~30
``` ```
# Example dashboards # Example dashboards
* https://grafana.com/dashboards/1299 * https://grafana.com/dashboards/1299 (thanks to @exbane )
* https://grafana.com/dashboards/3556 * https://grafana.com/dashboards/3556 (VMware cloud overview, mostly provisioning/global cloud usage stats)
* https://grafana.com/dashboards/3571 (VMware performance, mostly VM oriented performance stats)
Contributions welcome!
# TODO # TODO
* Add service discovery(or probably something like [Viper](https://github.com/spf13/viper) for easier and more flexible configuration with multiple backends) * Add service discovery(or probably something like [Viper](https://github.com/spf13/viper) for easier and more flexible configuration with multiple backends)

View File

@ -0,0 +1,94 @@
#!/usr/bin/python
#============================================
# Script: change_metric_collection_level.py
# Description: Change the metric collection level of an interval in a vCenter
# Copyright 2017 Adrian Todorov, Oxalide ato@oxalide.com
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#============================================
from pyVim.connect import SmartConnect, Disconnect
from pyVmomi import vim
import atexit
import sys
import requests
import argparse
import getpass
import linecache
requests.packages.urllib3.disable_warnings()
def PrintException():
exc_type, exc_obj, tb = sys.exc_info()
f = tb.tb_frame
lineno = tb.tb_lineno
filename = f.f_code.co_filename
linecache.checkcache(filename)
line = linecache.getline(filename, lineno, f.f_globals)
print 'EXCEPTION IN ({}, LINE {} "{}"): {}'.format(filename, lineno, line.strip(), exc_obj)
def get_args():
parser = argparse.ArgumentParser(description='Arguments for talking to vCenter and modifying a PerfManager collection interval')
parser.add_argument('-s', '--host', required=True,action='store',help='vSpehre service to connect to')
parser.add_argument('-o', '--port', type=int, default=443, action='store', help='Port to connect on')
parser.add_argument('-u', '--user', required=True, action='store', help='User name to use')
parser.add_argument('-p', '--password', required=False, action='store', help='Password to use')
parser.add_argument('--interval-name', required=False, action='store', dest='intervalName', help='The name of the interval to modify')
parser.add_argument('--interval-key', required=False, action='store', dest='intervalKey', help='The key of the interval to modify')
parser.add_argument('--interval-level', type=int, required=True, default=4, action='store', dest='intervalLevel', help='The collection level wanted for the interval')
args = parser.parse_args()
if not args.password:
args.password = getpass.getpass(prompt='Enter password:\n')
if not args.intervalName and not args.intervalKey:
print "An interval name or key is needed"
exit(2)
return args
def change_level(host, user, pwd, port, level, key, name):
try:
print user
print pwd
print host
serviceInstance = SmartConnect(host=host,user=user,pwd=pwd,port=port)
atexit.register(Disconnect, serviceInstance)
content = serviceInstance.RetrieveContent()
pm = content.perfManager
for hi in pm.historicalInterval:
if (key and int(hi.key) == int(key)) or (name and str(hi.name) == str(name)):
print "Changing interval '" + str(hi.name) + "'"
newobj = hi
newobj.level = level
pm.UpdatePerfInterval(newobj)
print "Intervals are now configured as follows: "
print "Name | Level"
pm2 = content.perfManager
for hi2 in pm2.historicalInterval:
print hi2.name + " | " + str(hi2.level)
except Exception, e:
print "Error: %s " % (e)
PrintException()
exit(2)
if __name__ == "__main__":
args = get_args()
change_level(args.host, args.user, args.password, args.port, args.intervalLevel, args.intervalKey, args.intervalName)

3
tools/requirements.txt Normal file
View File

@ -0,0 +1,3 @@
pyVmomi
requests
argparse

Binary file not shown.