mirror of
https://github.com/TECHNOFAB11/zfs-localpv.git
synced 2025-12-12 06:20:11 +01:00
feat(analytics): adding google analytics for ZFSPV
Whenever a volume is provisioned and de-provisioned we will send a google event with mainly following details : 1. pvName (will shown as app title in google analytics) 2. size of the volume 3. event type : volume-provision, volume-deprovision 4. storage type zfs-localpv 5. replicacount as 1 6. ClientId as default namespace uuid Apart from this, we send the event once in 24 hr, which will have some info like number of nodes, node type, kubernetes version etc. This metric is cotrolled by OPENEBS_IO_ENABLE_ANALYTICS env. We can set it to false if we don't want to send the metrics. Signed-off-by: Pawan <pawan@mayadata.io>
This commit is contained in:
parent
0fc86d843b
commit
d608dbacd8
28 changed files with 1731 additions and 18 deletions
63
pkg/usage/ping.go
Normal file
63
pkg/usage/ping.go
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
Copyright 2020 The OpenEBS Authors.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
package usage
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/openebs/zfs-localpv/pkg/common/env"
|
||||
)
|
||||
|
||||
var OpenEBSPingPeriod = "OPENEBS_IO_ANALYTICS_PING_INTERVAL"
|
||||
|
||||
const (
|
||||
// defaultPingPeriod sets the default ping heartbeat interval
|
||||
defaultPingPeriod time.Duration = 24 * time.Hour
|
||||
// minimumPingPeriod sets the minimum possible configurable
|
||||
// heartbeat period, if a value lower than this will be set, the
|
||||
// defaultPingPeriod will be used
|
||||
minimumPingPeriod time.Duration = 1 * time.Hour
|
||||
)
|
||||
|
||||
// PingCheck sends ping events to Google Analytics
|
||||
func PingCheck() {
|
||||
// Create a new usage field
|
||||
u := New()
|
||||
duration := getPingPeriod()
|
||||
ticker := time.NewTicker(duration)
|
||||
for _ = range ticker.C {
|
||||
u.Build().
|
||||
InstallBuilder(true).
|
||||
SetCategory(Ping).
|
||||
Send()
|
||||
}
|
||||
}
|
||||
|
||||
// getPingPeriod sets the duration of health events, defaults to 24
|
||||
func getPingPeriod() time.Duration {
|
||||
value := env.GetOrDefault(OpenEBSPingPeriod, string(defaultPingPeriod))
|
||||
duration, _ := time.ParseDuration(value)
|
||||
// Sanitychecks for setting time duration of health events
|
||||
// This way, we are checking for negative and zero time duration and we
|
||||
// also have a minimum possible configurable time duration between health events
|
||||
if duration < minimumPingPeriod {
|
||||
// Avoid corner case when the ENV value is undesirable
|
||||
return time.Duration(defaultPingPeriod)
|
||||
} else {
|
||||
return time.Duration(duration)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue