[icinga-checkins] icinga.org: icinga2-api-examples/master: go-icinga2-events: Better logging

git at icinga.org git at icinga.org
Tue Oct 18 21:55:45 CEST 2016


Module: icinga2-api-examples
Branch: master
Commit: 55a48ebc8d9caacf8eab3a7a1b25b143870b254c
URL:    https://git.icinga.org/?p=icinga2-api-examples.git;a=commit;h=55a48ebc8d9caacf8eab3a7a1b25b143870b254c

Author: Michael Friedrich <michael.friedrich at icinga.com>
Date:   Sat Oct 15 20:32:11 2016 +0200

go-icinga2-events: Better logging

---

 go-icinga2-events/main.go |   20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/go-icinga2-events/main.go b/go-icinga2-events/main.go
index 958c3d0..21a05ce 100644
--- a/go-icinga2-events/main.go
+++ b/go-icinga2-events/main.go
@@ -137,9 +137,7 @@ func handleEventTypes(response string) {
 	}
 
 	if CheckResult.Type == "CheckResult" {
-		fmt.Println("Processing type 'CheckResult'")
-
-		fmt.Println()
+		//fmt.Println("Processing type 'CheckResult'")
 
 		CheckResultCount++
 
@@ -156,12 +154,14 @@ func handleEventTypes(response string) {
 		StateChangesObject[ObjectName] = append(StateChangesObject[ObjectName], state)
 
 		//periodic statistics
-		if time.Now().Unix() % 5 == 0 {
-			var CheckResultRate = CheckResultCount / (time.Now().Unix() - StartTime)
-			fmt.Println("Global check result rate:", CheckResultRate)
+		if time.Now().Unix() % 2 == 0 {
+			var CheckResultRate = float64(CheckResultCount) / float64(time.Now().Unix() - StartTime)
+			fmt.Println("Global check result rate/second:", CheckResultRate)
+
+			var CheckResultObjectRate = float64(CheckResultCountObject[ObjectName]) / float64(time.Now().Unix() - StartTime)
+			fmt.Printf("Check result rate for object '%s': %.02f\n", ObjectName, CheckResultObjectRate)
 
-			var CheckResultObjectRate = CheckResultCountObject[ObjectName] / (time.Now().Unix() - StartTime)
-			fmt.Printf("Check result rate for object %s: %f", ObjectName, CheckResultObjectRate)
+			fmt.Println(" ")
 		}
 	}
 }
@@ -203,8 +203,8 @@ func eventLoop() {
 			fmt.Println("Error reading stream", err)
 			return
 		}
-		fmt.Println("Processing message")
-		fmt.Println(string(line))
+		//fmt.Println("Processing message")
+		//fmt.Println(string(line))
 
 		//call handler for json decoding and message processing
 		handleEventTypes(string(line))



More information about the icinga-checkins mailing list