-
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.
* Demonstrates how the current package can be extended with third party packages Signed-off-by: Mahendra Paipuri <[email protected]>
- Loading branch information
1 parent
cae81df
commit 8425162
Showing
5 changed files
with
149 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Boiler plate code to create a new instance of BatchJobExporter entrypoint | ||
|
||
package main | ||
|
||
// Ensure to import the current mock collector | ||
import ( | ||
_ "github.com/mahendrapaipuri/batchjob_monitoring/examples/mock_exporter/pkg/collector" | ||
batchjob_collector "github.com/mahendrapaipuri/batchjob_monitoring/pkg/collector" | ||
) | ||
|
||
// Main entry point for `batchjob_exporter` app | ||
func main() { | ||
// Create a new app | ||
batchJobExporterApp, err := batchjob_collector.NewBatchJobExporter() | ||
if err != nil { | ||
panic("Failed to create an instance of BatchJobExporter App") | ||
} | ||
|
||
// Main entrypoint of the app | ||
batchJobExporterApp.Main() | ||
} |
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 collector | ||
|
||
import ( | ||
"math/rand" | ||
|
||
"github.com/go-kit/log" | ||
"github.com/mahendrapaipuri/batchjob_monitoring/pkg/collector" | ||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
// A mock collector that exports a random value between 0 and configurable maximum value | ||
const mockCollectorSubsystem = "mock" | ||
|
||
// Define mock collector struct | ||
type mockCollector struct { | ||
logger log.Logger | ||
mockMetricDesc *prometheus.Desc | ||
} | ||
|
||
// Define vars and flags necessary to configure collector | ||
var ( | ||
maxRandInt = collector.BatchJobExporterApp.Flag( | ||
"collector.mock.max", | ||
"Maximum value of the mock metric.", | ||
).Default("100").Int() | ||
) | ||
|
||
// Register mock collector | ||
func init() { | ||
collector.RegisterCollector(mockCollectorSubsystem, true, NewMockCollector) | ||
} | ||
|
||
// NewMockCollector returns a new Collector exposing mock metrics. | ||
func NewMockCollector(logger log.Logger) (collector.Collector, error) { | ||
// Define mock metric description | ||
mockMetricDesc := prometheus.NewDesc( | ||
prometheus.BuildFQName(collector.Namespace, mockCollectorSubsystem, "mockunit_total"), | ||
"Current mock metric", []string{}, nil, | ||
) | ||
|
||
// Create a new mockCollector struct | ||
collector := mockCollector{ | ||
logger: logger, | ||
mockMetricDesc: mockMetricDesc, | ||
} | ||
return &collector, nil | ||
} | ||
|
||
// Update implements Collector and exposes mock metrics. | ||
func (c *mockCollector) Update(ch chan<- prometheus.Metric) error { | ||
// Return a random value | ||
ch <- prometheus.MustNewConstMetric(c.mockMetricDesc, prometheus.CounterValue, float64(rand.Intn(*maxRandInt))) | ||
return nil | ||
} |
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,21 @@ | ||
// Boiler plate code to create a new instance of BatchJobStatsServer entrypoint | ||
|
||
package main | ||
|
||
// Ensure to import the current mock scheduler | ||
import ( | ||
_ "github.com/mahendrapaipuri/batchjob_monitoring/examples/mock_scheduler/pkg/scheduler" | ||
batchjob_stats "github.com/mahendrapaipuri/batchjob_monitoring/pkg/jobstats" | ||
) | ||
|
||
// Main entry point for `batchjob_stats_server` app | ||
func main() { | ||
// Create a new app | ||
batchJobStatsServerApp, err := batchjob_stats.NewBatchJobStatsServer() | ||
if err != nil { | ||
panic("Failed to create an instance of Batch Job Stats Server App") | ||
} | ||
|
||
// Main entrypoint of the app | ||
batchJobStatsServerApp.Main() | ||
} |
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,52 @@ | ||
package scheduler | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/go-kit/log" | ||
"github.com/go-kit/log/level" | ||
"github.com/mahendrapaipuri/batchjob_monitoring/pkg/jobstats" | ||
) | ||
|
||
type mockScheduler struct { | ||
logger log.Logger | ||
} | ||
|
||
const mockBatchScheduler = "mock" | ||
|
||
var ( | ||
slurmUserUid int | ||
slurmUserGid int | ||
macctPath = jobstats.BatchJobStatsServerApp.Flag( | ||
"mock.acct.path", | ||
"Absolute path to macct executable.", | ||
).Default("/usr/local/bin/macct").String() | ||
) | ||
|
||
func init() { | ||
// Register batch scheduler with jobstats pkg | ||
jobstats.RegisterBatch(mockBatchScheduler, true, NewMockScheduler) | ||
} | ||
|
||
// Do all basic checks here | ||
func preflightChecks(logger log.Logger) error { | ||
return nil | ||
} | ||
|
||
// NewMockScheduler returns a new MockScheduler that returns batch job stats | ||
func NewMockScheduler(logger log.Logger) (jobstats.Batch, error) { | ||
err := preflightChecks(logger) | ||
if err != nil { | ||
level.Error(logger).Log("msg", "Failed to create mock batch scheduler for retreiving jobs.", "err", err) | ||
return nil, err | ||
} | ||
level.Info(logger).Log("msg", "Jobs from mock batch scheduler will be retrieved.") | ||
return &mockScheduler{ | ||
logger: logger, | ||
}, nil | ||
} | ||
|
||
// Add the logic here to get jobs from batch scheduler and return slice of BatchJob structs | ||
func (s *mockScheduler) GetJobs(start time.Time, end time.Time) ([]jobstats.BatchJob, error) { | ||
return []jobstats.BatchJob{{Jobid: "1000"}, {Jobid: "1100"}}, nil | ||
} |
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