Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Extends metrics to keep track of OCISAppsMetric and OCISUniqUsers #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"strings"
"time"
)

var pushFlag bool
var prefixFlag string
var carbonServerFlag string
Expand Down Expand Up @@ -49,6 +48,12 @@ func main() {
pattern = path.Join("/data/log/", today, "box.samba*/*/td.var.log.samba.smbclients.log")
metrics = append(metrics, parse(pattern, uniqSamba)...)

// analyze OCIS logs
OCISappsMetrics := revad.NewOCISAppsMetric()
OCISuniqWeb := revad.NewOCISUniqUsers()
pattern = path.Join("/data/log/", today, "box.ocis*/*/td.var.log.revad-gateway.log")
metrics = append(metrics, parse(pattern, OCISappsMetrics, OCISuniqWeb)...)

// send to carbon
push(metrics)
}
Expand Down
76 changes: 76 additions & 0 deletions revad/revad.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ type line struct {
Environment string `json:"environment"`
Time time.Time `json:"time"`
Username string `json:"username"`
Path string `json:"path"`
Agent string `json:"agent"`
User string `json:"user"`
Country string `json:"country"`
}

type UserCreated struct {
Expand Down Expand Up @@ -82,3 +86,75 @@ func (uu *UniqUsers) Metrics() map[string]int {
}
return m
}

//Apps used metric scanning for OCIS specific app identifiers
type OCISAppsMetric struct {
dist map[string]int
}

func (uu *OCISAppsMetric) Do(data []byte) {
l := &line{}

if err := jsoniter.Unmarshal([]byte(data), l); err != nil {
er(err)
}

if strings.Contains(l.Path, "/text-editor") {
uu.dist["OCIS.apps.usage.OCIStext-editor"]++
} else if strings.Contains(l.Path, "/*.docx?app=MS'%'20365'%'20on'%'20Cloud") {
uu.dist["OCIS.apps.usage.word"]++
} else if strings.Contains(l.Path, "/draw-io") {
uu.dist["OCIS.apps.usage.OCISdrawio"]++
} else if strings.Contains(l.Path, "/*.md?app=CodiMD") {
uu.dist["OCIS.apps.usage.CodiMD"]++
} else if strings.Contains(l.Path, "/*.xlsx?app=MS'%'20365'%'20on'%'20Cloud") {
uu.dist["OCIS.apps.usage.excel"]++
} else if strings.Contains(l.Path, "/*.pptx?app=MS'%'20365'%'20on'%'20Cloud") {
uu.dist["OCIS.apps.usage.pwpoint"]++
} else if strings.Contains(l.Path, "/*.odt?app=Collabora") {
uu.dist["OCIS.apps.usage.openDoc"]++
} else if strings.Contains(l.Path, "/*.ods?app=Collabora") {
uu.dist["OCIS.apps.usage.openSpread"]++
} else if strings.Contains(l.Path, "/*.odp?app=Collabora") {
uu.dist["OCIS.apps.usage.openSlide"]++
}

}

func NewOCISAppsMetric() *OCISAppsMetric {
return &OCISAppsMetric{
dist: map[string]int{},
}
}

func (uu *OCISAppsMetric) Metrics() map[string]int {
return uu.dist
}

//metric that keeps track of Unique OCIS Users
type OCISUniqUsers struct {
dist map[string]int
}

func (uu *OCISUniqUsers) Do(data []byte) {
l := &line{}

if err := jsoniter.Unmarshal([]byte(data), l); err != nil {
er(err)
}

if l.User != "" {
uu.dist[l.User]++
}
}

func NewOCISUniqUsers() *OCISUniqUsers {
return &OCISUniqUsers{dist: map[string]int{}}
}

func (uu *OCISUniqUsers) Metrics() map[string]int {
m := map[string]int{
"users.OCISweb": len(uu.dist),
}
return m
}