Skip to content

Commit

Permalink
1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
freedomkk-qfeng committed Sep 26, 2017
1 parent 514e837 commit 13c09ae
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 12 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Windows Metrics
|tcpip.conestablished |GAUGE|/|tcp connect established |
|tcpip.conreset |COUNTER|/|tcp connect reset|
|net.port.listen |GAUGE|port=port|port alive|
|proc.num |GAUGE|cmdline=proccmdline,name=procname|proc/cmdline number|
|proc.num |GAUGE|cmdline=cmdline,proc=proc|proc number|


IIs Metrics
Expand Down Expand Up @@ -198,6 +198,8 @@ go get ./...
go build -o windows-agent.exe
```
#### Release 版本
可以从这里直接下载编译好的 [Release 版本](https://github.com/freedomkk-qfeng/windows-agent/releases)

#### 运行
以下命令需在管理员模式下运行开 cmd 或 Powershell
Expand All @@ -207,6 +209,7 @@ go build -o windows-agent.exe
.\windows-agent.exe
2016/08/08 13:44:31 cfg.go:96: read config file: cfg.json successfully
2016/08/08 13:44:31 var.go:31: logging on windows.log
2016/08/08 13:44:31 http.go:64: listening :1988
```
等待1-2分钟,观察输出,确认运行正常
使用 [nssm](https://nssm.cc/) 注册为 Windows 服务。
Expand Down
6 changes: 4 additions & 2 deletions funcs/func_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ func Test_net_status(t *testing.T) {
}

func Test_IsTCPPortUsed(t *testing.T) {
res := IsTCPPortUsed(80)
t.Log(res)
res := IsTCPPortV4Used(135)
t.Log("V4:", res)
res = IsTCPPortV6Used(135)
t.Log("v6:", res)
}

func Test_TestIOCounters(t *testing.T) {
Expand Down
25 changes: 20 additions & 5 deletions funcs/portstat.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package funcs

import (
"fmt"

"log"
"net"
"strconv"

"github.com/freedomkk-qfeng/windows-agent/g"
"github.com/open-falcon/common/model"
Expand All @@ -14,13 +15,27 @@ const (
maxTCPPort = 65535
)

func IsTCPPortUsed(port int64) bool {
func IsTCPPortV4Used(port int64) bool {
if port < minTCPPort || port > maxTCPPort {
return false
}
connString := "127.0.0.1:" + strconv.FormatInt(port, 10)
conn, err := net.Listen("tcp", connString)
log.Println(connString, conn, err)
if err != nil {
return true
}
conn.Close()
return false
}

conn, err := net.Listen("tcp", ":"+string(port))

func IsTCPPortV6Used(port int64) bool {
if port < minTCPPort || port > maxTCPPort {
return false
}
connString := "[::1]:" + strconv.FormatInt(port, 10)
conn, err := net.Listen("tcp", connString)
log.Println(connString, conn, err)
if err != nil {
return true
}
Expand All @@ -37,7 +52,7 @@ func PortMetrics() (L []*model.MetricValue) {

for i := 0; i < sz; i++ {
tags := fmt.Sprintf("port=%d", reportPorts[i])
if IsTCPPortUsed(reportPorts[i]) {
if IsTCPPortV4Used(reportPorts[i]) || IsTCPPortV6Used(reportPorts[i]) {
L = append(L, GaugeValue(g.NET_PORT_LISTEN, 1, tags))
} else {
L = append(L, GaugeValue(g.NET_PORT_LISTEN, 0, tags))
Expand Down
3 changes: 2 additions & 1 deletion g/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
// changelog:
// 1.0.0 windows-agent
// 1.0.1 ifstat use ifname instead ifdescription
// 1.0.2 fix net.listen.port bug
const (
VERSION = "1.0.1"
VERSION = "1.0.2"
COLLECT_INTERVAL = time.Second
NET_PORT_LISTEN = "net.port.listen"
DU_BS = "du.bs"
Expand Down
5 changes: 2 additions & 3 deletions http/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ func configAdminRoutes() {
http.HandleFunc("/workdir", func(w http.ResponseWriter, r *http.Request) {
RenderDataJson(w, file.SelfDir())
})

http.HandleFunc("/ips", func(w http.ResponseWriter, r *http.Request) {
RenderDataJson(w, g.TrustableIps())
http.HandleFunc("/config", func(w http.ResponseWriter, r *http.Request) {
RenderDataJson(w, g.Config())
})
}

0 comments on commit 13c09ae

Please sign in to comment.