Merge "Add a smaller vcenter plugin for status"

This commit is contained in:
Jenkins 2017-08-12 21:37:11 +00:00 committed by Gerrit Code Review
commit 5d53a29e40
3 changed files with 132 additions and 0 deletions

View File

@ -0,0 +1,27 @@
init_config:
# vcenter credentials. Port defaults to the value shown, while all others default to empty strings
vcenter_ip: "127.0.0.1"
vcenter_user: "joe"
vcenter_password: "12345"
vcenter_port: 443
# number of retries to the vcenter api
retry_count: 3
poll_interval: 0.5
# maximum number of objects to return from vcenter, this should be larger than the total number of vms running.
vcenter_max_objects: 100000
# Sets the keys to be collected from the annotations on vms. By default this is empty, meaning no
# annotations will be collected
allowed_keys:
- project_id
# This can be used to change the name of a key when it is added to the metric dimensions. By default, all
# keys will be recorded without modification
key_map:
project_id: tenant_id
instances:
# this plugin doesn't support instances, this section will be ignored (but is still required for structure)

View File

@ -191,6 +191,7 @@ The following plugins are delivered via setup as part of the standard plugin che
| tcp_check | | |
| varnish | | |
| vcenter | | |
| vcenter_slim | | Tracks vm status only |
| vertica | /root/.vertica.cnf |
| wmi_check | | |
| zk | | Apache Zookeeper |
@ -2374,6 +2375,34 @@ Below are the list of metrics collected by this plugin from the configured clust
"id": <cluster-name>-<vcenter-ip or fqdn>
```
## VCenter Slim
This plugin provides exclusively vm status metrics for VMware ESX clusters. Includes configuration for which annotations
to add to dimensions via allowed_keys (collects annotations with that key, if available) and key_map (replaces annotation key when creating dimension).
In the example below, the resulting metrics will have a dimension of 'tenant_id' with the value from the 'project_id' annotation.
### Sample Config
```
init_config:
vcenter_ip: "127.0.0.1"
vcenter_user: "joe"
vcenter_password: "12345"
vcenter_port: 443
retry_count: 3
poll_interval: 0.5
vcenter_max_objects: 100000
allowed_keys:
- project_id
key_map:
project_id: tenant_id
instances:
# this plugin doesn't support instances, this section will be ignored (but is still required for structure)
```
| Metric Name | Description |
| ----------- | ----------- |
| vm.status | The connection status of the vm. Value is 0 if the vm can be managed normally, 1 for all other states |
## Vertica Checks
This section describes the vertica check that can be performed by the Agent. The vertica check requires a configuration file called vertica.yaml to be available in the agent conf.d configuration directory.

View File

@ -0,0 +1,76 @@
# (C) Copyright 2017 Hewlett Packard Enterprise Development LP
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""
VCenter plugin that returns only vm status. Takes no instances, reads from a single configured VCenter
"""
from monasca_agent.collector.checks import AgentCheck
from oslo_vmware import api
from oslo_vmware import vim_util
STATUS_MAP = {
"connected": 0
}
class VcenterSlim(AgentCheck):
def __init__(self, name, init_config, agent_config):
AgentCheck.__init__(self, name, init_config, agent_config, instances=[{}])
self.max_objects = init_config.get("vcenter_max_objects", 100000)
def check(self, instance):
dim_base = self._set_dimensions(None, instance)
allowed_keys = set(self.init_config.get("allowed_keys", []))
key_map = self.init_config.get("key_map", {})
session = self.get_api_session()
result = session.invoke_api(vim_util, "get_objects", session.vim, "VirtualMachine", self.max_objects,
["runtime.connectionState", "config.annotation", "config.instanceUuid"])
for vm in result[0]:
vm_status = 1
# vm_name = vm.obj.value
vm_dimensions = dim_base.copy()
for prop in vm.propSet:
if prop.name == "runtime.connectionState":
if prop.val in STATUS_MAP:
vm_status = STATUS_MAP[prop.val]
else:
vm_status = 1
if prop.name == "config.annotation":
for line in prop.val.split("\n"):
key_val = line.split(":")
if len(key_val) == 2 and key_val[0] in allowed_keys:
value = key_val[1]
key = key_val[0]
if key in key_map.keys():
key = key_map[key_val[0]]
vm_dimensions[key] = value
if prop.name == "config.instanceUuid":
vm_dimensions["instance_id"] = prop.val
self.gauge("vm.status", vm_status, vm_dimensions)
session.logout()
def get_api_session(self):
api_session = api.VMwareAPISession(
self.init_config.get("vcenter_ip", ""),
self.init_config.get("vcenter_user", ""),
self.init_config.get("vcenter_password", ""),
self.init_config.get("retry_count", 3), # retry count
self.init_config.get("poll_interval", 0.5), # task_poll_interval
port=self.init_config.get("vcenter_port", 443),
scheme="https")
return api_session