-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add package handling the metrics. Add example metric for mask plugin
- Loading branch information
Sandu Kiritsa
committed
Mar 6, 2022
1 parent
228a048
commit 1ec090e
Showing
5 changed files
with
90 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package stats | ||
|
||
import ( | ||
"github.com/ozontech/file.d/pipeline" | ||
prom "github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
type MetricDesc struct { | ||
Subsystem string | ||
Name string | ||
Help string | ||
} | ||
|
||
type key struct { | ||
namespace string | ||
subsystem string | ||
name string | ||
} | ||
|
||
type AnyMetric prom.Collector | ||
|
||
type stats struct { | ||
allMetrics map[key]AnyMetric | ||
} | ||
|
||
var statsGlobal *stats | ||
|
||
func InitStats() { | ||
statsGlobal = &stats{} | ||
statsGlobal.allMetrics = make(map[key]AnyMetric) | ||
} | ||
|
||
func RegisterCounter(metricDesc *MetricDesc) { | ||
maskPromCounter := prom.NewCounter(prom.CounterOpts{ | ||
Namespace: pipeline.PromNamespace, | ||
Subsystem: metricDesc.Subsystem, | ||
Name: metricDesc.Name, | ||
Help: metricDesc.Help, | ||
}) | ||
|
||
keyInternal := key{pipeline.PromNamespace, metricDesc.Subsystem, metricDesc.Name} | ||
statsGlobal.registerMetric(keyInternal, maskPromCounter) | ||
} | ||
|
||
func GetCounter(subsystem, metricName string) prom.Counter { | ||
return statsGlobal.allMetrics[getKey(subsystem, metricName)].(prom.Counter) | ||
} | ||
|
||
func getKey(subsystem, metricName string) key { | ||
return key{pipeline.PromNamespace, subsystem, metricName} | ||
} | ||
|
||
func (s *stats) registerMetric(k key, metric prom.Collector) { | ||
s.allMetrics[k] = metric | ||
prom.DefaultRegisterer.Unregister(metric) | ||
prom.DefaultRegisterer.MustRegister(metric) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters