-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support report the index of servicecomb_kie_config_count to prometheus #315
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package metric | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 应该是server/metrics包 |
||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/go-chassis/go-chassis/v2/pkg/metrics" | ||
"github.com/go-chassis/openlog" | ||
|
||
"github.com/apache/servicecomb-kie/server/config" | ||
"github.com/apache/servicecomb-kie/server/datasource" | ||
) | ||
|
||
const ReportInterval = 15 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个需要可配置 |
||
|
||
func InitMetric(m config.MetricObject) 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 | ||
} | ||
if m.Domain == "" { | ||
m.Domain = "default" | ||
} | ||
if m.Project == "" { | ||
m.Project = "default" | ||
} | ||
ReportTicker := time.NewTicker(ReportInterval * time.Second) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 局部变量命名大写开头不规范 |
||
go func() { | ||
for { | ||
_, ok := <-ReportTicker.C | ||
if !ok { | ||
return | ||
} | ||
getTotalConfigCount(m.Project, m.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 | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不需要配置,这些通过环境变量控制即可