-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
215 additions
and
19 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,105 @@ | ||
package harmonytask | ||
|
||
import ( | ||
promclient "github.com/prometheus/client_golang/prometheus" | ||
"go.opencensus.io/stats" | ||
"go.opencensus.io/stats/view" | ||
"go.opencensus.io/tag" | ||
) | ||
|
||
var ( | ||
taskNameTag, _ = tag.NewKey("task_name") | ||
sourceTag, _ = tag.NewKey("source") | ||
pre = "harmonytask_" | ||
|
||
// tasks can be short, but can extend to hours | ||
durationBuckets = []float64{0.5, 1, 3, 6, 10, 20, 30, 60, 120, 300, 600, 1800, 3600, 7200, 18000, 36000} | ||
) | ||
|
||
// TaskMeasures groups all harmonytask metrics. | ||
var TaskMeasures = struct { | ||
TasksStarted *stats.Int64Measure | ||
TasksCompleted *stats.Int64Measure | ||
TasksFailed *stats.Int64Measure | ||
TaskDuration promclient.Histogram | ||
ActiveTasks *stats.Int64Measure | ||
CpuUsage *stats.Float64Measure | ||
GpuUsage *stats.Float64Measure | ||
RamUsage *stats.Float64Measure | ||
PollerIterations *stats.Int64Measure | ||
AddedTasks *stats.Int64Measure | ||
}{ | ||
TasksStarted: stats.Int64(pre+"tasks_started", "Total number of tasks started.", stats.UnitDimensionless), | ||
TasksCompleted: stats.Int64(pre+"tasks_completed", "Total number of tasks completed successfully.", stats.UnitDimensionless), | ||
TasksFailed: stats.Int64(pre+"tasks_failed", "Total number of tasks that failed.", stats.UnitDimensionless), | ||
TaskDuration: promclient.NewHistogram(promclient.HistogramOpts{ | ||
Name: pre + "task_duration_seconds", | ||
Buckets: durationBuckets, | ||
Help: "The histogram of task durations in seconds.", | ||
}), | ||
ActiveTasks: stats.Int64(pre+"active_tasks", "Current number of active tasks.", stats.UnitDimensionless), | ||
CpuUsage: stats.Float64(pre+"cpu_usage", "Percentage of CPU in use.", stats.UnitDimensionless), | ||
GpuUsage: stats.Float64(pre+"gpu_usage", "Percentage of GPU in use.", stats.UnitDimensionless), | ||
RamUsage: stats.Float64(pre+"ram_usage", "Percentage of RAM in use.", stats.UnitDimensionless), | ||
PollerIterations: stats.Int64(pre+"poller_iterations", "Total number of poller iterations.", stats.UnitDimensionless), | ||
AddedTasks: stats.Int64(pre+"added_tasks", "Total number of tasks added.", stats.UnitDimensionless), | ||
} | ||
|
||
// TaskViews groups all harmonytask-related default views. | ||
func init() { | ||
err := view.Register( | ||
&view.View{ | ||
Measure: TaskMeasures.TasksStarted, | ||
Aggregation: view.Sum(), | ||
TagKeys: []tag.Key{taskNameTag, sourceTag}, | ||
}, | ||
&view.View{ | ||
Measure: TaskMeasures.TasksCompleted, | ||
Aggregation: view.Sum(), | ||
TagKeys: []tag.Key{taskNameTag}, | ||
}, | ||
&view.View{ | ||
Measure: TaskMeasures.TasksFailed, | ||
Aggregation: view.Sum(), | ||
TagKeys: []tag.Key{taskNameTag}, | ||
}, | ||
&view.View{ | ||
Measure: TaskMeasures.ActiveTasks, | ||
Aggregation: view.LastValue(), | ||
TagKeys: []tag.Key{taskNameTag}, | ||
}, | ||
&view.View{ | ||
Measure: TaskMeasures.CpuUsage, | ||
Aggregation: view.LastValue(), | ||
TagKeys: []tag.Key{}, | ||
}, | ||
&view.View{ | ||
Measure: TaskMeasures.GpuUsage, | ||
Aggregation: view.LastValue(), | ||
TagKeys: []tag.Key{}, | ||
}, | ||
&view.View{ | ||
Measure: TaskMeasures.RamUsage, | ||
Aggregation: view.LastValue(), | ||
TagKeys: []tag.Key{}, | ||
}, | ||
&view.View{ | ||
Measure: TaskMeasures.PollerIterations, | ||
Aggregation: view.Sum(), | ||
TagKeys: []tag.Key{}, | ||
}, | ||
&view.View{ | ||
Measure: TaskMeasures.AddedTasks, | ||
Aggregation: view.Sum(), | ||
TagKeys: []tag.Key{taskNameTag}, | ||
}, | ||
) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
err = promclient.Register(TaskMeasures.TaskDuration) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |
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,29 @@ | ||
package metrics | ||
|
||
import ( | ||
"net/http" | ||
|
||
"contrib.go.opencensus.io/exporter/prometheus" | ||
promclient "github.com/prometheus/client_golang/prometheus" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func Exporter() http.Handler { | ||
// Prometheus globals are exposed as interfaces, but the prometheus | ||
// OpenCensus exporter expects a concrete *Registry. The concrete type of | ||
// the globals are actually *Registry, so we downcast them, staying | ||
// defensive in case things change under the hood. | ||
registry, ok := promclient.DefaultRegisterer.(*promclient.Registry) | ||
if !ok { | ||
log.Warnf("failed to export default prometheus registry; some metrics will be unavailable; unexpected type: %T", promclient.DefaultRegisterer) | ||
} | ||
exporter, err := prometheus.NewExporter(prometheus.Options{ | ||
Registry: registry, | ||
Namespace: "curio", | ||
}) | ||
if err != nil { | ||
log.Errorf("could not create the prometheus stats exporter: %v", err) | ||
} | ||
|
||
return exporter | ||
} |
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