Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
G
gitlab-runner-do-monitor
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
2
Issues
2
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Server Tools
gitlab-runner-do-monitor
Commits
9b68510e
Commit
9b68510e
authored
Aug 19, 2018
by
Erick Hitter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Basic config and logging
parent
1ee0492c
Pipeline
#171
failed with stages
in 11 minutes and 24 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
130 additions
and
0 deletions
+130
-0
config-sample.json
config-sample.json
+6
-0
glrdomon.go
glrdomon.go
+108
-0
glrdomon_test.go
glrdomon_test.go
+16
-0
No files found.
config-sample.json
0 → 100644
View file @
9b68510e
{
"debug-dest"
:
"os.Stdout"
,
"debug"
:
false
,
"api-key"
:
""
,
"threshold"
:
3600
}
glrdomon.go
View file @
9b68510e
package
main
import
(
"encoding/json"
"flag"
"io/ioutil"
"log"
"os"
"os/signal"
"path/filepath"
"syscall"
)
type
config
struct
{
DebugDest
string
`json:"debug-dest"`
Debug
bool
`json:"debug"`
ApiKey
string
`json:"api-key"`
Threshold
int
`json:"threshold"`
}
var
(
configPath
string
logger
*
log
.
Logger
debugDest
string
debug
bool
)
func
init
()
{
flag
.
StringVar
(
&
configPath
,
"config"
,
"./config.json"
,
"Path to configuration file"
)
flag
.
Parse
()
cfgPathValid
:=
validatePath
(
&
configPath
)
if
!
cfgPathValid
{
usage
()
}
configFile
,
err
:=
ioutil
.
ReadFile
(
configPath
)
if
err
!=
nil
{
usage
()
}
cfg
:=
config
{}
if
err
=
json
.
Unmarshal
(
configFile
,
&
cfg
);
err
!=
nil
{
usage
()
}
debugDest
=
cfg
.
DebugDest
debug
=
cfg
.
Debug
setUpLogger
()
}
func
main
()
{
logger
.
Printf
(
"Starting GitLab Runner monitoring with config %s"
,
configPath
)
sig
:=
make
(
chan
os
.
Signal
,
1
)
signal
.
Notify
(
sig
,
syscall
.
SIGINT
,
syscall
.
SIGTERM
)
// TODO: something!
if
debug
{
logger
.
Println
(
"Test"
)
}
caughtSig
:=
<-
sig
logger
.
Printf
(
"Stopping, got signal %s"
,
caughtSig
)
}
func
setUpLogger
()
{
logOpts
:=
log
.
Ldate
|
log
.
Ltime
|
log
.
LUTC
|
log
.
Lshortfile
if
debugDest
==
"os.Stdout"
{
logger
=
log
.
New
(
os
.
Stdout
,
"DEBUG: "
,
logOpts
)
}
else
{
path
,
err
:=
filepath
.
Abs
(
debugDest
)
if
err
!=
nil
{
logger
.
Fatal
(
err
)
}
logFile
,
err
:=
os
.
OpenFile
(
path
,
os
.
O_WRONLY
|
os
.
O_CREATE
|
os
.
O_APPEND
,
0644
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
logger
=
log
.
New
(
logFile
,
""
,
logOpts
)
}
}
func
validatePath
(
path
*
string
)
bool
{
if
len
(
*
path
)
<=
1
{
return
false
}
var
err
error
*
path
,
err
=
filepath
.
Abs
(
*
path
)
if
err
!=
nil
{
logger
.
Printf
(
"Error: %s"
,
err
.
Error
())
return
false
}
if
_
,
err
=
os
.
Stat
(
*
path
);
os
.
IsNotExist
(
err
)
{
return
false
}
return
true
}
func
usage
()
{
flag
.
Usage
()
os
.
Exit
(
3
)
}
glrdomon_test.go
View file @
9b68510e
package
main
import
"testing"
func
TestValidatePath
(
t
*
testing
.
T
)
{
emptyString
:=
""
notValid
:=
validatePath
(
&
emptyString
)
if
notValid
==
true
{
t
.
Error
(
"Empty path shouldn't validate"
)
}
sampleConfig
:=
"./config-sample.json"
valid
:=
validatePath
(
&
sampleConfig
)
if
valid
!=
true
{
t
.
Error
(
"Couldn't validate path to sample config"
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment