forked from apache/servicecomb-kie
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat]support report the index of servicecomb_kie_config_count to pro…
…metheus (apache#316) Co-authored-by: songshiyuan 00649746 <[email protected]> (cherry picked from commit 0167fb0)
- Loading branch information
1 parent
77a402f
commit 22bdbaf
Showing
4 changed files
with
62 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package metrics | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/go-chassis/go-archaius" | ||
"github.com/go-chassis/go-chassis/v2/pkg/metrics" | ||
"github.com/go-chassis/openlog" | ||
|
||
"github.com/apache/servicecomb-kie/server/datasource" | ||
) | ||
|
||
const domain = "default" | ||
const project = "default" | ||
|
||
func InitMetric() error { | ||
err := metrics.CreateGauge(metrics.GaugeOpts{ | ||
Key: "servicecomb_kie_config_count", | ||
Help: "use to show the number of config under a specifical domain and project pair", | ||
Labels: []string{"domain", "project"}, | ||
}) | ||
if err != nil { | ||
openlog.Error("init servicecomb_kie_config_count Gauge fail:" + err.Error()) | ||
return err | ||
} | ||
reportIntervalstr := archaius.GetString("servicecomb.metrics.interval", "5s") | ||
reportInterval, _ := time.ParseDuration(reportIntervalstr) | ||
reportTicker := time.NewTicker(reportInterval) | ||
go func() { | ||
for { | ||
_, ok := <-reportTicker.C | ||
if !ok { | ||
return | ||
} | ||
getTotalConfigCount(project, domain) | ||
} | ||
}() | ||
return nil | ||
} | ||
|
||
func getTotalConfigCount(project, domain string) { | ||
total, err := datasource.GetBroker().GetKVDao().Total(context.TODO(), project, domain) | ||
if err != nil { | ||
openlog.Error("set total config number fail: " + err.Error()) | ||
return | ||
} | ||
labels := map[string]string{"domain": domain, "project": project} | ||
err = metrics.GaugeSet("servicecomb_kie_config_count", float64(total), labels) | ||
if err != nil { | ||
openlog.Error("set total config number fail:" + err.Error()) | ||
return | ||
} | ||
} |
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