Skip to content

Commit

Permalink
[feat] Create Metrics from JS
Browse files Browse the repository at this point in the history
  • Loading branch information
uppfinnarn committed Nov 18, 2016
1 parent 72123b4 commit de3e46f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
40 changes: 40 additions & 0 deletions js/lib/speedboat/metrics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
export let CounterType = 1;
export let GaugeType = 2;
export let TrendType = 3;

export class Metric {
constructor(t, name) {
if (!__initapi__) {
throw new Error("Metrics can only be created during the init phase");
}
this._impl = __initapi__.NewMetric(t, name);
}
}

export class Counter extends Metric {
constructor(name) {
super(CounterType, name);
}
}

export class Gauge extends Metric {
constructor(name) {
super(GaugeType, name);
}
}

export class Trend extends Metric {
constructor(name) {
super(TrendType, name);
}
}

export default {
CounterType: CounterType,
GaugeType: GaugeType,
TrendType: TrendType,
Metric: Metric,
Counter: Counter,
Gauge: Gauge,
Trend: Trend,
}
2 changes: 2 additions & 0 deletions js/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Runtime struct {
VM *otto.Otto
Root string
Exports map[string]otto.Value
Metrics map[string]*stats.Metric

lib map[string]otto.Value
}
Expand All @@ -41,6 +42,7 @@ func New() (*Runtime, error) {
VM: otto.New(),
Root: wd,
Exports: make(map[string]otto.Value),
Metrics: make(map[string]*stats.Metric),
lib: make(map[string]otto.Value),
}

Expand Down

0 comments on commit de3e46f

Please sign in to comment.