Skip to content

Instantly share code, notes, and snippets.

@gregarndt
Created March 19, 2016 16:16
Show Gist options
  • Save gregarndt/cdcade83b92148519859 to your computer and use it in GitHub Desktop.
Save gregarndt/cdcade83b92148519859 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"sync"
"github.com/snaury/tdigest-go"
)
type Aggregator struct {
Projects map[string]*Project
}
type counterMetric struct {
m sync.Mutex
count float64
hourlyCount float64
}
type valueMetric struct {
m sync.Mutex
digest *tdigest.MergingDigest
hourlySummary []tdigest.Centroid
}
type Project struct {
countMetrics map[interface{}]*counterMetric
valueMetrics map[interface{}]*valueMetric
}
func main() {
agg := &Aggregator{Projects: make(map[string]*Project)}
agg.Projects["project1"] = &Project{
countMetrics: make(map[interface{}]*counterMetric),
valueMetrics: make(map[interface{}]*valueMetric),
}
type dimension struct {
workerType string
region string
}
dimKey := &dimension{workerType: "b2gtest", region: "us-west-2"}
agg.Projects["project1"].countMetrics[dimKey] = &counterMetric{
count: 64,
hourlyCount: 300,
}
for projectName, project := range agg.Projects {
fmt.Println("Processing", projectName)
for dim, metrics := range project.countMetrics {
// Can compose the signal fx dimensions based on this key.
fmt.Printf("%+v\n", dim)
fmt.Printf("%+v\n", metrics)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment