Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
gitlab-runner-do-monitor
Manage
Activity
Members
Labels
Plan
Issues
2
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Server Tools
gitlab-runner-do-monitor
Commits
b97386e9
Commit
b97386e9
authored
6 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
Doesn't need its own cron
parent
e1d56df9
No related branches found
No related tags found
1 merge request
!1
Initial release
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
config-sample.json
+0
-1
0 additions, 1 deletion
config-sample.json
glrdomon.go
+11
-23
11 additions, 23 deletions
glrdomon.go
with
11 additions
and
24 deletions
config-sample.json
+
0
−
1
View file @
b97386e9
...
@@ -2,6 +2,5 @@
...
@@ -2,6 +2,5 @@
"log-dest"
:
"os.Stdout"
,
"log-dest"
:
"os.Stdout"
,
"api-key"
:
""
,
"api-key"
:
""
,
"threshold"
:
3600
,
"threshold"
:
3600
,
"schedule"
:
"* */10 * * * *"
,
"delete-stale"
:
true
"delete-stale"
:
true
}
}
This diff is collapsed.
Click to expand it.
glrdomon.go
+
11
−
23
View file @
b97386e9
...
@@ -7,14 +7,12 @@ import (
...
@@ -7,14 +7,12 @@ import (
"io/ioutil"
"io/ioutil"
"log"
"log"
"os"
"os"
"os/signal"
"path/filepath"
"path/filepath"
"sy
scall
"
"sy
nc
"
"time"
"time"
"github.com/digitalocean/godo"
"github.com/digitalocean/godo"
"github.com/dustin/go-humanize"
"github.com/dustin/go-humanize"
"github.com/robfig/cron"
"golang.org/x/oauth2"
"golang.org/x/oauth2"
)
)
...
@@ -22,7 +20,6 @@ type config struct {
...
@@ -22,7 +20,6 @@ type config struct {
LogDest
string
`json:"log-dest"`
LogDest
string
`json:"log-dest"`
APIKey
string
`json:"api-key"`
APIKey
string
`json:"api-key"`
Threshold
int
`json:"threshold"`
Threshold
int
`json:"threshold"`
Schedule
string
`json:"schedule"`
DeleteStale
bool
`json:"delete-stale"`
DeleteStale
bool
`json:"delete-stale"`
}
}
...
@@ -39,9 +36,10 @@ var (
...
@@ -39,9 +36,10 @@ var (
apiKey
string
apiKey
string
threshold
int
threshold
int
schedule
string
deleteStale
bool
deleteStale
bool
wg
sync
.
WaitGroup
client
*
godo
.
Client
client
*
godo
.
Client
)
)
...
@@ -65,34 +63,27 @@ func init() {
...
@@ -65,34 +63,27 @@ func init() {
}
}
logDest
=
cfg
.
LogDest
logDest
=
cfg
.
LogDest
apiKey
=
cfg
.
APIKey
apiKey
=
cfg
.
APIKey
threshold
=
cfg
.
Threshold
threshold
=
cfg
.
Threshold
schedule
=
cfg
.
Schedule
deleteStale
=
cfg
.
DeleteStale
deleteStale
=
cfg
.
DeleteStale
setUpLogger
()
setUpLogger
()
}
func
main
()
{
logger
.
Printf
(
"Starting GitLab Runner monitoring with config %s"
,
configPath
)
logger
.
Printf
(
"Starting GitLab Runner monitoring with config %s"
,
configPath
)
sig
:=
make
(
chan
os
.
Signal
,
1
)
signal
.
Notify
(
sig
,
syscall
.
SIGINT
,
syscall
.
SIGTERM
)
if
deleteStale
{
if
deleteStale
{
logger
.
Println
(
"Stale droplets WILL BE DELETED automatically"
)
logger
.
Println
(
"Stale droplets WILL BE DELETED automatically"
)
}
else
{
}
else
{
logger
.
Println
(
"Stale droplets will be logged, but not deleted"
)
logger
.
Println
(
"Stale droplets will be logged, but not deleted"
)
}
}
}
func
main
()
{
authenticate
()
authenticate
()
startCron
()
checkAPI
()
caughtSig
:=
<-
sig
logger
.
Printf
(
"Stopping, got signal %s"
,
caughtSig
)
wg
.
Wait
()
logger
.
Println
(
"Execution complete!"
)
}
}
func
authenticate
()
{
func
authenticate
()
{
...
@@ -113,12 +104,6 @@ func (t *tokenSource) Token() (*oauth2.Token, error) {
...
@@ -113,12 +104,6 @@ func (t *tokenSource) Token() (*oauth2.Token, error) {
return
token
,
nil
return
token
,
nil
}
}
func
startCron
()
{
c
:=
cron
.
New
()
c
.
AddFunc
(
schedule
,
checkAPI
)
c
.
Start
()
}
func
checkAPI
()
{
func
checkAPI
()
{
ctx
:=
context
.
TODO
()
ctx
:=
context
.
TODO
()
droplets
,
err
:=
listDroplets
(
ctx
,
client
)
droplets
,
err
:=
listDroplets
(
ctx
,
client
)
...
@@ -129,6 +114,7 @@ func checkAPI() {
...
@@ -129,6 +114,7 @@ func checkAPI() {
}
}
for
_
,
droplet
:=
range
droplets
{
for
_
,
droplet
:=
range
droplets
{
wg
.
Add
(
1
)
go
checkDropletAge
(
droplet
)
go
checkDropletAge
(
droplet
)
}
}
}
}
...
@@ -163,6 +149,8 @@ func listDroplets(ctx context.Context, client *godo.Client) ([]godo.Droplet, err
...
@@ -163,6 +149,8 @@ func listDroplets(ctx context.Context, client *godo.Client) ([]godo.Droplet, err
}
}
func
checkDropletAge
(
droplet
godo
.
Droplet
)
{
func
checkDropletAge
(
droplet
godo
.
Droplet
)
{
defer
wg
.
Done
()
thr
:=
time
.
Now
()
.
Add
(
time
.
Duration
(
-
threshold
))
thr
:=
time
.
Now
()
.
Add
(
time
.
Duration
(
-
threshold
))
created
,
err
:=
time
.
Parse
(
time
.
RFC3339
,
droplet
.
Created
)
created
,
err
:=
time
.
Parse
(
time
.
RFC3339
,
droplet
.
Created
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment