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
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
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
c95027bc
There was an error fetching the commit references. Please try again later.
Commit
c95027bc
authored
6 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
Parse and log stale droplets
parent
58a1bbae
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
+2
-1
2 additions, 1 deletion
config-sample.json
glrdomon.go
+39
-10
39 additions, 10 deletions
glrdomon.go
with
41 additions
and
11 deletions
config-sample.json
+
2
−
1
View file @
c95027bc
...
@@ -3,5 +3,6 @@
...
@@ -3,5 +3,6 @@
"debug"
:
false
,
"debug"
:
false
,
"api-key"
:
""
,
"api-key"
:
""
,
"threshold"
:
3600
,
"threshold"
:
3600
,
"schedule"
:
"* */10 * * * *"
"schedule"
:
"* */10 * * * *"
,
"delete-stale"
:
true
}
}
This diff is collapsed.
Click to expand it.
glrdomon.go
+
39
−
10
View file @
c95027bc
...
@@ -10,18 +10,21 @@ import (
...
@@ -10,18 +10,21 @@ import (
"os/signal"
"os/signal"
"path/filepath"
"path/filepath"
"syscall"
"syscall"
"time"
"github.com/digitalocean/godo"
"github.com/digitalocean/godo"
"github.com/dustin/go-humanize"
"github.com/robfig/cron"
"github.com/robfig/cron"
"golang.org/x/oauth2"
"golang.org/x/oauth2"
)
)
type
config
struct
{
type
config
struct
{
DebugDest
string
`json:"debug-dest"`
DebugDest
string
`json:"debug-dest"`
Debug
bool
`json:"debug"`
Debug
bool
`json:"debug"`
APIKey
string
`json:"api-key"`
APIKey
string
`json:"api-key"`
Threshold
int
`json:"threshold"`
Threshold
int
`json:"threshold"`
Schedule
string
`json:"schedule"`
Schedule
string
`json:"schedule"`
DeleteStale
bool
`json:"delete-stale"`
}
}
type
tokenSource
struct
{
type
tokenSource
struct
{
...
@@ -37,8 +40,9 @@ var (
...
@@ -37,8 +40,9 @@ var (
apiKey
string
apiKey
string
threshold
int
threshold
int
schedule
string
schedule
string
deleteStale
bool
client
*
godo
.
Client
client
*
godo
.
Client
)
)
...
@@ -69,6 +73,7 @@ func init() {
...
@@ -69,6 +73,7 @@ func init() {
threshold
=
cfg
.
Threshold
threshold
=
cfg
.
Threshold
schedule
=
cfg
.
Schedule
schedule
=
cfg
.
Schedule
deleteStale
=
cfg
.
DeleteStale
setUpLogger
()
setUpLogger
()
}
}
...
@@ -79,8 +84,10 @@ func main() {
...
@@ -79,8 +84,10 @@ func main() {
sig
:=
make
(
chan
os
.
Signal
,
1
)
sig
:=
make
(
chan
os
.
Signal
,
1
)
signal
.
Notify
(
sig
,
syscall
.
SIGINT
,
syscall
.
SIGTERM
)
signal
.
Notify
(
sig
,
syscall
.
SIGINT
,
syscall
.
SIGTERM
)
if
debug
{
if
deleteStale
{
logger
.
Println
(
"Test"
)
logger
.
Println
(
"Stale droplets WILL BE DELETED automatically"
)
}
else
{
logger
.
Println
(
"Stale droplets will be logged, but not deleted"
)
}
}
authenticate
()
authenticate
()
...
@@ -119,7 +126,9 @@ func checkAPI() {
...
@@ -119,7 +126,9 @@ func checkAPI() {
ctx
:=
context
.
TODO
()
ctx
:=
context
.
TODO
()
droplets
,
err
:=
listDroplets
(
ctx
,
client
)
droplets
,
err
:=
listDroplets
(
ctx
,
client
)
if
err
!=
nil
{
if
err
!=
nil
{
logger
.
Fatal
(
"Failed to retrieve droplet list"
)
logger
.
Println
(
"Warning! Failed to retrieve droplet list."
)
logger
.
Print
(
err
)
return
}
}
for
_
,
droplet
:=
range
droplets
{
for
_
,
droplet
:=
range
droplets
{
...
@@ -159,6 +168,26 @@ func listDroplets(ctx context.Context, client *godo.Client) ([]godo.Droplet, err
...
@@ -159,6 +168,26 @@ func listDroplets(ctx context.Context, client *godo.Client) ([]godo.Droplet, err
func
checkDropletAge
(
droplet
godo
.
Droplet
)
{
func
checkDropletAge
(
droplet
godo
.
Droplet
)
{
logger
.
Print
(
droplet
.
ID
)
logger
.
Print
(
droplet
.
ID
)
logger
.
Print
(
droplet
.
Created
)
logger
.
Print
(
droplet
.
Created
)
thr
:=
time
.
Now
()
.
Add
(
time
.
Duration
(
threshold
))
created
,
err
:=
time
.
Parse
(
time
.
RFC3339
,
droplet
.
Created
)
if
err
!=
nil
{
logger
.
Printf
(
"Could not parse created-timestamp for droplet ID %d"
,
droplet
.
ID
)
return
}
if
thr
.
After
(
created
)
{
logger
.
Printf
(
"Stale droplet => ID: %d; name:
\"
%s
\"
; created: %s, %s (%d)"
,
droplet
.
ID
,
droplet
.
Name
,
humanize
.
Time
(
created
),
droplet
.
Created
,
created
.
Unix
())
if
deleteStale
{
deleteDroplet
(
droplet
)
}
}
}
func
deleteDroplet
(
droplet
godo
.
Droplet
)
bool
{
logger
.
Printf
(
"Deleting droplet %d"
,
droplet
.
ID
)
return
false
}
}
func
setUpLogger
()
{
func
setUpLogger
()
{
...
...
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