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"
"strings"
"sync"
)
type configManager struct {
config_manager.ConfigManager // interface implements
configs map[string] *config_manager.Config
configs map[string]*config_manager.Config
globalConfig config_manager.GlobalConfig
}
@ -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 + "/"
@ -157,7 +153,7 @@ func (c *configManager) removeConfig(id string) {
// check exists
config, ok := c.configs[removeid]
if !ok {
return;
return
}
// 해당 파일 삭제
@ -179,8 +175,6 @@ func (c *configManager) removeConfig(id string) {
//}
}
// 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")
@ -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" : {}
}
]
}