-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Complete initial implementation of persistent WebSocket for both cont…
…ainer and response realtime data.
- Loading branch information
1 parent
f9b8b8f
commit 04b56ce
Showing
9 changed files
with
130 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package dockmon | ||
|
||
import ( | ||
"mime" | ||
"net" | ||
"net/http" | ||
) | ||
|
||
const messageTypeResponse = "response" | ||
|
||
type messageResponse struct { | ||
RemoteAddr string `json:"remote_addr"` | ||
CountryCode string `json:"country_code"` | ||
CountryName string `json:"country_name"` | ||
Method string `json:"method"` | ||
Host string `json:"host"` | ||
Path string `json:"path"` | ||
StatusCode int `json:"status_code"` | ||
Status string `json:"status"` | ||
ContentLength string `json:"content_length"` | ||
ContentType string `json:"content_type"` | ||
} | ||
|
||
func (d *Dockmon) responseCallback(resp *http.Response) { | ||
host, _, err := net.SplitHostPort(resp.Request.RemoteAddr) | ||
if err != nil { | ||
host = resp.Request.RemoteAddr | ||
} | ||
var ( | ||
countryCode string | ||
countryName string | ||
) | ||
r, err := d.logger.Geolocate(host) | ||
if err == nil { | ||
countryCode = r.CountryCode | ||
countryName = r.CountryName | ||
} | ||
contentType := resp.Header.Get("Content-Type") | ||
mediatype, _, err := mime.ParseMediaType(contentType) | ||
if err != nil { | ||
mediatype = contentType | ||
} | ||
d.logger.Log(messageTypeResponse, &messageResponse{ | ||
RemoteAddr: host, | ||
CountryCode: countryCode, | ||
CountryName: countryName, | ||
Method: resp.Request.Method, | ||
Host: resp.Request.Host, | ||
Path: resp.Request.URL.Path, | ||
StatusCode: resp.StatusCode, | ||
Status: resp.Status, | ||
ContentLength: resp.Header.Get("Content-Length"), | ||
ContentType: mediatype, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.