-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support report the index of servicecomb_kie_config_count
- Loading branch information
songshiyuan 00649746
committed
Jan 24, 2024
1 parent
bea6626
commit 8910c73
Showing
7 changed files
with
88 additions
and
8 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
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,65 @@ | ||
package metrics | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"strings" | ||
"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" | ||
) | ||
|
||
func InitMetric(m *config.Config) 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 | ||
} | ||
domain, project := "", "" | ||
if os.Getenv("DOMAIN") == "" { | ||
domain = "default" | ||
} | ||
if os.Getenv("PROJECT") == "" { | ||
project = "default" | ||
} | ||
reportInterval := 10 * time.Second | ||
if config.GetReportInterval() != "" { | ||
str := strings.TrimSpace(config.GetReportInterval()) | ||
reportInterval, _ = time.ParseDuration(str) | ||
} | ||
reportTicker := time.NewTicker(reportInterval) | ||
fmt.Println(m) | ||
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