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,12 +9,11 @@ import (
"os" "os"
"strings" "strings"
"sync" "sync"
) )
type configManager struct { type configManager struct {
config_manager.ConfigManager // interface implements config_manager.ConfigManager // interface implements
configs map[string] *config_manager.Config configs map[string]*config_manager.Config
globalConfig config_manager.GlobalConfig globalConfig config_manager.GlobalConfig
} }
@ -33,7 +32,6 @@ func GetInstance() *configManager {
func (c *configManager) stop() {} func (c *configManager) stop() {}
func (c *configManager) getConfigPath() string { func (c *configManager) getConfigPath() string {
return c.globalConfig.Paths.RootFolder + c.globalConfig.Paths.ConfigFolder 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 return c.getContainerPath() + appendSeperator(config.Crawler.Container) + appendSeperator(config.Crawler.Name) + config.Id
} }
func appendSeperator(str string) string { func appendSeperator(str string) string {
if strings.LastIndex(str, "/") != len(str)-1 { if strings.LastIndex(str, "/") != len(str)-1 {
return str + "/" return str + "/"
@ -157,7 +153,7 @@ func (c *configManager) removeConfig(id string) {
// check exists // check exists
config, ok := c.configs[removeid] config, ok := c.configs[removeid]
if !ok { if !ok {
return; return
} }
// 해당 파일 삭제 // 해당 파일 삭제
@ -179,8 +175,6 @@ func (c *configManager) removeConfig(id string) {
//} //}
} }
// implements methods // implements methods
func (c *configManager) GetGlobalConfig() *config_manager.GlobalConfig { func (c *configManager) GetGlobalConfig() *config_manager.GlobalConfig {
return &c.globalConfig return &c.globalConfig
@ -188,6 +182,6 @@ func (c *configManager) GetGlobalConfig() *config_manager.GlobalConfig {
func (c *configManager) GetSensorById(id string) *config_manager.Config { func (c *configManager) GetSensorById(id string) *config_manager.Config {
return c.configs[id] 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 return c.configs
} }

View File

@ -3,13 +3,13 @@ package config_manager_go
import ( import (
"testing" "testing"
//"github.com/stretchr/testify/assert" //"github.com/stretchr/testify/assert"
"io/ioutil"
"log"
"loafle.com/overflow/agent_api/config_manager"
"encoding/json" "encoding/json"
"github.com/google/uuid" "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/messages"
"loafle.com/overflow/agent_api/observer"
"log"
"time" "time"
) )
@ -35,7 +35,6 @@ func TestLoadConfig(t *testing.T) {
//time.Sleep(1 * time.Second) //time.Sleep(1 * time.Second)
} }
func TestAddConfig(t *testing.T) { func TestAddConfig(t *testing.T) {
_configManager.loadGlobalConfig("/root/gowork/src/loafle.com/overflow/config_manager_go/test_agent/global.yaml") _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) json.Unmarshal(b, &m)
// uuid로 원본 파일 복제 // uuid로 원본 파일 복제
rid,_ := uuid.NewRandom() rid, _ := uuid.NewRandom()
m.Id = rid.String() m.Id = rid.String()
b,err = json.Marshal(&m) b, err = json.Marshal(&m)
ioutil.WriteFile("/root/gowork/src/loafle.com/overflow/config_manager_go/test_agent/" + m.Id,b,0644) ioutil.WriteFile("/root/gowork/src/loafle.com/overflow/config_manager_go/test_agent/"+m.Id, b, 0644)
// add test // 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) time.Sleep(1 * time.Second)
} }
func TestRemoveConfig(t *testing.T) { func TestRemoveConfig(t *testing.T) {
GetInstance() GetInstance()
_configManager.loadGlobalConfig("/home/snoop/develop/path/go/src/loafle.com/overflow/config_manager_go/test_agent/global.yaml") _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 ( import (
"loafle.com/overflow/agent_api/config_manager" "loafle.com/overflow/agent_api/config_manager"
) )
//import ( //import (
@ -11,10 +10,6 @@ import (
//) //)
// //
func Start(ch chan *config_manager.GlobalConfig, path string) error { func Start(ch chan *config_manager.GlobalConfig, path string) error {
_configManager = GetInstance() _configManager = GetInstance()
_configManager.loadGlobalConfig(path + "/" + "global.yaml") _configManager.loadGlobalConfig(path + "/" + "global.yaml")
@ -35,7 +30,6 @@ func Stop(ch chan bool) {
ch <- true ch <- true
} }
func AddSensor(tmpFilePath string) { func AddSensor(tmpFilePath string) {
GetInstance().addConfig(tmpFilePath) GetInstance().addConfig(tmpFilePath)
@ -67,12 +61,10 @@ func RemoveSensor(id string) {
GetInstance().removeConfig(id) GetInstance().removeConfig(id)
} }
func UpdateSensor(tmpFile string) { func UpdateSensor(tmpFile string) {
//GetInstance(). //GetInstance().
//overwrite file //overwrite file
@ -82,14 +74,6 @@ func UpdateSensor(tmpFile string) {
} }
//func agentStartHandler() { //func agentStartHandler() {
// agentStart := make(chan interface{}, 0) // agentStart := make(chan interface{}, 0)
// observer.Add(messages.AGT_STARTING, agentStart) // observer.Add(messages.AGT_STARTING, agentStart)
@ -129,5 +113,3 @@ func UpdateSensor(tmpFile string) {
// observer.Add(messages.TASK_SENSOR_REMOVE,_configManager.removeCh) // observer.Add(messages.TASK_SENSOR_REMOVE,_configManager.removeCh)
// go _configManager.removeConfig() // go _configManager.removeConfig()
//} //}

View File

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

View File

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

View File

@ -2,19 +2,19 @@
"id" : "989238744", "id" : "989238744",
"target" : { "target" : {
"connection" : { "connection" : {
"ip" : "192.168.1.107", "ip" : "192.168.1.106",
"port" : "5432", "port" : "5432",
"ssl" : false, "ssl" : false,
"portType" : "tcp" "portType" : "tcp"
}, },
"auth" : { "auth" : {
"url":"jdbc:postgresql://192.168.1.107:5432/postgres", "url":"jdbc:postgresql://192.168.1.106:5432/postgres",
"id":"postgres", "id":"vertx",
"pw":"!@#$qwer1234" "pw":"qwe123"
} }
}, },
"schedule" : { "schedule" : {
"interval" : "10" "interval" : "3"
}, },
"crawler" : { "crawler" : {
"name":"SQL", "name":"SQL",
@ -24,13 +24,14 @@
{ {
"keys" : [ "keys" : [
{ {
"metric":"net.connection_count", "metric":"net.pgsql.connection_count",
"key" : "connection_count" "key" : "connection_count"
} }
], ],
"queryInfo":{ "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" : {}
} }
] ]
} }