Skip to content

Commit

Permalink
resolve conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
cha87de committed Nov 21, 2018
2 parents 4e74f75 + bbd6726 commit c7e00ac
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 44 deletions.
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[![Build Status](https://travis-ci.org/cha87de/kvmtop.svg?branch=profiler)](https://travis-ci.org/cha87de/kvmtop)
[![GitHub release](https://img.shields.io/github/release/cha87de/kvmtop.svg)](https://github.com/cha87de/kvmtop/releases)
[![GitHub stars](https://img.shields.io/github/stars/cha87de/kvmtop.svg?style=social&label=Stars)](https://github.com/cha87de/kvmtop)
[![Go Report Card](https://goreportcard.com/badge/github.com/cha87de/kvmtop)](https://goreportcard.com/report/github.com/cha87de/kvmtop)
[![GoDoc](https://godoc.org/github.com/cha87de/kvmtop?status.svg)](https://godoc.org/github.com/cha87de/kvmtop)
[![Docker Pulls](https://img.shields.io/docker/pulls/cha87de/kvmtop.svg)](https://hub.docker.com/r/cha87de/kvmtop/)

## What kvmtop does
Expand Down Expand Up @@ -119,8 +121,6 @@ A more detailed list, including all metrics is available here at [./docs/README.
## kvmtop with InfluxDB

kvmtop can be used as a monitoring agent to send data to an InfluxDB instance: kvmtop transmits JSON data via TCP to logstash, while logstash writes to InfluxDB. More detailes are available at [https://github.com/cha87de/kvmtop-datasink/](https://github.com/cha87de/kvmtop-datasink/).
<<<<<<< HEAD
=======

```
kvmtop-datasink
Expand All @@ -134,4 +134,17 @@ kvmtop can be used as a monitoring agent to send data to an InfluxDB instance: k
| |
+-----------------------------------------------------+
```
>>>>>>> master

# Development Guide

Install the golang binary. Create a new folder as your kvmtop workspace, e.g. /opt/kvmtop. Then follow these steps:

```
cd /opt/kvmtop
export GOPATH=$(pwd) # take workspace as GOPATH
go get -d github.com/cha87de/kvmtop/... # download all source files, including depencencies
go install github.com/cha87de/kvmtop/... # compile kvmtop binaries
```
The resulting binaries are then located in `/opt/kvmtop/bin`.

Further reading: https://golang.org/doc/code.html
3 changes: 3 additions & 0 deletions collectors/cpucollector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ func (collector *Collector) Collect() {
cpuCollect(&domain)
return true
})

// collect host measurements
cpuCollectHost(models.Collection.Host)
}

// Print returns the collectors measurements in a Printable struct
Expand Down
4 changes: 4 additions & 0 deletions collectors/cpucollector/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func cpuLookupHost(host *models.Host) {
host.AddMetricMeasurement("cpu_cores", models.CreateMeasurement(uint64(cores)))
}

func cpuCollectHost(host *models.Host) {
// TODO lookup cpu host utilisation, cf. #23
}

func cpuPrintHost(host *models.Host) []string {
cpuMinfreq := collectors.GetMetricFloat64(host.Measurable, "cpu_minfreq", 0)
cpuMaxfreq := collectors.GetMetricFloat64(host.Measurable, "cpu_maxfreq", 0)
Expand Down
36 changes: 22 additions & 14 deletions collectors/hostcollector/collector.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package hostcollector

import (
"os"

"github.com/cha87de/kvmtop/config"
"github.com/cha87de/kvmtop/models"
)

Expand All @@ -17,9 +16,10 @@ func (collector *Collector) Lookup() {
uuid := key.(string)
domain := value.(models.Domain)
libvirtDomain, _ := models.Collection.LibvirtDomains.Load(uuid)
hostLookup(&domain, libvirtDomain)
domainLookup(&domain, libvirtDomain)
return true
})
hostLookup(models.Collection.Host)
}

// Collect host collector data
Expand All @@ -28,35 +28,43 @@ func (collector *Collector) Collect() {
models.Collection.Domains.Map.Range(func(key, value interface{}) bool {
// uuid := key.(string)
domain := value.(models.Domain)
hostCollect(&domain)
domainCollect(&domain)
return true
})
hostCollect(models.Collection.Host)
}

// Print returns the collectors measurements in a Printable struct
func (collector *Collector) Print() models.Printable {
hostFields := []string{
"host_name",
}
domainFields := []string{
"host_name",
}

if config.Options.Verbose {
hostFields = append(hostFields,
"host_uuid",
)
}

printable := models.Printable{
HostFields: []string{
"host_name",
},
DomainFields: []string{
"host_name",
},
HostFields: hostFields,
DomainFields: domainFields,
}

// lookup for each domain
printable.DomainValues = make(map[string][]string)
models.Collection.Domains.Map.Range(func(key, value interface{}) bool {
uuid := key.(string)
domain := value.(models.Domain)
printable.DomainValues[uuid] = hostPrint(&domain)
printable.DomainValues[uuid] = domainPrint(&domain)
return true
})

// lookup for host
// printable.HostValues = cpuPrintHost(host)
hostname, _ := os.Hostname()
printable.HostValues = append(printable.HostValues, hostname)
printable.HostValues = hostPrint(models.Collection.Host)

return printable
}
Expand Down
7 changes: 7 additions & 0 deletions collectors/hostcollector/domainCollect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package hostcollector

import "github.com/cha87de/kvmtop/models"

func domainCollect(domain *models.Domain) {
// nothing to do at present
}
16 changes: 16 additions & 0 deletions collectors/hostcollector/domainLookup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package hostcollector

import (
"os"

"github.com/cha87de/kvmtop/models"
libvirt "github.com/libvirt/libvirt-go"
)

func domainLookup(domain *models.Domain, libvirtDomain libvirt.Domain) {
name, err := os.Hostname()
if err != nil {
panic(err)
}
domain.AddMetricMeasurement("host_name", models.CreateMeasurement(name))
}
12 changes: 12 additions & 0 deletions collectors/hostcollector/domainPrint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package hostcollector

import (
"github.com/cha87de/kvmtop/collectors"
"github.com/cha87de/kvmtop/models"
)

func domainPrint(domain *models.Domain) []string {
host := collectors.GetMetricString(domain.Measurable, "host_name", 0)
result := append([]string{host})
return result
}
7 changes: 7 additions & 0 deletions collectors/hostcollector/hostCollect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package hostcollector

import "github.com/cha87de/kvmtop/models"

func hostCollect(host *models.Host) {
// nothing to do
}
22 changes: 22 additions & 0 deletions collectors/hostcollector/hostLookup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package hostcollector

import (
"os"

"github.com/cha87de/kvmtop/config"
"github.com/cha87de/kvmtop/models"
"github.com/cha87de/kvmtop/util"
)

func hostLookup(host *models.Host) {
name, err := os.Hostname()
if err != nil {
panic(err)
}
host.AddMetricMeasurement("host_name", models.CreateMeasurement(name))

if config.Options.Verbose {
uuid := util.GetSysDmiUUID()
host.AddMetricMeasurement("host_uuid", models.CreateMeasurement(uuid.Value))
}
}
18 changes: 18 additions & 0 deletions collectors/hostcollector/hostPrint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package hostcollector

import (
"github.com/cha87de/kvmtop/collectors"
"github.com/cha87de/kvmtop/config"
"github.com/cha87de/kvmtop/models"
)

func hostPrint(host *models.Host) []string {
hostname := collectors.GetMetricString(host.Measurable, "host_name", 0)
result := []string{hostname}

if config.Options.Verbose {
hostUUID := collectors.GetMetricString(host.Measurable, "host_uuid", 0)
result = append(result, hostUUID)
}
return result
}
27 changes: 0 additions & 27 deletions collectors/hostcollector/worker.go

This file was deleted.

25 changes: 25 additions & 0 deletions util/sys-dmi-uuid.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package util

import (
"bytes"
"fmt"
"io/ioutil"
)

// SysDmiUUID reflects the systems UUID from /sys/devices/virtual/dmi/id/product_uuid
type SysDmiUUID struct {
Value string
}

// GetSysDmiUUID reads the hosts DMI UUID from /sys/devices/virtual/dmi/id/product_uuid
// Please Note: root privileges are required to read the file
func GetSysDmiUUID() SysDmiUUID {
stat := SysDmiUUID{}
filepath := fmt.Sprint("/sys/devices/virtual/dmi/id/product_uuid")
filecontent, _ := ioutil.ReadFile(filepath)
fmt.Fscan(
bytes.NewBuffer(filecontent),
&stat.Value,
)
return stat
}

0 comments on commit c7e00ac

Please sign in to comment.