sql problem has solved

This commit is contained in:
insanity@loafle.com 2017-05-18 13:45:05 +09:00
parent ca5d24c9a0
commit 36751de2f7
7 changed files with 82 additions and 107 deletions

View File

@ -9,13 +9,12 @@ import (
"os"
"strings"
"sync"
)
type configManager struct {
config_manager.ConfigManager // interface implements
configs map[string] *config_manager.Config
globalConfig config_manager.GlobalConfig
configs map[string]*config_manager.Config
globalConfig config_manager.GlobalConfig
}
var _configManager *configManager
@ -33,7 +32,6 @@ func GetInstance() *configManager {
func (c *configManager) stop() {}
func (c *configManager) getConfigPath() string {
return c.globalConfig.Paths.RootFolder + c.globalConfig.Paths.ConfigFolder
}
@ -46,8 +44,6 @@ func (c *configManager) getConfigFilePath(config *config_manager.Config) string
return c.getContainerPath() + appendSeperator(config.Crawler.Container) + appendSeperator(config.Crawler.Name) + config.Id
}
func appendSeperator(str string) string {
if strings.LastIndex(str, "/") != len(str)-1 {
return str + "/"
@ -112,75 +108,73 @@ func (c *configManager) loadCrawlerConfig(root string, dir string) {
func (c *configManager) addConfig(tmp string) {
//for data := range c.addCh {
path := tmp
b, err := ioutil.ReadFile(path)
if err != nil {
// error process
log.Panic(err)
}
path := tmp
b, err := ioutil.ReadFile(path)
if err != nil {
// error process
log.Panic(err)
}
// 임시파일을 로드 , Config로 변환
var m = config_manager.Config{}
err = json.Unmarshal(b, &m)
if err != nil {
// error process
log.Panic(err)
}
// 임시파일을 로드 , Config로 변환
var m = config_manager.Config{}
err = json.Unmarshal(b, &m)
if err != nil {
// error process
log.Panic(err)
}
// agent 폴더 / config / crawler / .. / .. / .. / 에 해당하는 파일이 있는지 확인, 있다면 삭제
// Config 파일로 저장
savePath := c.getConfigFilePath(&m)
ioutil.WriteFile(savePath, b, 0644)
// agent 폴더 / config / crawler / .. / .. / .. / 에 해당하는 파일이 있는지 확인, 있다면 삭제
// Config 파일로 저장
savePath := c.getConfigFilePath(&m)
ioutil.WriteFile(savePath, b, 0644)
// tempfile remove
err = os.Remove(path)
if err != nil {
// error process
log.Panic(err)
}
// tempfile remove
err = os.Remove(path)
if err != nil {
// error process
log.Panic(err)
}
// Config 맵에 저장
c.configs[m.Id] = &m
// Config 맵에 저장
c.configs[m.Id] = &m
// notify id
//err = observer.Notify(messages.SCF_SENSOR_ADD_DONE, m.Id)
//if err != nil {
// continue
//}
// notify id
//err = observer.Notify(messages.SCF_SENSOR_ADD_DONE, m.Id)
//if err != nil {
// continue
//}
//}
}
func (c *configManager) removeConfig(id string) {
//for data := range c.removeCh {
removeid := id
removeid := id
// check exists
config, ok := c.configs[removeid]
if !ok {
return;
}
// check exists
config, ok := c.configs[removeid]
if !ok {
return
}
// 해당 파일 삭제
path := c.getConfigFilePath(config)
err := os.Remove(path)
if err != nil {
// error check
log.Panic(err)
}
// 해당 파일 삭제
path := c.getConfigFilePath(config)
err := os.Remove(path)
if err != nil {
// error check
log.Panic(err)
}
// 해당 id 삭제
delete(c.configs, removeid)
// 해당 id 삭제
delete(c.configs, removeid)
// notify id
//err = observer.Notify("TASK_DONE", removeid)
//if err != nil {
// continue
//}
// notify id
//err = observer.Notify("TASK_DONE", removeid)
//if err != nil {
// continue
//}
//}
}
// implements methods
func (c *configManager) GetGlobalConfig() *config_manager.GlobalConfig {
return &c.globalConfig
@ -188,6 +182,6 @@ func (c *configManager) GetGlobalConfig() *config_manager.GlobalConfig {
func (c *configManager) GetSensorById(id string) *config_manager.Config {
return c.configs[id]
}
func (c *configManager) GetSensors() map[string] *config_manager.Config {
func (c *configManager) GetSensors() map[string]*config_manager.Config {
return c.configs
}

View File

@ -3,13 +3,13 @@ package config_manager_go
import (
"testing"
//"github.com/stretchr/testify/assert"
"io/ioutil"
"log"
"loafle.com/overflow/agent_api/config_manager"
"encoding/json"
"github.com/google/uuid"
"loafle.com/overflow/agent_api/observer"
"io/ioutil"
"loafle.com/overflow/agent_api/config_manager"
"loafle.com/overflow/agent_api/messages"
"loafle.com/overflow/agent_api/observer"
"log"
"time"
)
@ -35,7 +35,6 @@ func TestLoadConfig(t *testing.T) {
//time.Sleep(1 * time.Second)
}
func TestAddConfig(t *testing.T) {
_configManager.loadGlobalConfig("/root/gowork/src/loafle.com/overflow/config_manager_go/test_agent/global.yaml")
@ -48,17 +47,16 @@ func TestAddConfig(t *testing.T) {
json.Unmarshal(b, &m)
// uuid로 원본 파일 복제
rid,_ := uuid.NewRandom()
rid, _ := uuid.NewRandom()
m.Id = rid.String()
b,err = json.Marshal(&m)
ioutil.WriteFile("/root/gowork/src/loafle.com/overflow/config_manager_go/test_agent/" + m.Id,b,0644)
b, err = json.Marshal(&m)
ioutil.WriteFile("/root/gowork/src/loafle.com/overflow/config_manager_go/test_agent/"+m.Id, b, 0644)
// add test
observer.Notify(messages.TASK_SENSOR_ADD,"/root/gowork/src/loafle.com/overflow/config_manager_go/test_agent/" + m.Id)
observer.Notify(messages.TASK_SENSOR_ADD, "/root/gowork/src/loafle.com/overflow/config_manager_go/test_agent/"+m.Id)
time.Sleep(1 * time.Second)
}
func TestRemoveConfig(t *testing.T) {
GetInstance()
_configManager.loadGlobalConfig("/home/snoop/develop/path/go/src/loafle.com/overflow/config_manager_go/test_agent/global.yaml")

View File

@ -2,7 +2,6 @@ package config_manager_go
import (
"loafle.com/overflow/agent_api/config_manager"
)
//import (
@ -11,10 +10,6 @@ import (
//)
//
func Start(ch chan *config_manager.GlobalConfig, path string) error {
_configManager = GetInstance()
_configManager.loadGlobalConfig(path + "/" + "global.yaml")
@ -24,7 +19,7 @@ func Start(ch chan *config_manager.GlobalConfig, path string) error {
func StartSensorConfig(ch chan config_manager.ConfigManager, authKey string) error {
if err := _configManager.loadCrawlerConfigAll(); err != nil {
return err
return err
}
ch <- _configManager
return nil
@ -35,7 +30,6 @@ func Stop(ch chan bool) {
ch <- true
}
func AddSensor(tmpFilePath string) {
GetInstance().addConfig(tmpFilePath)
@ -67,12 +61,10 @@ func RemoveSensor(id string) {
GetInstance().removeConfig(id)
}
func UpdateSensor(tmpFile string) {
//GetInstance().
//overwrite file
@ -82,14 +74,6 @@ func UpdateSensor(tmpFile string) {
}
//func agentStartHandler() {
// agentStart := make(chan interface{}, 0)
// observer.Add(messages.AGT_STARTING, agentStart)
@ -129,5 +113,3 @@ func UpdateSensor(tmpFile string) {
// observer.Add(messages.TASK_SENSOR_REMOVE,_configManager.removeCh)
// go _configManager.removeConfig()
//}

View File

@ -24,13 +24,13 @@
{
"keys" : [
{
"metric":"net.connection_count",
"metric":"net.mysql.connection_count",
"key":"Connections"
}
],
"queryInfo" : {
"query":"show status where `variable_name` = 'Connections'"
"query":"show status where variable_name = 'Connections'"
},
"mappingInfo" : {
"parseDirection" : "row",

View File

@ -14,7 +14,7 @@
}
},
"schedule" : {
"interval" : "5"
"interval" : "10"
},
"crawler" : {
"name":"SQL",
@ -24,8 +24,8 @@
{
"keys" : [
{
"metric" :"net.connection_count",
"key" : "Connections"
"metric" :"net.sqlserver.connection_count",
"key" : "connection_count"
}
],
"queryInfo" : {

View File

@ -2,19 +2,19 @@
"id" : "989238744",
"target" : {
"connection" : {
"ip" : "192.168.1.107",
"ip" : "192.168.1.106",
"port" : "5432",
"ssl" : false,
"portType" : "tcp"
},
"auth" : {
"url":"jdbc:postgresql://192.168.1.107:5432/postgres",
"id":"postgres",
"pw":"!@#$qwer1234"
"url":"jdbc:postgresql://192.168.1.106:5432/postgres",
"id":"vertx",
"pw":"qwe123"
}
},
"schedule" : {
"interval" : "10"
"interval" : "3"
},
"crawler" : {
"name":"SQL",
@ -24,13 +24,14 @@
{
"keys" : [
{
"metric":"net.connection_count",
"metric":"net.pgsql.connection_count",
"key" : "connection_count"
}
],
"queryInfo":{
"query" : "select count(pid) as connection_count from pg_catalog.pg_stat_activity where state <> 'idle'"
}
"query" : "select count(pid) as connection_count from pg_catalog.pg_stat_activity where state <> 'idle';"
},
"mappingInfo" : {}
}
]
}