Skip to content
This repository was archived by the owner on Jan 24, 2023. It is now read-only.

Commit 6666dda

Browse files
committed
added some more expvar stats tracking
1 parent 661f5c0 commit 6666dda

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,11 @@ The following options are available:
5252

5353
Currently `innovazammad` uses innovaphone's [v10 SOAP API](http://wiki.innovaphone.com/index.php?title=Reference10:SOAP_API) (see `innovaphone/pbx10_00.{go,wsdl}`). Older PBX might not work.
5454

55-
On the Zammad side, it has been tested against the `2.9.x` branch.
55+
On the Zammad side, it has been tested against the `2.9.x` branch.
56+
57+
## Monitoring
58+
59+
Internal state can be monitored by querying the metrics endpoint:
60+
```
61+
curl -s localhost:8080/debug/vars
62+
```

main.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"net/http"
77
"os"
8+
"time"
89

910
"github.com/regiohelden/innovazammad/config"
1011
"github.com/regiohelden/innovazammad/innovaphone"
@@ -62,19 +63,29 @@ func main() {
6263

6364
logrus.Infof("starting innovaphone-zammad bridge")
6465

66+
connectionStats := expvar.NewMap("connection_stats")
67+
6568
zammadSession := zammad.NewSession()
6669
for {
6770
innovaphoneSession := innovaphone.NewSession()
71+
connectionStats.Set("on_since", timeString(time.Now().Format(time.RFC3339)))
6872
calls, errs := innovaphoneSession.PollForever()
6973
handling:
7074
for {
7175
select {
7276
case call := <-calls:
73-
go zammadSession.Submit(call)
77+
zammadSession.Submit(call)
7478
case err := <-errs:
7579
logrus.Errorf("error while polling: %s", err)
7680
break handling
7781
}
7882
}
83+
connectionStats.Add("errors", 1)
7984
}
8085
}
86+
87+
type timeString string
88+
89+
func (ts timeString) String() string {
90+
return fmt.Sprintf("\"%s\"", string(ts))
91+
}

zammad/zammad.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func (cs callMap) String() string {
6767
// Session keeps track of the states successfully submitted to Zammad
6868
type Session struct {
6969
callMap callMap
70+
stats *expvar.Map
7071
sync.Mutex
7172
}
7273

@@ -80,6 +81,7 @@ type stateTransition struct {
8081
func NewSession() *Session {
8182
calls := &Session{
8283
callMap: callMap{},
84+
stats: expvar.NewMap("stats"),
8385
}
8486
expvar.Publish("calls", calls.callMap)
8587
return calls
@@ -110,12 +112,15 @@ func (zs *Session) setOrUpdate(callID int, newEntry *callEntry) {
110112
} else if curEntry, ok := zs.callMap[callID]; ok {
111113
curEntry.State = newEntry.State
112114
} else {
115+
zs.stats.Add("calls_total", 1)
113116
zs.callMap[callID] = newEntry
114117
}
115118
}
116119

117120
// Submit sends a call to Zammad, if we are aware of it and can correctly map its state to some known Zammad state
118121
func (zs *Session) Submit(call *innovaphone.CallInSession) error {
122+
zs.stats.Add("events_total", 1)
123+
119124
src, dst, err := call.GetSourceAndDestination()
120125
if err != nil {
121126
return err
@@ -201,6 +206,7 @@ func (zs *Session) Submit(call *innovaphone.CallInSession) error {
201206
if resp.StatusCode < 200 || resp.StatusCode > 299 {
202207
return fmt.Errorf("could not submit to Zammad: %s", resp.Status)
203208
}
209+
zs.stats.Add("events_submitted", 1)
204210
zs.setOrUpdate(call.Call, entry)
205211
return nil
206212
}

0 commit comments

Comments
 (0)