{"action":"created","comment":{"url":"https://api.github.com/repos/prometheus/node_exporter/pulls/comments/38914295","id":38914295,"diff_hunk":"@@ -0,0 +1,200 @@\n+// +build !nomdadm\n+\n+package collector\n+\n+import (\n+\t\"io/ioutil\"\n+\t\"strconv\"\n+\t\"strings\"\n+\n+\t\"github.com/prometheus/client_golang/prometheus\"\n+\t\"github.com/prometheus/log\"\n+)\n+\n+var statusfile = \"/proc/mdstat\"\n+\n+type mdstatus struct {\n+\tmdName       string\n+\tisActive     bool\n+\tdisksActive  int64\n+\tdisksTotal   int64\n+\tblocksTotal  int64\n+\tblocksSynced int64\n+}\n+\n+type mdadmCollector struct {\n+\tisActive     *prometheus.GaugeVec\n+\tdisksActive  *prometheus.GaugeVec\n+\tdisksTotal   *prometheus.GaugeVec\n+\tblocksTotal  *prometheus.GaugeVec\n+\tblocksSynced *prometheus.GaugeVec\n+}\n+\n+func init() {\n+\tFactories[\"mdadm\"] = NewMdadmCollector\n+}\n+\n+func evalStatusline(statusline string) (active, total, size int64) {\n+\n+\tfirst_split := strings.Split(statusline, \"[\")\n+\tsecond_split := strings.Split(first_split[1], \"]\")\n+\n+\tsizeDirty := strings.Split(first_split[0], \"blocks\")[0]\n+\tsizeStripped := strings.Replace(sizeDirty, \" \", \"\", -1)\n+\n+\tnumberOfDrives := strings.Split(second_split[0], \"/\")\n+\n+\ttotal, _ = strconv.ParseInt(numberOfDrives[0], 10, 64)\n+\tactive, _ = strconv.ParseInt(numberOfDrives[1], 10, 64)\n+\tsize, _ = strconv.ParseInt(sizeStripped, 10, 64)\n+\n+\treturn active, total, size\n+\n+}\n+\n+// gets the size that has already been synced out of the sync-line\n+func evalBuildline(buildline string) int64 {\n+\tfirst_split := strings.Split(buildline, \"(\")\n+\tsize := strings.Split(first_split[1], \"/\")[0]\n+\n+\tsyncedSize, _ := strconv.ParseInt(size, 10, 64)\n+\n+\treturn syncedSize\n+}\n+\n+// parses an mdstat-file and returns a struct with the relevant infos\n+func parseMdstat(mdstatusfilepath string) ([]mdstatus, error) {\n+\n+\tcontent, err := ioutil.ReadFile(mdstatusfilepath)\n+\tif err != nil {\n+\t\treturn []mdstatus{}, err\n+\t}\n+\n+\tmdstatusfile := string(content)","path":"collector/mdadm.go","position":73,"original_position":73,"commit_id":"98593470c0d7a21ccb74d9a05679faf750e87497","original_commit_id":"98593470c0d7a21ccb74d9a05679faf750e87497","user":{"login":"juliusv","id":538008,"avatar_url":"https://avatars.githubusercontent.com/u/538008?v=3","gravatar_id":"","url":"https://api.github.com/users/juliusv","html_url":"https://github.com/juliusv","followers_url":"https://api.github.com/users/juliusv/followers","following_url":"https://api.github.com/users/juliusv/following{/other_user}","gists_url":"https://api.github.com/users/juliusv/gists{/gist_id}","starred_url":"https://api.github.com/users/juliusv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juliusv/subscriptions","organizations_url":"https://api.github.com/users/juliusv/orgs","repos_url":"https://api.github.com/users/juliusv/repos","events_url":"https://api.github.com/users/juliusv/events{/privacy}","received_events_url":"https://api.github.com/users/juliusv/received_events","type":"User","site_admin":false},"body":"I'd probably go for word boundaries somewhere in here. `mdStatusFile`?\r\n\r\nBtw., since md is an initialism for \"multiple disks\", variables like `currentMd` where MD starts capitalized should then be `currentMD` (https://github.com/golang/go/wiki/CodeReviewComments#initialisms).","created_at":"2015-09-08T11:21:29Z","updated_at":"2015-09-08T11:21:29Z","html_url":"https://github.com/prometheus/node_exporter/pull/109#discussion_r38914295","pull_request_url":"https://api.github.com/repos/prometheus/node_exporter/pulls/109","_links":{"self":{"href":"https://api.github.com/repos/prometheus/node_exporter/pulls/comments/38914295"},"html":{"href":"https://github.com/prometheus/node_exporter/pull/109#discussion_r38914295"},"pull_request":{"href":"https://api.github.com/repos/prometheus/node_exporter/pulls/109"}}},"pull_request":{"url":"https://api.github.com/repos/prometheus/node_exporter/pulls/109","id":44418007,"html_url":"https://github.com/prometheus/node_exporter/pull/109","diff_url":"https://github.com/prometheus/node_exporter/pull/109.diff","patch_url":"https://github.com/prometheus/node_exporter/pull/109.patch","issue_url":"https://api.github.com/repos/prometheus/node_exporter/issues/109","number":109,"state":"open","locked":false,"title":"adding collector for linux-mdadm-software-raid","user":{"login":"cherti","id":6452205,"avatar_url":"https://avatars.githubusercontent.com/u/6452205?v=3","gravatar_id":"","url":"https://api.github.com/users/cherti","html_url":"https://github.com/cherti","followers_url":"https://api.github.com/users/cherti/followers","following_url":"https://api.github.com/users/cherti/following{/other_user}","gists_url":"https://api.github.com/users/cherti/gists{/gist_id}","starred_url":"https://api.github.com/users/cherti/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cherti/subscriptions","organizations_url":"https://api.github.com/users/cherti/orgs","repos_url":"https://api.github.com/users/cherti/repos","events_url":"https://api.github.com/users/cherti/events{/privacy}","received_events_url":"https://api.github.com/users/cherti/received_events","type":"User","site_admin":false},"body":"Implementing a collector able to parse /proc/mdstat and exposing metrics regarding the state of the md-devices present.\r\n\r\nexposed metrics atm:\r\n* `md_is_active` indicates whether the device in question is marked as active\r\n* `md_disks_total` indicates the number of disks the device consists of\r\n* `md_disks_active` indicates how many of those devices are active (if lower than `md_disks_total` the devic should be considered degraded)\r\n* `md_blocks_total` indicates the number of blocks the device contains\r\n* `md_blocks_synced` indicates the number of blocks in sync\r\n\r\n\r\nComments, suggestions etc.?","created_at":"2015-09-08T10:52:50Z","updated_at":"2015-09-08T11:21:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"771bad777b1421bdadc1137d175dfbf48743f44c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/prometheus/node_exporter/pulls/109/commits","review_comments_url":"https://api.github.com/repos/prometheus/node_exporter/pulls/109/comments","review_comment_url":"https://api.github.com/repos/prometheus/node_exporter/pulls/comments{/number}","comments_url":"https://api.github.com/repos/prometheus/node_exporter/issues/109/comments","statuses_url":"https://api.github.com/repos/prometheus/node_exporter/statuses/98593470c0d7a21ccb74d9a05679faf750e87497","head":{"label":"cherti:mdadm","ref":"mdadm","sha":"98593470c0d7a21ccb74d9a05679faf750e87497","user":{"login":"cherti","id":6452205,"avatar_url":"https://avatars.githubusercontent.com/u/6452205?v=3","gravatar_id":"","url":"https://api.github.com/users/cherti","html_url":"https://github.com/cherti","followers_url":"https://api.github.com/users/cherti/followers","following_url":"https://api.github.com/users/cherti/following{/other_user}","gists_url":"https://api.github.com/users/cherti/gists{/gist_id}","starred_url":"https://api.github.com/users/cherti/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cherti/subscriptions","organizations_url":"https://api.github.com/users/cherti/orgs","repos_url":"https://api.github.com/users/cherti/repos","events_url":"https://api.github.com/users/cherti/events{/privacy}","received_events_url":"https://api.github.com/users/cherti/received_events","type":"User","site_admin":false},"repo":{"id":42021684,"name":"node_exporter","full_name":"cherti/node_exporter","owner":{"login":"cherti","id":6452205,"avatar_url":"https://avatars.githubusercontent.com/u/6452205?v=3","gravatar_id":"","url":"https://api.github.com/users/cherti","html_url":"https://github.com/cherti","followers_url":"https://api.github.com/users/cherti/followers","following_url":"https://api.github.com/users/cherti/following{/other_user}","gists_url":"https://api.github.com/users/cherti/gists{/gist_id}","starred_url":"https://api.github.com/users/cherti/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cherti/subscriptions","organizations_url":"https://api.github.com/users/cherti/orgs","repos_url":"https://api.github.com/users/cherti/repos","events_url":"https://api.github.com/users/cherti/events{/privacy}","received_events_url":"https://api.github.com/users/cherti/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/cherti/node_exporter","description":"Exporter for machine metrics","fork":true,"url":"https://api.github.com/repos/cherti/node_exporter","forks_url":"https://api.github.com/repos/cherti/node_exporter/forks","keys_url":"https://api.github.com/repos/cherti/node_exporter/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cherti/node_exporter/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cherti/node_exporter/teams","hooks_url":"https://api.github.com/repos/cherti/node_exporter/hooks","issue_events_url":"https://api.github.com/repos/cherti/node_exporter/issues/events{/number}","events_url":"https://api.github.com/repos/cherti/node_exporter/events","assignees_url":"https://api.github.com/repos/cherti/node_exporter/assignees{/user}","branches_url":"https://api.github.com/repos/cherti/node_exporter/branches{/branch}","tags_url":"https://api.github.com/repos/cherti/node_exporter/tags","blobs_url":"https://api.github.com/repos/cherti/node_exporter/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cherti/node_exporter/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cherti/node_exporter/git/refs{/sha}","trees_url":"https://api.github.com/repos/cherti/node_exporter/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cherti/node_exporter/statuses/{sha}","languages_url":"https://api.github.com/repos/cherti/node_exporter/languages","stargazers_url":"https://api.github.com/repos/cherti/node_exporter/stargazers","contributors_url":"https://api.github.com/repos/cherti/node_exporter/contributors","subscribers_url":"https://api.github.com/repos/cherti/node_exporter/subscribers","subscription_url":"https://api.github.com/repos/cherti/node_exporter/subscription","commits_url":"https://api.github.com/repos/cherti/node_exporter/commits{/sha}","git_commits_url":"https://api.github.com/repos/cherti/node_exporter/git/commits{/sha}","comments_url":"https://api.github.com/repos/cherti/node_exporter/comments{/number}","issue_comment_url":"https://api.github.com/repos/cherti/node_exporter/issues/comments{/number}","contents_url":"https://api.github.com/repos/cherti/node_exporter/contents/{+path}","compare_url":"https://api.github.com/repos/cherti/node_exporter/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cherti/node_exporter/merges","archive_url":"https://api.github.com/repos/cherti/node_exporter/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cherti/node_exporter/downloads","issues_url":"https://api.github.com/repos/cherti/node_exporter/issues{/number}","pulls_url":"https://api.github.com/repos/cherti/node_exporter/pulls{/number}","milestones_url":"https://api.github.com/repos/cherti/node_exporter/milestones{/number}","notifications_url":"https://api.github.com/repos/cherti/node_exporter/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cherti/node_exporter/labels{/name}","releases_url":"https://api.github.com/repos/cherti/node_exporter/releases{/id}","created_at":"2015-09-06T22:59:11Z","updated_at":"2015-09-06T22:59:12Z","pushed_at":"2015-09-08T10:44:08Z","git_url":"git://github.com/cherti/node_exporter.git","ssh_url":"git@github.com:cherti/node_exporter.git","clone_url":"https://github.com/cherti/node_exporter.git","svn_url":"https://github.com/cherti/node_exporter","homepage":"http://prometheus.io/","size":1088,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"prometheus:master","ref":"master","sha":"704e8f76d81e9569873eb8f8a0bac0bc1dd74c4e","user":{"login":"prometheus","id":3380462,"avatar_url":"https://avatars.githubusercontent.com/u/3380462?v=3","gravatar_id":"","url":"https://api.github.com/users/prometheus","html_url":"https://github.com/prometheus","followers_url":"https://api.github.com/users/prometheus/followers","following_url":"https://api.github.com/users/prometheus/following{/other_user}","gists_url":"https://api.github.com/users/prometheus/gists{/gist_id}","starred_url":"https://api.github.com/users/prometheus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/prometheus/subscriptions","organizations_url":"https://api.github.com/users/prometheus/orgs","repos_url":"https://api.github.com/users/prometheus/repos","events_url":"https://api.github.com/users/prometheus/events{/privacy}","received_events_url":"https://api.github.com/users/prometheus/received_events","type":"Organization","site_admin":false},"repo":{"id":9524057,"name":"node_exporter","full_name":"prometheus/node_exporter","owner":{"login":"prometheus","id":3380462,"avatar_url":"https://avatars.githubusercontent.com/u/3380462?v=3","gravatar_id":"","url":"https://api.github.com/users/prometheus","html_url":"https://github.com/prometheus","followers_url":"https://api.github.com/users/prometheus/followers","following_url":"https://api.github.com/users/prometheus/following{/other_user}","gists_url":"https://api.github.com/users/prometheus/gists{/gist_id}","starred_url":"https://api.github.com/users/prometheus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/prometheus/subscriptions","organizations_url":"https://api.github.com/users/prometheus/orgs","repos_url":"https://api.github.com/users/prometheus/repos","events_url":"https://api.github.com/users/prometheus/events{/privacy}","received_events_url":"https://api.github.com/users/prometheus/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/prometheus/node_exporter","description":"Exporter for machine metrics","fork":false,"url":"https://api.github.com/repos/prometheus/node_exporter","forks_url":"https://api.github.com/repos/prometheus/node_exporter/forks","keys_url":"https://api.github.com/repos/prometheus/node_exporter/keys{/key_id}","collaborators_url":"https://api.github.com/repos/prometheus/node_exporter/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/prometheus/node_exporter/teams","hooks_url":"https://api.github.com/repos/prometheus/node_exporter/hooks","issue_events_url":"https://api.github.com/repos/prometheus/node_exporter/issues/events{/number}","events_url":"https://api.github.com/repos/prometheus/node_exporter/events","assignees_url":"https://api.github.com/repos/prometheus/node_exporter/assignees{/user}","branches_url":"https://api.github.com/repos/prometheus/node_exporter/branches{/branch}","tags_url":"https://api.github.com/repos/prometheus/node_exporter/tags","blobs_url":"https://api.github.com/repos/prometheus/node_exporter/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/prometheus/node_exporter/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/prometheus/node_exporter/git/refs{/sha}","trees_url":"https://api.github.com/repos/prometheus/node_exporter/git/trees{/sha}","statuses_url":"https://api.github.com/repos/prometheus/node_exporter/statuses/{sha}","languages_url":"https://api.github.com/repos/prometheus/node_exporter/languages","stargazers_url":"https://api.github.com/repos/prometheus/node_exporter/stargazers","contributors_url":"https://api.github.com/repos/prometheus/node_exporter/contributors","subscribers_url":"https://api.github.com/repos/prometheus/node_exporter/subscribers","subscription_url":"https://api.github.com/repos/prometheus/node_exporter/subscription","commits_url":"https://api.github.com/repos/prometheus/node_exporter/commits{/sha}","git_commits_url":"https://api.github.com/repos/prometheus/node_exporter/git/commits{/sha}","comments_url":"https://api.github.com/repos/prometheus/node_exporter/comments{/number}","issue_comment_url":"https://api.github.com/repos/prometheus/node_exporter/issues/comments{/number}","contents_url":"https://api.github.com/repos/prometheus/node_exporter/contents/{+path}","compare_url":"https://api.github.com/repos/prometheus/node_exporter/compare/{base}...{head}","merges_url":"https://api.github.com/repos/prometheus/node_exporter/merges","archive_url":"https://api.github.com/repos/prometheus/node_exporter/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/prometheus/node_exporter/downloads","issues_url":"https://api.github.com/repos/prometheus/node_exporter/issues{/number}","pulls_url":"https://api.github.com/repos/prometheus/node_exporter/pulls{/number}","milestones_url":"https://api.github.com/repos/prometheus/node_exporter/milestones{/number}","notifications_url":"https://api.github.com/repos/prometheus/node_exporter/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/prometheus/node_exporter/labels{/name}","releases_url":"https://api.github.com/repos/prometheus/node_exporter/releases{/id}","created_at":"2013-04-18T14:44:52Z","updated_at":"2015-09-03T08:28:04Z","pushed_at":"2015-09-08T10:52:51Z","git_url":"git://github.com/prometheus/node_exporter.git","ssh_url":"git@github.com:prometheus/node_exporter.git","clone_url":"https://github.com/prometheus/node_exporter.git","svn_url":"https://github.com/prometheus/node_exporter","homepage":"http://prometheus.io/","size":1088,"stargazers_count":57,"watchers_count":57,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":35,"mirror_url":null,"open_issues_count":17,"forks":35,"open_issues":17,"watchers":57,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/prometheus/node_exporter/pulls/109"},"html":{"href":"https://github.com/prometheus/node_exporter/pull/109"},"issue":{"href":"https://api.github.com/repos/prometheus/node_exporter/issues/109"},"comments":{"href":"https://api.github.com/repos/prometheus/node_exporter/issues/109/comments"},"review_comments":{"href":"https://api.github.com/repos/prometheus/node_exporter/pulls/109/comments"},"review_comment":{"href":"https://api.github.com/repos/prometheus/node_exporter/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/prometheus/node_exporter/pulls/109/commits"},"statuses":{"href":"https://api.github.com/repos/prometheus/node_exporter/statuses/98593470c0d7a21ccb74d9a05679faf750e87497"}}}}