-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from whywaita/fix/106
Switch to dispatcher-worker method
- Loading branch information
Showing
6 changed files
with
257 additions
and
104 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package metric | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
|
||
"github.com/whywaita/myshoes/internal/config" | ||
"github.com/whywaita/myshoes/pkg/datastore" | ||
"github.com/whywaita/myshoes/pkg/starter" | ||
) | ||
|
||
const memoryName = "memory" | ||
|
||
var ( | ||
memoryStarterMaxRunning = prometheus.NewDesc( | ||
prometheus.BuildFQName(namespace, memoryName, "starter_max_running"), | ||
"The number of max running in starter (Config)", | ||
[]string{"starter"}, nil, | ||
) | ||
memoryStarterQueueRunning = prometheus.NewDesc( | ||
prometheus.BuildFQName(namespace, memoryName, "starter_queue_running"), | ||
"running queue in starter", | ||
[]string{"starter"}, nil, | ||
) | ||
memoryStarterQueueWaiting = prometheus.NewDesc( | ||
prometheus.BuildFQName(namespace, memoryName, "starter_queue_waiting"), | ||
"waiting queue in starter", | ||
[]string{"starter"}, nil, | ||
) | ||
) | ||
|
||
// ScraperMemory is scraper implement for memory | ||
type ScraperMemory struct{} | ||
|
||
// Name return name | ||
func (ScraperMemory) Name() string { | ||
return memoryName | ||
} | ||
|
||
// Help return help | ||
func (ScraperMemory) Help() string { | ||
return "Collect from memory" | ||
} | ||
|
||
// Scrape scrape metrics | ||
func (ScraperMemory) Scrape(ctx context.Context, ds datastore.Datastore, ch chan<- prometheus.Metric) error { | ||
if err := scrapeStarterValues(ch); err != nil { | ||
return fmt.Errorf("failed to scrape starter values: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func scrapeStarterValues(ch chan<- prometheus.Metric) error { | ||
configMax := config.Config.MaxConnectionsToBackend | ||
|
||
const labelStarter = "starter" | ||
|
||
ch <- prometheus.MustNewConstMetric( | ||
memoryStarterMaxRunning, prometheus.GaugeValue, float64(configMax), labelStarter) | ||
|
||
countRunning := starter.CountRunning | ||
countWaiting := starter.CountWaiting | ||
|
||
ch <- prometheus.MustNewConstMetric( | ||
memoryStarterQueueRunning, prometheus.GaugeValue, float64(countRunning), labelStarter) | ||
ch <- prometheus.MustNewConstMetric( | ||
memoryStarterQueueWaiting, prometheus.GaugeValue, float64(countWaiting), labelStarter) | ||
|
||
return nil | ||
} | ||
|
||
var _ Scraper = ScraperMemory{} |
Oops, something went wrong.