File tree Expand file tree Collapse file tree 1 file changed +13
-8
lines changed
Expand file tree Collapse file tree 1 file changed +13
-8
lines changed Original file line number Diff line number Diff line change @@ -77,18 +77,23 @@ func (pm *PrometheusMetric) Set() {
7777 metricM ["host" ][p .Host ]++
7878 }
7979 for k , v := range metricM {
80+ // todo: define a new type for metrics and contain name, protmetheus metric type. So, we won't have to
81+ // do manuel if-else check here.
8082 if k == "db" {
81- // todo: DRY
82- for i , j := range v {
83- pm .dbCount .With (prometheus.Labels {"db" : i }).Set (float64 (j ))
84- }
83+ setGaugeVec (k , v , pm .dbCount )
8584 } else {
8685 if k == "host" {
87- // todo: DRY
88- for i , j := range v {
89- pm .hostConn .With (prometheus.Labels {"host" : i }).Set (float64 (j ))
90- }
86+ setGaugeVec (k , v , pm .hostConn )
9187 }
9288 }
9389 }
9490}
91+
92+ func setGaugeVec (name string , m map [string ]int , gv * prometheus.GaugeVec ) {
93+ for i , j := range m {
94+ if i == "" {
95+ i = "UNKNOWN"
96+ }
97+ gv .With (prometheus.Labels {name : i }).Set (float64 (j ))
98+ }
99+ }
You can’t perform that action at this time.
0 commit comments