Skip to content

Commit

Permalink
Added ansible install script and fix disk root image read error
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian simon committed Nov 29, 2019
1 parent 00fe08e commit b61ab80
Show file tree
Hide file tree
Showing 184 changed files with 30,143 additions and 8,858 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ require (
bou.ke/monkey v1.0.1 // indirect
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
github.com/bradleyjkemp/cupaloy v2.3.0+incompatible
github.com/cloudfoundry/gosigar v1.1.0
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/diskfs/go-diskfs v0.0.0-20191115120903-6cf046d472d7 // indirect
github.com/go-ole/go-ole v1.2.4 // indirect
github.com/gorilla/websocket v1.4.1
github.com/jaypipes/ghw v0.0.0-20190821154021-743802778342
Expand Down
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@ github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUW
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
github.com/bradleyjkemp/cupaloy v2.3.0+incompatible h1:UafIjBvWQmS9i/xRg+CamMrnLTKNzo+bdmT/oH34c2Y=
github.com/bradleyjkemp/cupaloy v2.3.0+incompatible/go.mod h1:Au1Xw1sgaJ5iSFktEhYsS0dbQiS1B0/XMXl+42y9Ilk=
github.com/cloudfoundry/gosigar v1.1.0 h1:V/dVCzhKOdIU3WRB5inQU20s4yIgL9Dxx/Mhi0SF8eM=
github.com/cloudfoundry/gosigar v1.1.0/go.mod h1:3qLfc2GlfmwOx2+ZDaRGH3Y9fwQ0sQeaAleo2GV5pH0=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/diskfs/go-diskfs v0.0.0-20191115120903-6cf046d472d7 h1:R0Q5Sb1rWQwYHrf1etayhN446LSm7gvG2sgE88ochbA=
github.com/diskfs/go-diskfs v0.0.0-20191115120903-6cf046d472d7/go.mod h1:x7shCYRoIc+XvebaZAnK9x6wsYAS+ExHUjuoZcnO+nc=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI=
github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM=
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
Expand Down Expand Up @@ -57,9 +63,13 @@ go.uber.org/zap v1.10.0 h1:ORx85nbTijNz8ljznvCMR1ZBIPKFn3jQrag10X2AsuM=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
golang.org/x/sys v0.0.0-20190410235845-0ad05ae3009d h1:+9jagSGtlJZAaZGdRvJikXNpc5lh2/rq9eyMN/5kmwA=
golang.org/x/sys v0.0.0-20190410235845-0ad05ae3009d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190804053845-51ab0e2deafa h1:KIDDMLT1O0Nr7TSxp8xM5tJcdn8tgyAONntO829og1M=
golang.org/x/sys v0.0.0-20190804053845-51ab0e2deafa/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/djherbis/times.v1 v1.2.0 h1:UCvDKl1L/fmBygl2Y7hubXCnY7t4Yj46ZrBFNUipFbM=
gopkg.in/djherbis/times.v1 v1.2.0/go.mod h1:AQlg6unIsrsCEdQYhTzERy542dz6SFdQFZFv6mUY0P8=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
1 change: 1 addition & 0 deletions installing/ansibe/hosts.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
localhost ansible_ssh_user=root
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
- hosts: all
vars_files:
- vars/settings.yml
tasks:
- name: Create destination directory
file:
path: /usr/lokal/funk_metric_agent
state: directory
mode: '0755'

- name: Download binary {{ DOWNLOADURL }}
get_url:
url: "{{ DOWNLOADURL }}"
dest: /usr/lokal/funk_metric_agent/funk_metric_agent_LINUX_{{ VERSION }}
mode: '0755'

- name: Copy init.d file
template:
src: ./funkmetricagent.j2
dest: /etc/init.d/funkmetricagent
mode: '0755'

- name: Enable service funkmetricagent, and start service
service:
name: funkmetricagent
enabled: yes
state: started
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: funk-metric-agent
# Required-Start: $local_fs $network $named $time $syslog
# Required-Stop: $local_fs $network $named $time $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: This is the systctl sctipt to start funk_metric_agent it was rollout with ansible so do not change by hand
### END INIT INFO

SCRIPT="/usr/lokal/funk_metric_agent/funk_metric_agent_LINUX_{{ VERSION }} --funkserver {{ FUNKSERVER }} --connectionkey {{ CONNECTIONKEY }} --searchindex={{ SEARCHINDEX }} {{ FUNK_ARGS }} &"
RUNAS=root

PIDFILE=/var/run/funk-metric-agent.pid
LOGFILE=/var/log/funk-metric-agent.log

start() {
if [ -f /var/run/$PIDNAME ] && kill -0 $(cat /var/run/$PIDNAME); then
echo 'Service already running' >&2
return 1
fi
echo 'Starting service…' >&2
local CMD="$SCRIPT &> \"$LOGFILE\" & echo \$!"
su -c "$CMD" $RUNAS > "$PIDFILE"
echo 'Service started' >&2
}

stop() {
if [ ! -f "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE"); then
echo 'Service not running' >&2
return 1
fi
echo 'Stopping service…' >&2
kill -15 $(cat "$PIDFILE") && rm -f "$PIDFILE"
echo 'Service stopped' >&2
}

uninstall() {
echo -n "Are you really sure you want to uninstall this service? That cannot be undone. [yes|No] "
local SURE
read SURE
if [ "$SURE" = "yes" ]; then
stop
rm -f "$PIDFILE"
echo "Notice: log file is not be removed: '$LOGFILE'" >&2
update-rc.d -f funk-metric-agent remove
rm -fv "$0"
fi
}

case "$1" in
start)
start
;;
stop)
stop
;;
uninstall)
uninstall
;;
restart)
stop
start
;;
*)
echo "Usage: $0 {start|stop|restart|uninstall}"
esac
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
VERSION: 679
DOWNLOADURL: https://github.com/fasibio/funk-metric-agent/releases/download/refs%2Fheads%2F0.0.678/funk_metric_agent_LINUX_679
FUNK_ARGS: ''
SEARCHINDEX: host
FUNKSERVER: ws://localhost:3000
CONNECTIONKEY: changeMe04cf242924f6b5f96
5 changes: 5 additions & 0 deletions installing/ansibe/testbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- hosts: all

- name: Install funk metric agent
import_playbook: playbooks/funk_metric_agent/install_funk_metric_agent.yml host=all
48 changes: 36 additions & 12 deletions tracker/trackMetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"syscall"
"time"

sigar "github.com/cloudfoundry/gosigar"
"github.com/fasibio/funk-metric-agent/logger"
"github.com/jaypipes/ghw"
"github.com/mackerelio/go-osstat/cpu"
Expand Down Expand Up @@ -67,24 +68,47 @@ func NewMetricsReader() MetricsReadAble {
}

func (m *MetricsReader) GetDisksMetrics() ([]DiskInformation, error) {
fslist := sigar.FileSystemList{}
fslist.Get()
var res []DiskInformation
block, err := m.StatsReader.GetBlock()
if err == nil {
for _, one := range block.Disks {
for _, onePartion := range one.Partitions {
if !onePartion.IsReadOnly {
var tmp DiskInformation
tmp.DiskName = onePartion.Name
tmp.MountPoint = onePartion.MountPoint
diskuse := diskUsage(onePartion.MountPoint)
tmp.DiskTotal = diskuse.All
tmp.DiskFree = diskuse.Avail
tmp.DiskUsed = diskuse.Used
tmp.DiskUsedPercent = float64(diskuse.Used) / float64(diskuse.All) * 100
tmp.DiskAvailPercent = float64(diskuse.Avail) / float64(diskuse.All) * 100
res = append(res, tmp)
if len(one.Partitions) == 0 {

for _, f := range fslist.List {
if f.DevName == "/dev/"+one.Name {
var tmp DiskInformation
tmp.DiskName = one.Name
tmp.MountPoint = f.DirName
diskuse := diskUsage(f.DirName)
tmp.DiskTotal = diskuse.All
tmp.DiskFree = diskuse.Avail
tmp.DiskUsed = diskuse.Used
tmp.DiskUsedPercent = float64(diskuse.Used) / float64(diskuse.All) * 100
tmp.DiskAvailPercent = float64(diskuse.Avail) / float64(diskuse.All) * 100
logger.Get().Info(tmp)
res = append(res, tmp)
}
}

} else {
for _, onePartion := range one.Partitions {
if !onePartion.IsReadOnly {
var tmp DiskInformation
tmp.DiskName = onePartion.Name
tmp.MountPoint = onePartion.MountPoint
diskuse := diskUsage(onePartion.MountPoint)
tmp.DiskTotal = diskuse.All
tmp.DiskFree = diskuse.Avail
tmp.DiskUsed = diskuse.Used
tmp.DiskUsedPercent = float64(diskuse.Used) / float64(diskuse.All) * 100
tmp.DiskAvailPercent = float64(diskuse.Avail) / float64(diskuse.All) * 100
res = append(res, tmp)
}
}
}

}
} else {
logger.Get().Errorw("Error by reading dist block info: " + err.Error())
Expand Down
1 change: 1 addition & 0 deletions vendor/github.com/cloudfoundry/gosigar/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions vendor/github.com/cloudfoundry/gosigar/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 63 additions & 0 deletions vendor/github.com/cloudfoundry/gosigar/Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 72 additions & 0 deletions vendor/github.com/cloudfoundry/gosigar/Gopkg.toml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b61ab80

Please sign in to comment.