Skip to content

Commit

Permalink
Merge pull request #15 from metrumresearchgroup/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
shairozan authored Mar 27, 2020
2 parents 5a4c6ca + 8718509 commit e8d1d49
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 33 deletions.
4 changes: 0 additions & 4 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ steps:
image: golang
commands:
- go test ./... -covermode=count -coverprofile=coverage.out
when:
event:
exclude:
- pull_request

- name: Coverall Work
image: golang
Expand Down
25 changes: 14 additions & 11 deletions cmd/server/.goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,7 @@ nfpms:
id: gridengine_prometheus
# You can change the name of the package.
# Default: `{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}`
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"

# Replacements for GOOS and GOARCH in the package name.
# Keys should be valid GOOSs or GOARCHs.
# Values are the respective replacements.
# Default is empty.
replacements:
amd64: 64-bit
386: 32-bit
darwin: macOS
name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}"

# Your app's vendor.
# Default is empty.
Expand Down Expand Up @@ -74,4 +65,16 @@ nfpms:
# Keys are the possible targets during the installation process
# Values are the paths to the scripts which will be executed
scripts:
postinstall: "scripts/postinstall.sh"
postinstall: "scripts/postinstall.sh"
builds:
-
id: "default"
ldflags:
- -s -w -X 'github.com/metrumresearchgroup/gridengine_prometheus/cmd.Version={{ .Env.VERSION }}'

archives:
-
builds:
- default
name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}"
format: tar.gz
21 changes: 21 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cmd

import "github.com/spf13/cobra"

var Version string = "develop"

var versionCmd = &cobra.Command{
Use: "version",
Short: "Display binary version",
Long: "Display binary version",
Example: `gridengine_prometheus version`,
Run: version,
}

func version(cmd *cobra.Command, args []string) {
println(Version)
}

func init(){
RootCmd.AddCommand(versionCmd)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/metrumresearchgroup/gridengine_prometheus
go 1.13

require (
github.com/metrumresearchgroup/gogridengine v0.0.0-20191225174611-35c8b62cd3fe
github.com/metrumresearchgroup/gogridengine v0.0.1
github.com/prometheus/client_golang v1.2.1
github.com/sirupsen/logrus v1.4.2
github.com/spf13/cobra v0.0.5
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ github.com/metrumresearchgroup/gogridengine v0.0.0-20191218182527-bc69784db233 h
github.com/metrumresearchgroup/gogridengine v0.0.0-20191218182527-bc69784db233/go.mod h1:opfxgPaKkfTsV5EbwTkH3oUMAyJE7VL1twLdhEPXorg=
github.com/metrumresearchgroup/gogridengine v0.0.0-20191225174611-35c8b62cd3fe h1:Gl5qwfu5Q0ZSaLN5Z0EEIXVhVDzH0M+QudJhabyfJQ0=
github.com/metrumresearchgroup/gogridengine v0.0.0-20191225174611-35c8b62cd3fe/go.mod h1:opfxgPaKkfTsV5EbwTkH3oUMAyJE7VL1twLdhEPXorg=
github.com/metrumresearchgroup/gogridengine v0.0.1 h1:QG+ynp0mC7ydrZOsIIRYl87bwzfb2UEFfB5KbUgHuv4=
github.com/metrumresearchgroup/gogridengine v0.0.1/go.mod h1:opfxgPaKkfTsV5EbwTkH3oUMAyJE7VL1twLdhEPXorg=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
Expand Down
51 changes: 37 additions & 14 deletions grid.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,64 +26,86 @@ type GridEngine struct {
JobState *prometheus.Desc
JobPriority *prometheus.Desc
JobSlots *prometheus.Desc
JobErrors *prometheus.Desc
}

func NewGridEngine() *GridEngine {

hostLabels := []string{
"hostname",
"queue",
}

jobLabels := []string{
"hostname",
"queue",
"name",
"owner",
"job_number",
"task_id",
"state",
}

return &GridEngine{
TotalSlots: prometheus.NewDesc(
"total_slots_count",
"Total Number of slots available to the host",
[]string{"hostname", "queue"},
hostLabels,
nil),
UsedSlots: prometheus.NewDesc(
"used_slots_count",
"Number of used slots on host",
[]string{"hostname", "queue"},
hostLabels,
nil),
ReservedSlots: prometheus.NewDesc(
"reserved_slots_count",
"Number of reserved slots on host",
[]string{"hostname", "queue"},
hostLabels,
nil),
LoadAverage: prometheus.NewDesc(
"sge_load_average",
"Load average of this specific SGE host",
[]string{"hostname", "queue"},
hostLabels,
nil),
FreeMemory: prometheus.NewDesc(
"free_memory_bytes",
"Number of bytes in free memory",
[]string{"hostname", "queue"},
hostLabels,
nil),
UsedMemory: prometheus.NewDesc(
"sge_used_memory_bytes",
"Number of bytes in used memory",
[]string{"hostname", "queue"},
hostLabels,
nil),
TotalMemory: prometheus.NewDesc(
"sge_total_memory_bytes",
"Number of bytes in total memory",
[]string{"hostname", "queue"},
hostLabels,
nil),
CPUUtilization: prometheus.NewDesc(
"sge_cpu_utilization_percent",
"Decimal representing total CPU utilization on host",
[]string{"hostname", "queue"},
hostLabels,
nil),
JobState: prometheus.NewDesc(
"job_state_value",
"Indicates whether job is running (1) or not (0)",
[]string{"hostname", "queue", "name", "owner", "job_number", "task_id"},
jobLabels,
nil),
JobPriority: prometheus.NewDesc(
"job_priority_value",
"Qstat priority for given job",
[]string{"hostname", "queue", "name", "owner", "job_number", "task_id"},
jobLabels,
nil),
JobSlots: prometheus.NewDesc(
"job_slots_count",
"Number of slots on the selected job",
[]string{"hostname", "queue", "name", "owner", "job_number", "task_id"},
jobLabels,
nil),
JobErrors: prometheus.NewDesc(
"job_errors",
"Jobs that are reported in an errored or anomalous state",
jobLabels,
nil),
}
}
Expand Down Expand Up @@ -201,7 +223,8 @@ func processJob(j gogridengine.Job, ch chan<- prometheus.Metric, collector *Grid
number := strconv.FormatInt(j.JBJobNumber, 10)
taskID := strconv.Itoa(int(j.Tasks.TaskID))

ch <- prometheus.MustNewConstMetric(collector.JobState, prometheus.GaugeValue, float64(gogridengine.IsJobRunning(j)), hostname, queue, name, owner, number, taskID)
ch <- prometheus.MustNewConstMetric(collector.JobPriority, prometheus.GaugeValue, j.JATPriority, hostname, queue, name, owner, number, taskID)
ch <- prometheus.MustNewConstMetric(collector.JobSlots, prometheus.GaugeValue, float64(j.Slots), hostname, queue, name, owner, number, taskID)
ch <- prometheus.MustNewConstMetric(collector.JobState, prometheus.GaugeValue, float64(gogridengine.IsJobRunning(j)), hostname, queue, name, owner, number, taskID, j.State)
ch <- prometheus.MustNewConstMetric(collector.JobPriority, prometheus.GaugeValue, j.JATPriority, hostname, queue, name, owner, number, taskID, j.State)
ch <- prometheus.MustNewConstMetric(collector.JobSlots, prometheus.GaugeValue, float64(j.Slots), hostname, queue, name, owner, number, taskID, j.State)
ch <- prometheus.MustNewConstMetric(collector.JobErrors, prometheus.GaugeValue, float64(gogridengine.IsJobInErrorState(j)), hostname, queue, name, owner, number, taskID, j.State)
}
14 changes: 11 additions & 3 deletions grid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,22 @@ func Test_newGridEngine(t *testing.T) {
JobState: prometheus.NewDesc(
"job_state_value",
"Indicates whether job is running (1) or not (0)",
[]string{"hostname", "queue", "name", "owner", "job_number", "task_id"},
[]string{"hostname", "queue", "name", "owner", "job_number", "task_id", "state"},
nil),
JobPriority: prometheus.NewDesc(
"job_priority_value",
"Qstat priority for given job",
[]string{"hostname", "queue", "name", "owner", "job_number", "task_id"},
[]string{"hostname", "queue", "name", "owner", "job_number", "task_id", "state"},
nil),
JobSlots: prometheus.NewDesc(
"job_slots_count",
"Number of slots on the selected job",
[]string{"hostname", "queue", "name", "owner", "job_number", "task_id"},
[]string{"hostname", "queue", "name", "owner", "job_number", "task_id", "state"},
nil),
JobErrors: prometheus.NewDesc(
"job_errors",
"Jobs that are reported in an errored or anomalous state",
[]string{"hostname", "queue", "name", "owner", "job_number", "task_id", "state"},
nil),
},
},
Expand Down Expand Up @@ -175,6 +180,7 @@ func TestGridEngine_Collect(t *testing.T) {
JobState *prometheus.Desc
JobPriority *prometheus.Desc
JobSlots *prometheus.Desc
JobErrors *prometheus.Desc
}
type args struct {
ch chan<- prometheus.Metric
Expand All @@ -198,6 +204,7 @@ func TestGridEngine_Collect(t *testing.T) {
JobState: description.JobState,
JobPriority: description.JobPriority,
JobSlots: description.JobSlots,
JobErrors: description.JobErrors,
},
args: args{
ch: channel,
Expand All @@ -218,6 +225,7 @@ func TestGridEngine_Collect(t *testing.T) {
JobState: tt.fields.JobState,
JobPriority: tt.fields.JobPriority,
JobSlots: tt.fields.JobSlots,
JobErrors: tt.fields.JobErrors,
}
collector.Collect(tt.args.ch)
})
Expand Down

0 comments on commit e8d1d49

Please sign in to comment.