Skip to content

Commit 19b6ff2

Browse files
committed
merge with scouter-go-lib
1 parent a833f33 commit 19b6ff2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+3156
-55
lines changed

go.mod

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,4 @@ go 1.15
55
require (
66
github.com/emirpasic/gods v1.12.0
77
github.com/magiconair/properties v1.8.4
8-
github.com/scouter-project/scouter-go-lib v0.0.0
98
)
10-
11-
replace github.com/scouter-project/scouter-go-lib => /Users/gunlee/Documents/workspace/gunlee01/scouter-go-lib
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package netcafeconstant
2+
3+
var CAFE = []byte("CAFE")
4+
var CAFE_N = []byte("CAFN")
5+
var CAFE_MTU = []byte("CAFM")
6+
var JAVA = []byte("JAVA")
7+
var JAVA_N = []byte("JAVN")
8+
var JAVA_MTU = []byte("JAVM")
9+
var TCP_AGENT_V2 = 0xCAFE1002
10+
var TCP_AGENT = 0xCAFE1001
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package packconstants
2+
3+
// Pack type
4+
const (
5+
// M
6+
MAP byte = 10
7+
XLOG byte = 21
8+
DROPPED_XLOG byte = 22
9+
XLOG_PROFILE byte = 26
10+
XLOG_PROFILE2 byte = 27
11+
TEXT byte = 50
12+
PERFCOUNTER byte = 60
13+
PERF_STATUS byte = 61
14+
PERFCOUNTER_K8S byte = 65
15+
K8S_CLUSTER__INFO byte = 66
16+
ALERT byte = 70
17+
OBJECT byte = 80
18+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package tcpflag
2+
3+
const OK byte = 0x01
4+
const NOT_OK byte = 0x02
5+
6+
const HasNEXT byte = 0x03
7+
const NoNEXT byte = 0x04
8+
9+
const FAIL byte = 0x05
10+
const INVALID_SESSION byte = 0x44
11+
12+
const CLUSTER_SEND_NEXT byte = 0x03
13+
const CLUSTER_SEND_STOP byte = 0x04
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package timeconstants
2+
3+
const (
4+
REALTIME int8 = 1
5+
ONE_MIN int8 = 2
6+
FIVE_MIN int8 = 3
7+
TEN_MIN int8 = 4
8+
HOUR int8 = 5
9+
DAY int8 = 6
10+
SNAPSHOT int8 = 7
11+
)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package valueconstants
2+
3+
const (
4+
NULL byte = 0
5+
BOOLEAN byte = 10
6+
DECIMAL byte = 20
7+
FLOAT byte = 30
8+
DOUBLE byte = 40
9+
DOUBLE_SUMMARY byte = 45
10+
LONG_SUMMARY byte = 46
11+
TEXT byte = 50
12+
TEXT_HASH byte = 51
13+
BLOB byte = 60
14+
IP4ADDR byte = 61
15+
LIST byte = 70
16+
ARRAY_INT byte = 71
17+
ARRAY_FLOAT byte = 72
18+
ARRAY_TEXT byte = 73
19+
ARRAY_LONG byte = 74
20+
MAP byte = 80
21+
)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package channelfactory
2+
3+
import (
4+
"github.com/scouter-contrib/scouter-agent-golang/scouterx/conf"
5+
"sync"
6+
)
7+
8+
var once sync.Once
9+
var udpChannel chan []byte
10+
11+
//GetUDPChannel returns channel which stores pack data.
12+
func GetUDPChannel() chan []byte {
13+
once.Do(func() {
14+
udpChannel = make(chan []byte, conf.GetInstance().SendQueueSize)
15+
})
16+
return udpChannel
17+
}

scouterx/common/logger/logger.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package logger
2+
3+
import (
4+
"github.com/scouter-contrib/scouter-agent-golang/scouterx/common/util"
5+
"io"
6+
"log"
7+
"os"
8+
"path/filepath"
9+
)
10+
11+
//Init initializes logger
12+
func Init() {
13+
p := util.GetScouterPath()
14+
logPath := filepath.Join(p, "logs")
15+
util.MakeDir(logPath)
16+
fileName := filepath.Join(logPath, "scouter.log")
17+
logfile, e := os.OpenFile(fileName, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
18+
if e != nil {
19+
log.Fatalln("cannot open log file")
20+
}
21+
22+
Trace = log.New(io.MultiWriter(logfile, os.Stdout), "trace:", log.Ldate|log.Ltime|log.Lshortfile)
23+
Info = log.New(io.MultiWriter(logfile, os.Stdout), "info:", log.Ldate|log.Ltime|log.Lshortfile)
24+
Warning = log.New(io.MultiWriter(logfile, os.Stdout), "warning:", log.Ldate|log.Ltime|log.Lshortfile)
25+
Error = log.New(io.MultiWriter(logfile, os.Stderr), "error:", log.Ldate|log.Ltime|log.Lshortfile)
26+
}
27+
28+
// Error level
29+
var (
30+
Trace *log.Logger // trace log
31+
Info *log.Logger // info log
32+
Warning *log.Logger // warning log
33+
Error *log.Logger // error log
34+
)
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package netdata
2+
3+
import packconstants "github.com/scouter-contrib/scouter-agent-golang/scouterx/common/constants/packconstant"
4+
5+
type AlertLevel uint8
6+
7+
const AlertInfo AlertLevel = 0
8+
const AlertWarn AlertLevel = 1
9+
const AlertError AlertLevel = 2
10+
const AlertFatal AlertLevel = 3
11+
12+
// AlertPack has text info
13+
type AlertPack struct {
14+
Time int64
15+
ObjType string
16+
ObjHash int32
17+
Level AlertLevel
18+
Title string
19+
Message string
20+
Tags *MapValue
21+
}
22+
23+
func NewAlertPack() *AlertPack {
24+
pack := new(AlertPack)
25+
pack.Tags = NewMapValue()
26+
return pack
27+
}
28+
29+
func (p *AlertPack) Write(out *DataOutputX) error {
30+
_, err := out.WriteInt64(p.Time)
31+
_, err = out.WriteUInt8(uint8(p.Level))
32+
_, err = out.WriteString(p.ObjType)
33+
_, err = out.WriteInt32(p.ObjHash)
34+
_, err = out.WriteString(p.Title)
35+
_, err = out.WriteString(p.Message)
36+
_, err = out.WriteValue(p.Tags)
37+
38+
return err
39+
}
40+
41+
func (p *AlertPack) Read(in *DataInputX) (Pack, error) {
42+
//TODO not yet implemented
43+
return p, nil
44+
}
45+
46+
func (pack *AlertPack) ToString() string {
47+
var str string
48+
str += "AlertPack:"
49+
str += " title: " + pack.Title
50+
str += " message: " + pack.Message
51+
return str
52+
}
53+
54+
//GetPackType returns pack type
55+
func (pack *AlertPack) GetPackType() byte {
56+
return packconstants.ALERT
57+
}
58+
59+
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package netdata
2+
3+
import (
4+
valueconstants "github.com/scouter-contrib/scouter-agent-golang/scouterx/common/constants/valueconstant"
5+
)
6+
7+
//BooleanValue has bool value
8+
type BooleanValue struct {
9+
Value bool
10+
}
11+
12+
//NewBooleanValue return new BooleanVaue instance
13+
/*
14+
func NewBooleanValue(value bool) *BooleanValue {
15+
booleanValue := new(BooleanValue)
16+
booleanValue.Value = value
17+
return booleanValue
18+
19+
}
20+
*/
21+
22+
//NewBooleanValue return new BooleanVaue instance
23+
func NewBooleanValue(value bool) *BooleanValue {
24+
booleanValue := new(BooleanValue)
25+
booleanValue.Value = value
26+
return booleanValue
27+
28+
}
29+
30+
//NewBooleanEmptyValue return new BooleanVaue instance
31+
func NewBooleanEmptyValue() *BooleanValue {
32+
BooleanValue := new(BooleanValue)
33+
return BooleanValue
34+
}
35+
36+
//GetValueType returns value type
37+
func (booleanValue *BooleanValue) GetValueType() byte {
38+
return valueconstants.BOOLEAN
39+
}
40+
41+
func (booleanValue *BooleanValue) Read(in *DataInputX) (Value, error) {
42+
var err error
43+
booleanValue.Value, err = in.ReadBoolean()
44+
return booleanValue, err
45+
}
46+
47+
func (booleanValue *BooleanValue) Write(out *DataOutputX) error {
48+
_, err := out.WriteBoolean(booleanValue.Value)
49+
return err
50+
}
51+
52+
// ToString returns converted string value from boolean value
53+
func (booleanValue *BooleanValue) ToString() string {
54+
if booleanValue.Value {
55+
return "true"
56+
}
57+
return "fasle"
58+
}

0 commit comments

Comments
 (0)