Skip to content

Commit

Permalink
appdynamics update (#543)
Browse files Browse the repository at this point in the history
* add labels for appdynamics

* delete fixed labels for appdynamics

* update configure for appdynamics
  • Loading branch information
kongfei605 committed Jun 16, 2023
1 parent e9afd12 commit 7fdef35
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
4 changes: 4 additions & 0 deletions conf/input.appdynamics/app.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#url_vars = [
# { ip="127.0.0.1", port="8090", application="cms", metric_path="Application Infrastructure Performance|AdminServer|Individual Nodes|xxxxx|Agent|App|Availability", start_time="$START_TIME", end_time="$END_TIME"},
#]

# # 指定url_vars中哪些key 作为最终的label附加
# url_var_label_keys= []

# #从url中提取变量
# url_label_key="instance"
# url_label_value="{{.Host}}"
Expand Down
43 changes: 22 additions & 21 deletions inputs/appdynamics/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ type (
config.InstanceConfig

config.HTTPProxy
URLBase string `toml:"url_base"`
URLVars []map[string]string `toml:"url_vars"`
URLBase string `toml:"url_base"`
URLVars []map[string]string `toml:"url_vars"`
URLVarKey []string `toml:"url_var_label_keys"`

URLs []string `toml:"-"`
Headers map[string]string `toml:"headers"`
Expand Down Expand Up @@ -73,6 +74,8 @@ type (
)

var _ inputs.SampleGatherer = new(Instance)
var replacer = strings.NewReplacer(":", "_", "{", "_", "}", "_", "[", "_", "]", "_", "|", "_", "(", "_", ")",
"_", " ", "_", "%", "_", "/", "_per_")

func (ins *Instance) Drop() {
}
Expand Down Expand Up @@ -199,17 +202,28 @@ func (ins *Instance) Gather(slist *types.SampleList) {
}

wg := new(sync.WaitGroup)
for _, target := range ins.URLs {
for idx, target := range ins.URLs {
wg.Add(1)
go func(target string) {
go func(idx int, target string) {
defer wg.Done()
ins.gather(slist, target)
}(target)
labels := map[string]string{}
for k, v := range ins.URLVars[idx] {
if len(ins.URLVarKey) == 0 {
labels[k] = v
}
for _, key := range ins.URLVarKey {
if k == key {
labels[k] = v
}
}
}
ins.gather(slist, target, labels)
}(idx, target)
}
wg.Wait()
}

func (ins *Instance) gather(slist *types.SampleList, link string) {
func (ins *Instance) gather(slist *types.SampleList, link string, labels map[string]string) {
now := time.Now()
end := now.Add(-1 * time.Duration(ins.Delay))
start := end.Add(-1 * time.Duration(ins.Period))
Expand Down Expand Up @@ -237,7 +251,6 @@ func (ins *Instance) gather(slist *types.SampleList, link string) {
}

ins.setHeaders(req)
labels := map[string]string{}

if ins.LabelValue != "" {
urlKey, urlVal, err := ins.GenerateLabel(u)
Expand Down Expand Up @@ -283,21 +296,9 @@ func (ins *Instance) gather(slist *types.SampleList, link string) {
name = names[len(names)-1]
}

name = strings.ReplaceAll(name, ":", "_")
name = strings.ReplaceAll(name, "{", "_")
name = strings.ReplaceAll(name, "}", "_")
name = strings.ReplaceAll(name, "[", "_")
name = strings.ReplaceAll(name, "]", "_")
name = strings.ReplaceAll(name, "|", "_")
name = strings.ReplaceAll(name, "(", "_")
name = strings.ReplaceAll(name, ")", "_")
name = strings.ReplaceAll(name, " ", "_")
name = strings.ReplaceAll(name, "%", "_")
name = strings.ReplaceAll(name, "/", "_per_")
name = stringx.SnakeCase(name)
name = stringx.SnakeCase(replacer.Replace(name))

labels["metric_id"] = fmt.Sprintf("%v", metric.ID)
labels["metric_path"] = metric.Path
for _, val := range metric.Values {
sec := val.Timestamp / 1000
nsec := (val.Timestamp - sec*1000) * 1e6
Expand Down
7 changes: 1 addition & 6 deletions inputs/nsq/nsq.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,8 @@ func (ins *Instance) createHTTPClient() (*http.Client, error) {

dialer := &net.Dialer{}

proxy, err := ins.Proxy()
if err != nil {
return nil, err
}

client := httpx.CreateHTTPClient(httpx.TlsConfig(tlsCfg),
httpx.NetDialer(dialer), httpx.Proxy(proxy),
httpx.NetDialer(dialer), httpx.Proxy(httpx.GetProxyFunc(ins.HTTPProxyURL)),
httpx.Timeout(time.Duration(ins.Timeout)),
httpx.DisableKeepAlives(*ins.DisableKeepAlives),
httpx.FollowRedirects(*ins.FollowRedirects))
Expand Down

0 comments on commit 7fdef35

Please sign in to comment.