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
da31dc35
Commit
da31dc35
authored
6 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
Successful API retrieval
parent
91935a4f
No related branches found
No related tags found
1 merge request
!1
Initial release
Pipeline
#172
failed
6 years ago
Stage: test
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
config-sample.json
+1
-1
1 addition, 1 deletion
config-sample.json
glrdomon.go
+74
-10
74 additions, 10 deletions
glrdomon.go
with
75 additions
and
11 deletions
config-sample.json
+
1
−
1
View file @
da31dc35
...
...
@@ -3,5 +3,5 @@
"debug"
:
false
,
"api-key"
:
""
,
"threshold"
:
3600
,
"schedule"
:
"
0
10 * * * *"
"schedule"
:
"
* */
10 * * * *"
}
This diff is collapsed.
Click to expand it.
glrdomon.go
+
74
−
10
View file @
da31dc35
package
main
import
(
"context"
"encoding/json"
"flag"
"io/ioutil"
...
...
@@ -10,7 +11,9 @@ import (
"path/filepath"
"syscall"
"github.com/digitalocean/godo"
"github.com/robfig/cron"
"golang.org/x/oauth2"
)
type
config
struct
{
...
...
@@ -21,6 +24,10 @@ type config struct {
Schedule
string
`json:"schedule"`
}
type
TokenSource
struct
{
AccessToken
string
}
var
(
configPath
string
...
...
@@ -28,8 +35,12 @@ var (
debugDest
string
debug
bool
apiKey
string
threshold
int
schedule
string
client
*
godo
.
Client
)
func
init
()
{
...
...
@@ -54,6 +65,8 @@ func init() {
debugDest
=
cfg
.
DebugDest
debug
=
cfg
.
Debug
apiKey
=
cfg
.
ApiKey
threshold
=
cfg
.
Threshold
schedule
=
cfg
.
Schedule
...
...
@@ -70,29 +83,80 @@ func main() {
logger
.
Println
(
"Test"
)
}
if
authenticate
()
{
startCron
()
}
else
{
sig
<-
syscall
.
SIGTERM
}
authenticate
()
startCron
()
caughtSig
:=
<-
sig
logger
.
Printf
(
"Stopping, got signal %s"
,
caughtSig
)
}
func
authenticate
()
bool
{
return
true
func
authenticate
()
{
tokenSource
:=
&
TokenSource
{
AccessToken
:
apiKey
,
}
oauthClient
:=
oauth2
.
NewClient
(
context
.
Background
(),
tokenSource
)
client
=
godo
.
NewClient
(
oauthClient
)
}
func
(
t
*
TokenSource
)
Token
()
(
*
oauth2
.
Token
,
error
)
{
token
:=
&
oauth2
.
Token
{
AccessToken
:
t
.
AccessToken
,
}
return
token
,
nil
}
func
startCron
()
{
c
:=
cron
.
New
()
c
.
AddFunc
(
schedule
,
check
)
c
.
AddFunc
(
schedule
,
check
Api
)
c
.
Start
()
}
func
check
()
{
logger
.
Println
(
"Check!"
)
func
checkApi
()
{
context
:=
context
.
TODO
()
droplets
,
err
:=
listDroplets
(
context
,
client
)
if
err
!=
nil
{
logger
.
Fatal
(
"Failed to retrieve droplet list"
)
}
for
_
,
droplet
:=
range
droplets
{
go
checkDropletAge
(
droplet
)
}
}
func
listDroplets
(
ctx
context
.
Context
,
client
*
godo
.
Client
)
([]
godo
.
Droplet
,
error
)
{
list
:=
[]
godo
.
Droplet
{}
opt
:=
&
godo
.
ListOptions
{}
for
{
droplets
,
resp
,
err
:=
client
.
Droplets
.
List
(
ctx
,
opt
)
if
err
!=
nil
{
return
nil
,
err
}
for
_
,
d
:=
range
droplets
{
list
=
append
(
list
,
d
)
}
if
resp
.
Links
==
nil
||
resp
.
Links
.
IsLastPage
()
{
break
}
page
,
err
:=
resp
.
Links
.
CurrentPage
()
if
err
!=
nil
{
return
nil
,
err
}
opt
.
Page
=
page
+
1
}
return
list
,
nil
}
func
checkDropletAge
(
droplet
godo
.
Droplet
)
{
logger
.
Print
(
droplet
.
ID
)
logger
.
Print
(
droplet
.
Created
)
}
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